comparison genshi/template/eval.py @ 382:2682dabbcd04 trunk

* Added documentation for the various stream event kinds. * Move generation of HTML documentation into a custom distutils command, run by `setup.py build_doc` * Added verification of doctest snippets in documentation, which can be run by `setup.py test_doc` * Fixed `repr` of `Markup` instances.
author cmlenz
date Fri, 01 Dec 2006 23:43:59 +0000
parents 62de137b9322
children 1dc3d3df4a85
comparison
equal deleted inserted replaced
381:b9fc7a1f76ca 382:2682dabbcd04
199 '<Expression %s>' % (repr(source or '?').replace("'", '"')), 199 '<Expression %s>' % (repr(source or '?').replace("'", '"')),
200 lineno, code.co_lnotab, (), ()) 200 lineno, code.co_lnotab, (), ())
201 201
202 BUILTINS = __builtin__.__dict__.copy() 202 BUILTINS = __builtin__.__dict__.copy()
203 BUILTINS['Undefined'] = Undefined 203 BUILTINS['Undefined'] = Undefined
204 _UNDEF = Undefined(None)
204 205
205 def _lookup_name(data, name): 206 def _lookup_name(data, name):
206 __traceback_hide__ = True 207 __traceback_hide__ = True
207 val = data.get(name, Undefined) 208 val = data.get(name, _UNDEF)
208 if val is Undefined: 209 if val is _UNDEF:
209 val = BUILTINS.get(name, val) 210 val = BUILTINS.get(name, val)
210 if val is Undefined: 211 if val is _UNDEF:
211 return val(name) 212 return Undefined(name)
212 return val 213 return val
213 214
214 def _lookup_attr(data, obj, key): 215 def _lookup_attr(data, obj, key):
215 __traceback_hide__ = True 216 __traceback_hide__ = True
216 if type(obj) is Undefined: 217 if type(obj) is Undefined:
230 key = key[0] 231 key = key[0]
231 try: 232 try:
232 return obj[key] 233 return obj[key]
233 except (KeyError, IndexError, TypeError), e: 234 except (KeyError, IndexError, TypeError), e:
234 if isinstance(key, basestring): 235 if isinstance(key, basestring):
235 val = getattr(obj, key, Undefined) 236 val = getattr(obj, key, _UNDEF)
236 if val is Undefined: 237 if val is _UNDEF:
237 val = Undefined(key) 238 val = Undefined(key)
238 return val 239 return val
239 raise 240 raise
240 241
241 242
Copyright (C) 2012-2017 Edgewall Software