runtime.py
This file
Path
jinja2/runtime.py
537 lines · 17.7 KiB · Python
Last changed by
Improved error message for undefinedsArmin Ronacherbefore adoption98dbf5f
History of this fileTake it
The walk stopped after 200 commits: lines older than f7e405d point at it.
Linked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 1–7why, one step back1# -*- coding: utf-8 -*-2"""3 jinja2.runtime4 ~~~~~~~~~~~~~~56 Runtime helpers.7It's a new yearArmin Ronacherbefore adoption55494e4
line 8why, one step back8 :copyright: (c) 2010 by the Jinja Team.Linked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 9–12why, one step back9 :license: BSD.10"""11import sys12from itertools import chain, imapBiggest change to Jinja since the 1.x migration: added evaluation contextsArmin Ronacherbefore adoption8346bd7
line 13why, one step back13from jinja2.nodes import EvalContextLinked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
line 14why, one step back14from jinja2.utils import Markup, partial, soft_unicode, escape, missing, \Improved error message for undefinedsArmin Ronacherbefore adoption98dbf5f
lines 15–16why, one step back15 concat, MethodType, FunctionType, internalcode, next, \16 object_type_reprInclude statements can now be marked with ``ignore missing`` to skipArmin Ronacherbefore adoption37f58ce
lines 17–18why, one step back17from jinja2.exceptions import UndefinedError, TemplateRuntimeError, \18 TemplateNotFoundLinked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 19–21why, one step back192021# these variables are exported to the template runtimeAdded support for optional `scoped` modifier to blocks.Armin Ronacherbefore adoption74a0cd9
line 22why, one step back22__all__ = ['LoopContext', 'TemplateReference', 'Macro', 'Markup',Linked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
line 23why, one step back23 'TemplateRuntimeError', 'missing', 'concat', 'escape',More Python 3 support.Armin Ronacherbefore adoptionbd35772
lines 24–25why, one step back24 'markup_join', 'unicode_join', 'to_string',25 'TemplateNotFound']Linked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 26–30why, one step back262728#: the types we support for context functions29_context_function_types = (FunctionType, MethodType)30More Python 3 support.Armin Ronacherbefore adoptionbd35772
lines 31–34why, one step back31#: the name of the function that is used to convert something into32#: a string. 2to3 will adopt that automatically and the generated33#: code can take advantage of it.34to_string = unicodeLinked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
line 35why, one step back35More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 36why, one step back36Linked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 37–52why, one step back37def markup_join(seq):38 """Concatenation that escapes if necessary and converts to unicode."""39 buf = []40 iterator = imap(soft_unicode, seq)41 for arg in iterator:42 buf.append(arg)43 if hasattr(arg, '__html__'):44 return Markup(u'').join(chain(buf, iterator))45 return concat(buf)464748def unicode_join(seq):49 """Simple args to unicode conversion and concatenation."""50 return concat(imap(unicode, seq))5152Added support for optional `scoped` modifier to blocks.Armin Ronacherbefore adoption74a0cd9
lines 53–80why, one step back53def new_context(environment, template_name, blocks, vars=None,54 shared=None, globals=None, locals=None):55 """Internal helper to for context creation."""56 if vars is None:57 vars = {}58 if shared:59 parent = vars60 else:61 parent = dict(globals or (), **vars)62 if locals:63 # if the parent is shared a copy should be created because64 # we don't want to modify the dict passed65 if shared:66 parent = dict(parent)67 for key, value in locals.iteritems():68 if key[:2] == 'l_' and value is not missing:69 parent[key[2:]] = value70 return Context(environment, parent, template_name, blocks)717273class TemplateReference(object):74 """The `self` in templates."""7576 def __init__(self, context):77 self.__context = context7879 def __getitem__(self, name):80 blocks = self.__context.blocks[name]autoescape no longer is a plain boolean value but can also be a functionArmin Ronacherbefore adoption1da23d1
line 81why, one step back81 wrap = self.__context.eval_ctx.autoescape and \Added support for optional `scoped` modifier to blocks.Armin Ronacherbefore adoption74a0cd9
lines 82–91why, one step back82 Markup or (lambda x: x)83 return BlockReference(name, self.__context, blocks, 0)8485 def __repr__(self):86 return '<%s %r>' % (87 self.__class__.__name__,88 self.__context.name89 )9091Linked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 92–110why, one step back92class Context(object):93 """The template context holds the variables of a template. It stores the94 values passed to the template and also the names the template exports.95 Creating instances is neither supported nor useful as it's created96 automatically at various stages of the template evaluation and should not97 be created by hand.9899 The context is immutable. Modifications on :attr:`parent` **must not**100 happen and modifications on :attr:`vars` are allowed from generated101 template code only. Template filters and global functions marked as102 :func:`contextfunction`\s get the active context passed as first argument103 and are allowed to access the context read-only.104105 The template context supports read only dict operations (`get`,106 `keys`, `values`, `items`, `iterkeys`, `itervalues`, `iteritems`,107 `__getitem__`, `__contains__`). Additionally there is a :meth:`resolve`108 method that doesn't fail with a `KeyError` but returns an109 :class:`Undefined` object for missing variables.110 """Biggest change to Jinja since the 1.x migration: added evaluation contextsArmin Ronacherbefore adoption8346bd7
lines 111–112why, one step back111 __slots__ = ('parent', 'vars', 'environment', 'eval_ctx', 'exported_vars',112 'name', 'blocks', '__weakref__')Linked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 113–115why, one step back113114 def __init__(self, environment, parent, name, blocks):115 self.parent = parentReverted [73b04625ab54]. The old behavior is the new behavior, the otherArmin Ronacherbefore adoption2f0d659
line 116why, one step back116 self.vars = {}Linked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
line 117why, one step back117 self.environment = environmentautoescape no longer is a plain boolean value but can also be a functionArmin Ronacherbefore adoption1da23d1
line 118why, one step back118 self.eval_ctx = EvalContext(self.environment, name)Linked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 119–130why, one step back119 self.exported_vars = set()120 self.name = name121122 # create the initial mapping of blocks. Whenever template inheritance123 # takes place the runtime will update this mapping with the new blocks124 # from the template.125 self.blocks = dict((k, [v]) for k, v in blocks.iteritems())126127 def super(self, name, current):128 """Render a parent block."""129 try:130 blocks = self.blocks[name]Unified some code in the super/template reference system.Armin Ronacherbefore adoptionc347ed0
lines 131–132why, one step back131 index = blocks.index(current) + 1132 blocks[index]Linked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 133–136why, one step back133 except LookupError:134 return self.environment.undefined('there is no parent block '135 'called %r.' % name,136 name='super')Unified some code in the super/template reference system.Armin Ronacherbefore adoptionc347ed0
line 137why, one step back137 return BlockReference(name, self, blocks, index)Linked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 138–167why, one step back138139 def get(self, key, default=None):140 """Returns an item from the template context, if it doesn't exist141 `default` is returned.142 """143 try:144 return self[key]145 except KeyError:146 return default147148 def resolve(self, key):149 """Looks up a variable like `__getitem__` or `get` but returns an150 :class:`Undefined` object with the name of the name looked up.151 """152 if key in self.vars:153 return self.vars[key]154 if key in self.parent:155 return self.parent[key]156 return self.environment.undefined(name=key)157158 def get_exported(self):159 """Get a new dict with the exported variables."""160 return dict((k, self.vars[k]) for k in self.exported_vars)161162 def get_all(self):163 """Return a copy of the complete context as dict including the164 exported variables.165 """166 return dict(self.parent, **self.vars)167Improved Jinja's debugging support by introducing "@internalcode" which marks code objects that are skipped on tracebacks. Also template errors are now translated as well to help the pylons debugger.Armin Ronacherbefore adoptiond416a97
line 168why, one step back168 @internalcodeLinked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 169–179why, one step back169 def call(__self, __obj, *args, **kwargs):170 """Call the callable with the arguments and keyword arguments171 provided but inject the active context or environment as first172 argument if the callable is a :func:`contextfunction` or173 :func:`environmentfunction`.174 """175 if __debug__:176 __traceback_hide__ = True177 if isinstance(__obj, _context_function_types):178 if getattr(__obj, 'contextfunction', 0):179 args = (__self,) + argsBiggest change to Jinja since the 1.x migration: added evaluation contextsArmin Ronacherbefore adoption8346bd7
lines 180–181why, one step back180 elif getattr(__obj, 'evalcontextfunction', 0):181 args = (__self.eval_ctx,) + argsLinked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 182–185why, one step back182 elif getattr(__obj, 'environmentfunction', 0):183 args = (__self.environment,) + args184 return __obj(*args, **kwargs)185Added support for optional `scoped` modifier to blocks.Armin Ronacherbefore adoption74a0cd9
lines 186–187why, one step back186 def derived(self, locals=None):187 """Internal helper function to create a derived context."""Added proper super() support for scoped blocks.Armin Ronacherbefore adoption3f1d8f1
lines 188–189why, one step back188 context = new_context(self.environment, self.name, {},189 self.parent, True, None, locals)Biggest change to Jinja since the 1.x migration: added evaluation contextsArmin Ronacherbefore adoption8346bd7
line 190why, one step back190 context.eval_ctx = self.eval_ctxAdded proper super() support for scoped blocks.Armin Ronacherbefore adoption3f1d8f1
lines 191–192why, one step back191 context.blocks.update((k, list(v)) for k, v in self.blocks.iteritems())192 return contextAdded support for optional `scoped` modifier to blocks.Armin Ronacherbefore adoption74a0cd9
line 193why, one step back193Linked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 194–202why, one step back194 def _all(meth):195 proxy = lambda self: getattr(self.get_all(), meth)()196 proxy.__doc__ = getattr(dict, meth).__doc__197 proxy.__name__ = meth198 return proxy199200 keys = _all('keys')201 values = _all('values')202 items = _all('items')Started to work on Python 3 support.Armin Ronacherbefore adoption42a1988
lines 203–208why, one step back203204 # not available on python 3205 if hasattr(dict, 'iterkeys'):206 iterkeys = _all('iterkeys')207 itervalues = _all('itervalues')208 iteritems = _all('iteritems')Linked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 209–230why, one step back209 del _all210211 def __contains__(self, name):212 return name in self.vars or name in self.parent213214 def __getitem__(self, key):215 """Lookup a variable or raise `KeyError` if the variable is216 undefined.217 """218 item = self.resolve(key)219 if isinstance(item, Undefined):220 raise KeyError(key)221 return item222223 def __repr__(self):224 return '<%s %s of %r>' % (225 self.__class__.__name__,226 repr(self.get_all()),227 self.name228 )229230Various cleanups and added custom cycler.Armin Ronacherbefore adoptionccae055
line 231why, one step back231# register the context as mapping if possibleLinked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
line 232why, one step back232try:Various cleanups and added custom cycler.Armin Ronacherbefore adoptionccae055
lines 233–234why, one step back233 from collections import Mapping234 Mapping.register(Context)Linked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 235–236why, one step back235except ImportError:236 passUnified some code in the super/template reference system.Armin Ronacherbefore adoptionc347ed0
lines 237–257why, one step back237238239class BlockReference(object):240 """One block on a template reference."""241242 def __init__(self, name, context, stack, depth):243 self.name = name244 self._context = context245 self._stack = stack246 self._depth = depth247248 @property249 def super(self):250 """Super the block."""251 if self._depth + 1 >= len(self._stack):252 return self._context.environment. \253 undefined('there is no parent block called %r.' %254 self.name, name='super')255 return BlockReference(self.name, self._context, self._stack,256 self._depth + 1)257Improved Jinja's debugging support by introducing "@internalcode" which marks code objects that are skipped on tracebacks. Also template errors are now translated as well to help the pylons debugger.Armin Ronacherbefore adoptiond416a97
line 258why, one step back258 @internalcodeUnified some code in the super/template reference system.Armin Ronacherbefore adoptionc347ed0
lines 259–260why, one step back259 def __call__(self):260 rv = concat(self._stack[self._depth](self._context))autoescape no longer is a plain boolean value but can also be a functionArmin Ronacherbefore adoption1da23d1
line 261why, one step back261 if self._context.eval_ctx.autoescape:Unified some code in the super/template reference system.Armin Ronacherbefore adoptionc347ed0
lines 262–263why, one step back262 rv = Markup(rv)263 return rvLinked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 264–300why, one step back264265266class LoopContext(object):267 """A loop context for dynamic iteration."""268269 def __init__(self, iterable, recurse=None):270 self._iterator = iter(iterable)271 self._recurse = recurse272 self.index0 = -1273274 # try to get the length of the iterable early. This must be done275 # here because there are some broken iterators around where there276 # __len__ is the number of iterations left (i'm looking at your277 # listreverseiterator!).278 try:279 self._length = len(iterable)280 except (TypeError, AttributeError):281 self._length = None282283 def cycle(self, *args):284 """Cycles among the arguments with the current loop index."""285 if not args:286 raise TypeError('no items for cycling given')287 return args[self.index0 % len(args)]288289 first = property(lambda x: x.index0 == 0)290 last = property(lambda x: x.index0 + 1 == x.length)291 index = property(lambda x: x.index0 + 1)292 revindex = property(lambda x: x.length - x.index0)293 revindex0 = property(lambda x: x.length - x.index)294295 def __len__(self):296 return self.length297298 def __iter__(self):299 return LoopContextIterator(self)300Improved Jinja's debugging support by introducing "@internalcode" which marks code objects that are skipped on tracebacks. Also template errors are now translated as well to help the pylons debugger.Armin Ronacherbefore adoptiond416a97
line 301why, one step back301 @internalcodeLinked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 302–309why, one step back302 def loop(self, iterable):303 if self._recurse is None:304 raise TypeError('Tried to call non recursive loop. Maybe you '305 "forgot the 'recursive' modifier.")306 return self._recurse(iterable, self._recurse)307308 # a nifty trick to enhance the error message if someone tried to call309 # the the loop without or with too many arguments.broke a line into two. (test commit)Armin Ronacherbefore adoption2966f17
lines 310–311why, one step back310 __call__ = loop311 del loopLinked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 312–345why, one step back312313 @property314 def length(self):315 if self._length is None:316 # if was not possible to get the length of the iterator when317 # the loop context was created (ie: iterating over a generator)318 # we have to convert the iterable into a sequence and use the319 # length of that.320 iterable = tuple(self._iterator)321 self._iterator = iter(iterable)322 self._length = len(iterable) + self.index0 + 1323 return self._length324325 def __repr__(self):326 return '<%s %r/%r>' % (327 self.__class__.__name__,328 self.index,329 self.length330 )331332333class LoopContextIterator(object):334 """The iterator for a loop context."""335 __slots__ = ('context',)336337 def __init__(self, context):338 self.context = context339340 def __iter__(self):341 return self342343 def next(self):344 ctx = self.context345 ctx.index0 += 1More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 346why, one step back346 return next(ctx._iterator), ctxLinked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 347–363why, one step back347348349class Macro(object):350 """Wraps a macro."""351352 def __init__(self, environment, func, name, arguments, defaults,353 catch_kwargs, catch_varargs, caller):354 self._environment = environment355 self._func = func356 self._argument_count = len(arguments)357 self.name = name358 self.arguments = arguments359 self.defaults = defaults360 self.catch_kwargs = catch_kwargs361 self.catch_varargs = catch_varargs362 self.caller = caller363Improved Jinja's debugging support by introducing "@internalcode" which marks code objects that are skipped on tracebacks. Also template errors are now translated as well to help the pylons debugger.Armin Ronacherbefore adoptiond416a97
line 364why, one step back364 @internalcodeLinked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 365–393why, one step back365 def __call__(self, *args, **kwargs):366 arguments = []367 for idx, name in enumerate(self.arguments):368 try:369 value = args[idx]370 except:371 try:372 value = kwargs.pop(name)373 except:374 try:375 value = self.defaults[idx - self._argument_count]376 except:377 value = self._environment.undefined(378 'parameter %r was not provided' % name, name=name)379 arguments.append(value)380381 # it's important that the order of these arguments does not change382 # if not also changed in the compiler's `function_scoping` method.383 # the order is caller, keyword arguments, positional arguments!384 if self.caller:385 caller = kwargs.pop('caller', None)386 if caller is None:387 caller = self._environment.undefined('No caller defined',388 name='caller')389 arguments.append(caller)390 if self.catch_kwargs:391 arguments.append(kwargs)392 elif kwargs:393 raise TypeError('macro %r takes no keyword argument %r' %More Python 3 support.Armin Ronacherbefore adoptionbd35772
line 394why, one step back394 (self.name, next(iter(kwargs))))Linked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 395–425why, one step back395 if self.catch_varargs:396 arguments.append(args[self._argument_count:])397 elif len(args) > self._argument_count:398 raise TypeError('macro %r takes not more than %d argument(s)' %399 (self.name, len(self.arguments)))400 return self._func(*arguments)401402 def __repr__(self):403 return '<%s %s>' % (404 self.__class__.__name__,405 self.name is None and 'anonymous' or repr(self.name)406 )407408409class Undefined(object):410 """The default undefined type. This undefined type can be printed and411 iterated over, but every other access will raise an :exc:`UndefinedError`:412413 >>> foo = Undefined(name='foo')414 >>> str(foo)415 ''416 >>> not foo417 True418 >>> foo + 42419 Traceback (most recent call last):420 ...421 UndefinedError: 'foo' is undefined422 """423 __slots__ = ('_undefined_hint', '_undefined_obj', '_undefined_name',424 '_undefined_exception')425Undefineds give better hints for `None` objects now.Armin Ronacherbefore adoption4855908
line 426why, one step back426 def __init__(self, hint=None, obj=missing, name=None, exc=UndefinedError):Linked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 427–431why, one step back427 self._undefined_hint = hint428 self._undefined_obj = obj429 self._undefined_name = name430 self._undefined_exception = exc431Improved Jinja's debugging support by introducing "@internalcode" which marks code objects that are skipped on tracebacks. Also template errors are now translated as well to help the pylons debugger.Armin Ronacherbefore adoptiond416a97
line 432why, one step back432 @internalcodeLinked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 433–437why, one step back433 def _fail_with_undefined_error(self, *args, **kwargs):434 """Regular callback function for undefined objects that raises an435 `UndefinedError` on call.436 """437 if self._undefined_hint is None:Undefineds give better hints for `None` objects now.Armin Ronacherbefore adoption4855908
line 438why, one step back438 if self._undefined_obj is missing:Linked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 439–440why, one step back439 hint = '%r is undefined' % self._undefined_name440 elif not isinstance(self._undefined_name, basestring):Improved error message for undefinedsArmin Ronacherbefore adoption98dbf5f
lines 441–442why, one step back441 hint = '%s has no element %r' % (442 object_type_repr(self._undefined_obj),Linked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 443–445why, one step back443 self._undefined_name444 )445 else:Improved error message for undefinedsArmin Ronacherbefore adoption98dbf5f
lines 446–447why, one step back446 hint = '%r has no attribute %r' % (447 object_type_repr(self._undefined_obj),Linked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 448–454why, one step back448 self._undefined_name449 )450 else:451 hint = self._undefined_hint452 raise self._undefined_exception(hint)453454 __add__ = __radd__ = __mul__ = __rmul__ = __div__ = __rdiv__ = \Fixed a small bug with the undefined object: the error message on divisions with undefined objects was misleading.Armin Ronacherbefore adoption9efe081
line 455why, one step back455 __truediv__ = __rtruediv__ = __floordiv__ = __rfloordiv__ = \Linked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 456–457why, one step back456 __mod__ = __rmod__ = __pos__ = __neg__ = __call__ = \457 __getattr__ = __getitem__ = __lt__ = __le__ = __gt__ = __ge__ = \Fixed a small bug with the undefined object: the error message on divisions with undefined objects was misleading.Armin Ronacherbefore adoption9efe081
lines 458–459why, one step back458 __int__ = __float__ = __complex__ = __pow__ = __rpow__ = \459 _fail_with_undefined_errorLinked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 460–461why, one step back460461 def __str__(self):Various cleanups and added custom cycler.Armin Ronacherbefore adoptionccae055
line 462why, one step back462 return unicode(self).encode('utf-8')Linked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
line 463why, one step back463Added comment to why __unicode__ goes after __str__.Armin Ronacherbefore adoptionacbd408
lines 464–467why, one step back464 # unicode goes after __str__ because we configured 2to3 to rename465 # __unicode__ to __str__. because the 2to3 tree is not designed to466 # remove nodes from it, we leave the above __str__ around and let467 # it override at runtime.Linked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 468–501why, one step back468 def __unicode__(self):469 return u''470471 def __len__(self):472 return 0473474 def __iter__(self):475 if 0:476 yield None477478 def __nonzero__(self):479 return False480481 def __repr__(self):482 return 'Undefined'483484485class DebugUndefined(Undefined):486 """An undefined that returns the debug info when printed.487488 >>> foo = DebugUndefined(name='foo')489 >>> str(foo)490 '{{ foo }}'491 >>> not foo492 True493 >>> foo + 42494 Traceback (most recent call last):495 ...496 UndefinedError: 'foo' is undefined497 """498 __slots__ = ()499500 def __unicode__(self):501 if self._undefined_hint is None:Undefineds give better hints for `None` objects now.Armin Ronacherbefore adoption4855908
line 502why, one step back502 if self._undefined_obj is missing:Linked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 503–504why, one step back503 return u'{{ %s }}' % self._undefined_name504 return '{{ no such element: %s[%r] }}' % (Improved error message for undefinedsArmin Ronacherbefore adoption98dbf5f
line 505why, one step back505 object_type_repr(self._undefined_obj),Linked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 506–530why, one step back506 self._undefined_name507 )508 return u'{{ undefined value printed: %s }}' % self._undefined_hint509510511class StrictUndefined(Undefined):512 """An undefined that barks on print and iteration as well as boolean513 tests and all kinds of comparisons. In other words: you can do nothing514 with it except checking if it's defined using the `defined` test.515516 >>> foo = StrictUndefined(name='foo')517 >>> str(foo)518 Traceback (most recent call last):519 ...520 UndefinedError: 'foo' is undefined521 >>> not foo522 Traceback (most recent call last):523 ...524 UndefinedError: 'foo' is undefined525 >>> foo + 42526 Traceback (most recent call last):527 ...528 UndefinedError: 'foo' is undefined529 """530 __slots__ = ()Propably delaying release for better python 3 support. Started working onArmin Ronacherbefore adoption0faa861
lines 531–532why, one step back531 __iter__ = __unicode__ = __str__ = __len__ = __nonzero__ = __eq__ = \532 __ne__ = Undefined._fail_with_undefined_errorLinked from autoescape to markupArmin Ronacherbefore adoptionf7e405d
lines 533–537why, one step back533534535# remove remaining slots attributes, after the metaclass did the magic they536# are unneeded and irritating as they contain wrong data for the subclasses.537del Undefined.__slots__, DebugUndefined.__slots__, StrictUndefined.__slots__