comparison markup/eval.py @ 86:5d98c4259d68

Accidentially left some doctests disabled.
author cmlenz
date Mon, 17 Jul 2006 09:01:08 +0000
parents c82c002d4c32
children c6f07b7cd3ea
comparison
equal deleted inserted replaced
85:db8f2958c670 86:5d98c4259d68
40 Similar to e.g. Javascript, expressions in templates can use the dot 40 Similar to e.g. Javascript, expressions in templates can use the dot
41 notation for attribute access to access items in mappings: 41 notation for attribute access to access items in mappings:
42 42
43 >>> Expression('dict.some').evaluate(data) 43 >>> Expression('dict.some').evaluate(data)
44 'thing' 44 'thing'
45 """ 45
46 """
47 This also works the other way around: item access can be used to access 46 This also works the other way around: item access can be used to access
48 any object attribute (meaning there's no use for `getattr()` in templates): 47 any object attribute (meaning there's no use for `getattr()` in templates):
49 48
50 >>> class MyClass(object): 49 >>> class MyClass(object):
51 ... myattr = 'Bar' 50 ... myattr = 'Bar'
73 72
74 @param source: the expression as string 73 @param source: the expression as string
75 """ 74 """
76 self.source = source 75 self.source = source
77 76
78 tree = parse(self.source, 'eval') 77 ast = parse(self.source, 'eval')
79 if isinstance(filename, unicode): 78 if isinstance(filename, unicode):
80 # pycodegen doesn't like unicode in the filename 79 # pycodegen doesn't like unicode in the filename
81 filename = filename.encode('utf-8', 'replace') 80 filename = filename.encode('utf-8', 'replace')
82 tree.filename = filename or '<string>' 81 ast.filename = filename or '<string>'
83 gen = TemplateExpressionCodeGenerator(tree) 82 gen = TemplateExpressionCodeGenerator(ast)
84 if lineno >= 0: 83 if lineno >= 0:
85 gen.emit('SET_LINENO', lineno) 84 gen.emit('SET_LINENO', lineno)
86 self.code = gen.getCode() 85 self.code = gen.getCode()
87 86
88 def __repr__(self): 87 def __repr__(self):
Copyright (C) 2012-2017 Edgewall Software