Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.arcetri.astro.it/~lfini/cgi-bin/caffe.py
Дата изменения: Thu Nov 19 11:35:40 2015
Дата индексирования: Sun Apr 10 01:29:44 2016
Кодировка:

Поисковые слова: р р п п п п п п р п р п п п п п п п п п п п п п п п п п п
#!/usr/bin/python
import sys,re,os,time

PATH='~lfini/caffe'

import cgi
import cgitb; cgitb.enable()

mobj=re.compile('')
tobj=re.compile('\$REC___')
dobj=re.compile('\$DAT___')
ftime=()

PATH=os.path.expanduser(PATH)

class Ssheet:
def __init__(self):
self.memory=0
self.reset()

def reset(self):
self.tot=0
self.sums=[]
self.prefix=' '
self.format='|%7.2f'

def operate(self,il):
global ftime
mtch=dobj.search(il) # First substitute date
if mtch:
str='%2.2d/%2.2d/%4.4d'%(ftime[2],ftime[1],ftime[0])
il=dobj.sub(str,il)
mtch=tobj.search(il) # Then substitute total
if mtch:
str="%7.2f"%self.memory
il=tobj.sub(str,il)
mtch=mobj.search(il)
if not mtch: return il
oper=mtch.group(1)
flds=il.split('|')[1:-1]
while len(self.sums)
if oper[0] == 'P': sign = 1
elif oper[0] == 'M': sign = -1
elif oper[0] == 'X':
self.prefix=oper[1:]
return ''
elif oper[0] == 'S':
self.memory=self.tot
return ''
elif oper[0] == 'F':
self.format=oper[1:]
return ''
elif oper[0] == '=':
ret=self.prefix
for i in range(len(self.sums)):
ret += self.format % self.sums[i]
ret += '\n'
self.reset() # Reinitialize sum
return ret
else:
return il + ' <<< Code error'

for i in range(len(flds)):
str=flds[i].strip()
if not str: str='0.0'
self.sums[i] += sign*float(str)
self.tot += sign*float(str)
return il


print "Content-Type: text/html\n" # HTML is following

try:
year=sys.argv[1]
except:
fname=os.path.join(PATH,"current.year")
try:
infile=open(fname)
except:
year='????'
else:
year=int(infile.readline())

fname=os.path.join(PATH,"Registro%s.html"%year)

try:
infile=open(fname)
except:
print "

Cannot open:",fname,"

"
sys.exit()

mt=os.stat(fname).st_mtime
ftime=time.localtime(mt)

ss=Ssheet()

while 1:
il=infile.readline()
if not il: break
ol=ss.operate(il)
print ol,