-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogramBaseTmpl.py
500 lines (443 loc) · 19.3 KB
/
programBaseTmpl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
#!/usr/bin/env python
# -*- coding: : utf-8 -*-
"""this is module document
"""
##################################################
## DEPENDENCIES
import sys
import os
import os.path
try:
import builtins as builtin
except ImportError:
import __builtin__ as builtin
from os.path import getmtime, exists
import time
import types
from Cheetah.Version import MinCompatibleVersion as RequiredCheetahVersion
from Cheetah.Version import MinCompatibleVersionTuple as RequiredCheetahVersionTuple
from Cheetah.Template import Template
from Cheetah.DummyTransaction import *
from Cheetah.NameMapper import NotFound, valueForName, valueFromSearchList, valueFromFrameOrSearchList
from Cheetah.CacheRegion import CacheRegion
import Cheetah.Filters as Filters
import Cheetah.ErrorCatchers as ErrorCatchers
##################################################
## MODULE CONSTANTS
VFFSL=valueFromFrameOrSearchList
VFSL=valueFromSearchList
VFN=valueForName
currentTime=time.time
__CHEETAH_version__ = '2.4.4'
__CHEETAH_versionTuple__ = (2, 4, 4, 'development', 0)
__CHEETAH_genTime__ = 1466685242.762
__CHEETAH_genTimestamp__ = 'Thu Jun 23 20:34:02 2016'
__CHEETAH_src__ = 'programBaseTmpl.tmpl'
__CHEETAH_srcLastModified__ = 'Thu Jun 23 20:34:00 2016'
__CHEETAH_docstring__ = 'Autogenerated by Cheetah: The Python-Powered Template Engine'
if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple:
raise AssertionError(
'This template was compiled with Cheetah version'
' %s. Templates compiled before version %s must be recompiled.'%(
__CHEETAH_version__, RequiredCheetahVersion))
##################################################
## CLASSES
class programBaseTmpl(Template):
"""
this is class document
"""
##################################################
## CHEETAH GENERATED METHODS
def __init__(self, *args, **KWs):
super(programBaseTmpl, self).__init__(*args, **KWs)
if not self._CHEETAH__instanceInitialized:
cheetahKWArgs = {}
allowedKWs = 'searchList namespaces filter filtersLib errorCatcher'.split()
for k,v in KWs.items():
if k in allowedKWs: cheetahKWArgs[k] = v
self._initCheetahInstance(**cheetahKWArgs)
def respond(self, trans=None):
"""
this is document ## 必须带英文冒号
this is method document
"""
## CHEETAH: main method generated for this template
if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
trans = self.transaction # is None unless self.awake() was called
if not trans:
trans = DummyTransaction()
_dummyTrans = True
else: _dummyTrans = False
write = trans.response().write
SL = self._CHEETAH__searchList
_filter = self._CHEETAH__currentFilter
########################################
## START - generated method body
# program base
# 此处的空行也是生成的文本中的内容,但有注释就不是了。所以不能用回车格式化代码了;注定不易读!
self._CHEETAH__globalSetVars["a"] = True
b = True
c = True
d = 'test'
# del $d ## 用法不对
country = 'China'
if VFFSL(SL,"a",True) and VFFSL(SL,"b",True) and VFFSL(SL,"c",True): # generated from line 10, col 1
write(u'''\t<H1>ABC</H1>
''')
if VFFSL(SL,"country",True) in ('America', 'Italy', 'Australia',
'China'): # generated from line 14, col 1
write(u'''\t<H1>DEF</H1>
''')
else: # generated from line 17, col 1
write(u'''\t<H1>GHI</H1>
''')
# print: <H1>ABC</H1>
# <H1>DEF</H1>
write(u'''
''')
namespace1 = {'name' : {'attr' : lambda x, y, z: '1. %s, 2. %s, 3. %s' % (x, y, z)}}
subPlaceHolder = 'sub_placeholder'
_v = VFN(VFFSL(SL,"namespace1",True),"name",True)['attr']('abc', VFFSL(SL,"subPlaceHolder",True), 1) # u"${namespace1.name['attr']('abc', $subPlaceHolder, 1)}" on line 25, col 1
if _v is not None: write(_filter(_v, rawExpr=u"${namespace1.name['attr']('abc', $subPlaceHolder, 1)}")) # from line 25, col 1.
write(u'''
''')
# print: 1. abc, 2. sub_placeholder, 3. 1
write(u'''
''')
# set $nest = {'nest' : {'var' : 'the result of $nest($nest($val))'}}
nest = lambda arg: '[%s]' % arg
var = 'var'
_v = VFFSL(SL,"nest",False)(VFFSL(SL,"nest",False)(VFFSL(SL,"var",True))) # u'$nest($nest($var))' on line 31, col 1
if _v is not None: write(_filter(_v, rawExpr=u'$nest($nest($var))')) # from line 31, col 1.
write(u'''\t\t\t\t\t\t\t''')
# 相当于nest是个函数,调用了两次!
write(u'''
''')
# print: [[var]]
write(u'''
======================================================
''')
top = 20
# 不能格式化……否则输出都换行了,有table的话,table成了前缀
for i in VFFSL(SL,"range",False)(VFFSL(SL,"top",True), 0, -1) : # generated from line 36, col 1
_v = VFFSL(SL,"i",True) # u'$i' on line 37, col 1
if _v is not None: write(_filter(_v, rawExpr=u'$i')) # from line 37, col 1.
write(u''', ''')
write(u'''
======================================================
======================================================
''')
top = 20
# 不能格式化……否则输出都换行了,有table的话,table成了前缀
for i in VFFSL(SL,"xrange",False)(10) : # generated from line 42, col 1
_v = VFFSL(SL,"i",True) # u'$i' on line 43, col 1
if _v is not None: write(_filter(_v, rawExpr=u'$i')) # from line 43, col 1.
write(u''', ''')
write(u'''
======================================================
''')
self._CHEETAH__globalSetVars["value"] = 100
_v = VFFSL(SL,"id",False)(VFFSL(SL,"value",True)) # u'$id($value)' on line 47, col 1
if _v is not None: write(_filter(_v, rawExpr=u'$id($value)')) # from line 47, col 1.
write(u'''
''')
square = [x ** 2 for x in VFFSL(SL,"xrange",False)(VFFSL(SL,"self.size",True))]
for i in VFFSL(SL,"square",True): # generated from line 50, col 1
_v = VFFSL(SL,"i",True) # u'$i' on line 51, col 1
if _v is not None: write(_filter(_v, rawExpr=u'$i')) # from line 51, col 1.
write(u'''\t''')
write(u'''
''')
_v = VFFSL(SL,"fnTest",False)(VFFSL(SL,"self",True)) # u'$fnTest($self)' on line 53, col 1
if _v is not None: write(_filter(_v, rawExpr=u'$fnTest($self)')) # from line 53, col 1.
write(u'''
''')
# $self.fnTest() ## 不能以这种方式调用……
write(u'''
"""
line1 ''')
test = 10
write(u'''
line2
"""
"""
line3 ''')
test1 = 11
write(u'''
line4
"""
line5
\t- ''')
test2 = 12
write(u"""
line6
'""")
_v = VFFSL(SL,"test",True) # u'$test' on line 68, col 2
if _v is not None: write(_filter(_v, rawExpr=u'$test')) # from line 68, col 2.
write(u"""'
""")
_v = VFFSL(SL,"test",True) # u'$test' on line 69, col 1
if _v is not None: write(_filter(_v, rawExpr=u'$test')) # from line 69, col 1.
write(u'''\\.method
''')
# head: this is a head
write(u'''
What is ''')
_v = ' '.join(['that'] * 5)
if _v is not None: write(_filter(_v))
write(u'''?
''')
_v = VFN(VFFSL(SL,"square",True),"reverse",False)() # u'$square.reverse()' on line 79, col 1
if _v is not None: write(_filter(_v, rawExpr=u'$square.reverse()')) # from line 79, col 1.
write(u'''\t\t\t\t\t\t\t''')
# 此处silent没必要
write(u'''
''')
VFN(VFFSL(SL,"square",True),"reverse",False)()
write(u'''
''')
if True : # generated from line 82, col 1
_v = 'abc'
if _v is not None: write(_filter(_v))
else:
_v = 'def'
if _v is not None: write(_filter(_v))
write(u'''
''')
# a等同c,b等同d
# a
## START CACHE REGION: ID=_10355081. line 86, col 1 in the source.
_RECACHE__10355081 = False
_cacheRegion__10355081 = self.getCacheRegion(regionID='_10355081', cacheInfo={'type': 1, 'ID': "'$*cacheValue"})
if _cacheRegion__10355081.isNew():
_RECACHE__10355081 = True
_cacheItem__10355081 = _cacheRegion__10355081.getCacheItem('_10355081')
if _cacheItem__10355081.hasExpired():
_RECACHE__10355081 = True
if (not _RECACHE__10355081) and _cacheItem__10355081.getRefreshTime():
try:
_output = _cacheItem__10355081.renderOutput()
except KeyError:
_RECACHE__10355081 = True
else:
write(_output)
del _output
if _RECACHE__10355081 or not _cacheItem__10355081.getRefreshTime():
_orig_trans_10355081 = trans
trans = _cacheCollector__10355081 = DummyTransaction()
write = _cacheCollector__10355081.response().write
_v = VFFSL(SL,"cacheValue",True) # u'$*cacheValue' on line 86, col 1
if _v is not None: write(_filter(_v, rawExpr=u'$*cacheValue')) # from line 86, col 1.
trans = _orig_trans_10355081
write = trans.response().write
_cacheData = _cacheCollector__10355081.response().getvalue()
_cacheItem__10355081.setData(_cacheData)
write(_cacheData)
del _cacheData
del _cacheCollector__10355081
del _orig_trans_10355081
## END CACHE REGION: _10355081
write(u'''
''')
# b
## START CACHE REGION: ID=_56967698. line 88, col 1 in the source.
_RECACHE__56967698 = False
_cacheRegion__56967698 = self.getCacheRegion(regionID='_56967698', cacheInfo={'interval': 300.0, 'type': 2, 'ID': "'$*5*cacheValue1"})
if _cacheRegion__56967698.isNew():
_RECACHE__56967698 = True
_cacheItem__56967698 = _cacheRegion__56967698.getCacheItem('_56967698')
if _cacheItem__56967698.hasExpired():
_RECACHE__56967698 = True
if (not _RECACHE__56967698) and _cacheItem__56967698.getRefreshTime():
try:
_output = _cacheItem__56967698.renderOutput()
except KeyError:
_RECACHE__56967698 = True
else:
write(_output)
del _output
if _RECACHE__56967698 or not _cacheItem__56967698.getRefreshTime():
_orig_trans_56967698 = trans
trans = _cacheCollector__56967698 = DummyTransaction()
write = _cacheCollector__56967698.response().write
_cacheItem__56967698.setExpiryTime(currentTime() +300.0)
_v = VFFSL(SL,"cacheValue1",True) # u'$*5*cacheValue1' on line 88, col 1
if _v is not None: write(_filter(_v, rawExpr=u'$*5*cacheValue1')) # from line 88, col 1.
trans = _orig_trans_56967698
write = trans.response().write
_cacheData = _cacheCollector__56967698.response().getvalue()
_cacheItem__56967698.setData(_cacheData)
write(_cacheData)
del _cacheData
del _cacheCollector__56967698
del _orig_trans_56967698
## END CACHE REGION: _56967698
write(u'''
''')
# c
## START CACHE REGION: ID=_48627717. line 90, col 1 in the source.
_RECACHE__48627717 = False
_cacheRegion__48627717 = self.getCacheRegion(regionID='_48627717', cacheInfo={'type': 2})
if _cacheRegion__48627717.isNew():
_RECACHE__48627717 = True
_cacheItem__48627717 = _cacheRegion__48627717.getCacheItem('_48627717')
if _cacheItem__48627717.hasExpired():
_RECACHE__48627717 = True
if (not _RECACHE__48627717) and _cacheItem__48627717.getRefreshTime():
try:
_output = _cacheItem__48627717.renderOutput()
except KeyError:
_RECACHE__48627717 = True
else:
write(_output)
del _output
if _RECACHE__48627717 or not _cacheItem__48627717.getRefreshTime():
_orig_trans_48627717 = trans
trans = _cacheCollector__48627717 = DummyTransaction()
write = _cacheCollector__48627717.response().write
_v = VFFSL(SL,"cacheValue2",True) # u'$cacheValue2' on line 91, col 1
if _v is not None: write(_filter(_v, rawExpr=u'$cacheValue2')) # from line 91, col 1.
write(u'''
''')
trans = _orig_trans_48627717
write = trans.response().write
_cacheData = _cacheCollector__48627717.response().getvalue()
_cacheItem__48627717.setData(_cacheData)
write(_cacheData)
del _cacheData
del _cacheCollector__48627717
del _orig_trans_48627717
## END CACHE REGION: _48627717
# d
## START CACHE REGION: ID=_12739266. line 94, col 1 in the source.
_RECACHE__12739266 = False
_cacheRegion__12739266 = self.getCacheRegion(regionID='_12739266', cacheInfo={'interval': 5.0, 'type': 2})
if _cacheRegion__12739266.isNew():
_RECACHE__12739266 = True
_cacheItem__12739266 = _cacheRegion__12739266.getCacheItem('_12739266')
if _cacheItem__12739266.hasExpired():
_RECACHE__12739266 = True
if (not _RECACHE__12739266) and _cacheItem__12739266.getRefreshTime():
try:
_output = _cacheItem__12739266.renderOutput()
except KeyError:
_RECACHE__12739266 = True
else:
write(_output)
del _output
if _RECACHE__12739266 or not _cacheItem__12739266.getRefreshTime():
_orig_trans_12739266 = trans
trans = _cacheCollector__12739266 = DummyTransaction()
write = _cacheCollector__12739266.response().write
_cacheItem__12739266.setExpiryTime(currentTime() +5.0)
_v = VFFSL(SL,"cacheValue3",True) # u'$cacheValue3' on line 95, col 1
if _v is not None: write(_filter(_v, rawExpr=u'$cacheValue3')) # from line 95, col 1.
write(u'''
''')
trans = _orig_trans_12739266
write = trans.response().write
_cacheData = _cacheCollector__12739266.response().getvalue()
_cacheItem__12739266.setData(_cacheData)
write(_cacheData)
del _cacheData
del _cacheCollector__12739266
del _orig_trans_12739266
## END CACHE REGION: _12739266
# e, call templateObj.refreshCache(id) to refresh the cache
## START CACHE REGION: ID=cacheOnMe. line 98, col 1 in the source.
_RECACHE_cacheOnMe = False
_cacheRegion_cacheOnMe = self.getCacheRegion(regionID=u'cacheOnMe', cacheInfo={'type': 2, u'id': u'cacheOnMe'})
if _cacheRegion_cacheOnMe.isNew():
_RECACHE_cacheOnMe = True
_cacheItem_cacheOnMe = _cacheRegion_cacheOnMe.getCacheItem(u'cacheOnMe')
if _cacheItem_cacheOnMe.hasExpired():
_RECACHE_cacheOnMe = True
if (not _RECACHE_cacheOnMe) and _cacheItem_cacheOnMe.getRefreshTime():
try:
_output = _cacheItem_cacheOnMe.renderOutput()
except KeyError:
_RECACHE_cacheOnMe = True
else:
write(_output)
del _output
if _RECACHE_cacheOnMe or not _cacheItem_cacheOnMe.getRefreshTime():
_orig_transcacheOnMe = trans
trans = _cacheCollector_cacheOnMe = DummyTransaction()
write = _cacheCollector_cacheOnMe.response().write
_v = VFFSL(SL,"cacheValue4",True) # u'$cacheValue4' on line 99, col 1
if _v is not None: write(_filter(_v, rawExpr=u'$cacheValue4')) # from line 99, col 1.
write(u'''
''')
trans = _orig_transcacheOnMe
write = trans.response().write
_cacheData = _cacheCollector_cacheOnMe.response().getvalue()
_cacheItem_cacheOnMe.setData(_cacheData)
write(_cacheData)
del _cacheData
del _cacheCollector_cacheOnMe
del _orig_transcacheOnMe
## END CACHE REGION: cacheOnMe
# f, refresh when cacheValue4 == True
# 括号必须加,不加会报错
## START CACHE REGION: ID=_60347276. line 102, col 1 in the source.
_RECACHE__60347276 = False
_cacheRegion__60347276 = self.getCacheRegion(regionID='_60347276', cacheInfo={u'test': u'(VFFSL(SL,"cacheValue4",True) == True)', 'type': 2})
if _cacheRegion__60347276.isNew():
_RECACHE__60347276 = True
_cacheItem__60347276 = _cacheRegion__60347276.getCacheItem('_60347276')
if _cacheItem__60347276.hasExpired():
_RECACHE__60347276 = True
if (VFFSL(SL,"cacheValue4",True) == True):
_RECACHE__60347276 = True
if (not _RECACHE__60347276) and _cacheItem__60347276.getRefreshTime():
try:
_output = _cacheItem__60347276.renderOutput()
except KeyError:
_RECACHE__60347276 = True
else:
write(_output)
del _output
if _RECACHE__60347276 or not _cacheItem__60347276.getRefreshTime():
_orig_trans_60347276 = trans
trans = _cacheCollector__60347276 = DummyTransaction()
write = _cacheCollector__60347276.response().write
trans = _orig_trans_60347276
write = trans.response().write
_cacheData = _cacheCollector__60347276.response().getvalue()
_cacheItem__60347276.setData(_cacheData)
write(_cacheData)
del _cacheData
del _cacheCollector__60347276
del _orig_trans_60347276
## END CACHE REGION: _60347276
write(u'''
#set $rawValue\t\t\t\t= 10
$me
#def\t\t\t\t\t\t\t\t\t\t\t## \u4efb\u4f55\u4e1c\u897f\u90fd\u4e0d\u4f8b\u5916
#end def
''')
########################################
## END - generated method body
return _dummyTrans and trans.response().getvalue() or ""
##################################################
## CHEETAH GENERATED ATTRIBUTES
_CHEETAH__instanceInitialized = False
_CHEETAH_version = __CHEETAH_version__
_CHEETAH_versionTuple = __CHEETAH_versionTuple__
_CHEETAH_genTime = __CHEETAH_genTime__
_CHEETAH_genTimestamp = __CHEETAH_genTimestamp__
_CHEETAH_src = __CHEETAH_src__
_CHEETAH_srcLastModified = __CHEETAH_srcLastModified__
_mainCheetahMethod_for_programBaseTmpl= 'respond'
## END CLASS DEFINITION
if not hasattr(programBaseTmpl, '_initCheetahAttributes'):
templateAPIClass = getattr(programBaseTmpl, '_CHEETAH_templateClass', Template)
templateAPIClass._addCheetahPlumbingCodeToClass(programBaseTmpl)
# CHEETAH was developed by Tavis Rudd and Mike Orr
# with code, advice and input from many other volunteers.
# For more information visit http://www.CheetahTemplate.org/
##################################################
## if run from command line:
if __name__ == '__main__':
from Cheetah.TemplateCmdLineIface import CmdLineIface
CmdLineIface(templateObj=programBaseTmpl()).run()