<s> """<STR_LIT>""" <EOL> import sys <EOL> from itertools import chain , imap <EOL> from jinja2 . nodes import EvalContext , _context_function_types <EOL> from jinja2 . utils import Markup , partial , soft_unicode , escape , missing , concat , internalcode , next , object_type_repr <EOL> from jinja2 . exceptions import UndefinedError , TemplateRuntimeError , TemplateNotFound <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> to_string = unicode <EOL> identity = lambda x : x <EOL> def markup_join ( seq ) : <EOL> """<STR_LIT>""" <EOL> buf = [ ] <EOL> iterator = imap ( soft_unicode , seq ) <EOL> for arg in iterator : <EOL> buf . append ( arg ) <EOL> if hasattr ( arg , '<STR_LIT>' ) : <EOL> return Markup ( u'<STR_LIT>' ) . join ( chain ( buf , iterator ) ) <EOL> return concat ( buf ) <EOL> def unicode_join ( seq ) : <EOL> """<STR_LIT>""" <EOL> return concat ( imap ( unicode , seq ) ) <EOL> def new_context ( environment , template_name , blocks , vars = None , <EOL> shared = None , globals = None , locals = None ) : <EOL> """<STR_LIT>""" <EOL> if vars is None : <EOL> vars = { } <EOL> if shared : <EOL> parent = vars <EOL> else : <EOL> parent = dict ( globals or ( ) , ** vars ) <EOL> if locals : <EOL> if shared : <EOL> parent = dict ( parent ) <EOL> for key , value in locals . iteritems ( ) : <EOL> if key [ : <NUM_LIT:2> ] == '<STR_LIT>' and value is not missing : <EOL> parent [ key [ <NUM_LIT:2> : ] ] = value <EOL> return Context ( environment , parent , template_name , blocks ) <EOL> class TemplateReference ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , context ) : <EOL> self . __context = context <EOL> def __getitem__ ( self , name ) : <EOL> blocks = self . __context . blocks [ name ] <EOL> wrap = self . __context . eval_ctx . autoescape and Markup or ( lambda x : x ) <EOL> return BlockReference ( name , self . __context , blocks , <NUM_LIT:0> ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( <EOL> self . __class__ . __name__ , <EOL> self . __context . name <EOL> ) <EOL> class Context ( object ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def __init__ ( self , environment , parent , name , blocks ) : <EOL> self . parent = parent <EOL> self . vars = { } <EOL> self . environment = environment <EOL> self . eval_ctx = EvalContext ( self . environment , name ) <EOL> self . exported_vars = set ( ) <EOL> self . name = name <EOL> self . blocks = dict ( ( k , [ v ] ) for k , v in blocks . iteritems ( ) ) <EOL> def super ( self , name , current ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> blocks = self . blocks [ name ] <EOL> index = blocks . index ( current ) + <NUM_LIT:1> <EOL> blocks [ index ] <EOL> except LookupError : <EOL> return self . environment . undefined ( '<STR_LIT>' <EOL> '<STR_LIT>' % name , <EOL> name = '<STR_LIT>' ) <EOL> return BlockReference ( name , self , blocks , index ) <EOL> def get ( self , key , default = None ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return self [ key ] <EOL> except KeyError : <EOL> return default <EOL> def resolve ( self , key ) : <EOL> """<STR_LIT>""" <EOL> if key in self . vars : <EOL> return self . vars [ key ] <EOL> if key in self . parent : <EOL> return self . parent [ key ] <EOL> return self . environment . undefined ( name = key ) <EOL> def get_exported ( self ) : <EOL> """<STR_LIT>""" <EOL> return dict ( ( k , self . vars [ k ] ) for k in self . exported_vars ) <EOL> def get_all ( self ) : <EOL> """<STR_LIT>""" <EOL> return dict ( self . parent , ** self . vars ) <EOL> @ internalcode <EOL> def call ( __self , __obj , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if __debug__ : <EOL> __traceback_hide__ = True <EOL> if isinstance ( __obj , _context_function_types ) : <EOL> if getattr ( __obj , '<STR_LIT>' , <NUM_LIT:0> ) : <EOL> args = ( __self , ) + args <EOL> elif getattr ( __obj , '<STR_LIT>' , <NUM_LIT:0> ) : <EOL> args = ( __self . eval_ctx , ) + args <EOL> elif getattr ( __obj , '<STR_LIT>' , <NUM_LIT:0> ) : <EOL> args = ( __self . environment , ) + args <EOL> try : <EOL> return __obj ( * args , ** kwargs ) <EOL> except StopIteration : <EOL> return __self . environment . undefined ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def derived ( self , locals = None ) : <EOL> """<STR_LIT>""" <EOL> context = new_context ( self . environment , self . name , { } , <EOL> self . parent , True , None , locals ) <EOL> context . eval_ctx = self . eval_ctx <EOL> context . blocks . update ( ( k , list ( v ) ) for k , v in self . blocks . iteritems ( ) ) <EOL> return context <EOL> def _all ( meth ) : <EOL> proxy = lambda self : getattr ( self . get_all ( ) , meth ) ( ) <EOL> proxy . __doc__ = getattr ( dict , meth ) . __doc__ <EOL> proxy . __name__ = meth <EOL> return proxy <EOL> keys = _all ( '<STR_LIT>' ) <EOL> values = _all ( '<STR_LIT>' ) <EOL> items = _all ( '<STR_LIT>' ) <EOL> if hasattr ( dict , '<STR_LIT>' ) : <EOL> iterkeys = _all ( '<STR_LIT>' ) <EOL> itervalues = _all ( '<STR_LIT>' ) <EOL> iteritems = _all ( '<STR_LIT>' ) <EOL> del _all <EOL> def __contains__ ( self , name ) : <EOL> return name in self . vars or name in self . parent <EOL> def __getitem__ ( self , key ) : <EOL> """<STR_LIT>""" <EOL> item = self . resolve ( key ) <EOL> if isinstance ( item , Undefined ) : <EOL> raise KeyError ( key ) <EOL> return item <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( <EOL> self . __class__ . __name__ , <EOL> repr ( self . get_all ( ) ) , <EOL> self . name <EOL> ) <EOL> try : <EOL> from collections import Mapping <EOL> Mapping . register ( Context ) <EOL> except ImportError : <EOL> pass <EOL> class BlockReference ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , context , stack , depth ) : <EOL> self . name = name <EOL> self . _context = context <EOL> self . _stack = stack <EOL> self . _depth = depth <EOL> @ property <EOL> def super ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _depth + <NUM_LIT:1> >= len ( self . _stack ) : <EOL> return self . _context . environment . undefined ( '<STR_LIT>' % <EOL> self . name , name = '<STR_LIT>' ) <EOL> return BlockReference ( self . name , self . _context , self . _stack , <EOL> self . _depth + <NUM_LIT:1> ) <EOL> @ internalcode <EOL> def __call__ ( self ) : <EOL> rv = concat ( self . _stack [ self . _depth ] ( self . _context ) ) <EOL> if self . _context . eval_ctx . autoescape : <EOL> rv = Markup ( rv ) <EOL> return rv <EOL> class LoopContext ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , iterable , recurse = None ) : <EOL> self . _iterator = iter ( iterable ) <EOL> self . _recurse = recurse <EOL> self . index0 = - <NUM_LIT:1> <EOL> try : <EOL> self . _length = len ( iterable ) <EOL> except ( TypeError , AttributeError ) : <EOL> self . _length = None <EOL> def cycle ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> if not args : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> return args [ self . index0 % len ( args ) ] <EOL> first = property ( lambda x : x . index0 == <NUM_LIT:0> ) <EOL> last = property ( lambda x : x . index0 + <NUM_LIT:1> == x . length ) <EOL> index = property ( lambda x : x . index0 + <NUM_LIT:1> ) <EOL> revindex = property ( lambda x : x . length - x . index0 ) <EOL> revindex0 = property ( lambda x : x . length - x . index ) <EOL> def __len__ ( self ) : <EOL> return self . length <EOL> def __iter__ ( self ) : <EOL> return LoopContextIterator ( self ) <EOL> @ internalcode <EOL> def loop ( self , iterable ) : <EOL> if self . _recurse is None : <EOL> raise TypeError ( '<STR_LIT>' <EOL> "<STR_LIT>" ) <EOL> return self . _recurse ( iterable , self . _recurse ) <EOL> __call__ = loop <EOL> del loop <EOL> @ property <EOL> def length ( self ) : <EOL> if self . _length is None : <EOL> iterable = tuple ( self . _iterator ) <EOL> self . _iterator = iter ( iterable ) <EOL> self . _length = len ( iterable ) + self . index0 + <NUM_LIT:1> <EOL> return self . _length <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( <EOL> self . __class__ . __name__ , <EOL> self . index , <EOL> self . length <EOL> ) <EOL> class LoopContextIterator ( object ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = ( '<STR_LIT>' , ) <EOL> def __init__ ( self , context ) : <EOL> self . context = context <EOL> def __iter__ ( self ) : <EOL> return self <EOL> def next ( self ) : <EOL> ctx = self . context <EOL> ctx . index0 += <NUM_LIT:1> <EOL> return next ( ctx . _iterator ) , ctx <EOL> class Macro ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , environment , func , name , arguments , defaults , <EOL> catch_kwargs , catch_varargs , caller ) : <EOL> self . _environment = environment <EOL> self . _func = func <EOL> self . _argument_count = len ( arguments ) <EOL> self . name = name <EOL> self . arguments = arguments <EOL> self . defaults = defaults <EOL> self . catch_kwargs = catch_kwargs <EOL> self . catch_varargs = catch_varargs <EOL> self . caller = caller <EOL> @ internalcode <EOL> def __call__ ( self , * args , ** kwargs ) : <EOL> arguments = list ( args [ : self . _argument_count ] ) <EOL> off = len ( arguments ) <EOL> if off != self . _argument_count : <EOL> for idx , name in enumerate ( self . arguments [ len ( arguments ) : ] ) : <EOL> try : <EOL> value = kwargs . pop ( name ) <EOL> except KeyError : <EOL> try : <EOL> value = self . defaults [ idx - self . _argument_count + off ] <EOL> except IndexError : <EOL> value = self . _environment . undefined ( <EOL> '<STR_LIT>' % name , name = name ) <EOL> arguments . append ( value ) <EOL> if self . caller : <EOL> caller = kwargs . pop ( '<STR_LIT>' , None ) <EOL> if caller is None : <EOL> caller = self . _environment . undefined ( '<STR_LIT>' , <EOL> name = '<STR_LIT>' ) <EOL> arguments . append ( caller ) <EOL> if self . catch_kwargs : <EOL> arguments . append ( kwargs ) <EOL> elif kwargs : <EOL> raise TypeError ( '<STR_LIT>' % <EOL> ( self . name , next ( iter ( kwargs ) ) ) ) <EOL> if self . catch_varargs : <EOL> arguments . append ( args [ self . _argument_count : ] ) <EOL> elif len ( args ) > self . _argument_count : <EOL> raise TypeError ( '<STR_LIT>' % <EOL> ( self . name , len ( self . arguments ) ) ) <EOL> return self . _func ( * arguments ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( <EOL> self . __class__ . __name__ , <EOL> self . name is None and '<STR_LIT>' or repr ( self . name ) <EOL> ) <EOL> class Undefined ( object ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> def __init__ ( self , hint = None , obj = missing , name = None , exc = UndefinedError ) : <EOL> self . _undefined_hint = hint <EOL> self . _undefined_obj = obj <EOL> self . _undefined_name = name <EOL> self . _undefined_exception = exc <EOL> @ internalcode <EOL> def _fail_with_undefined_error ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if self . _undefined_hint is None : <EOL> if self . _undefined_obj is missing : <EOL> hint = '<STR_LIT>' % self . _undefined_name <EOL> elif not isinstance ( self . _undefined_name , basestring ) : <EOL> hint = '<STR_LIT>' % ( <EOL> object_type_repr ( self . _undefined_obj ) , <EOL> self . _undefined_name <EOL> ) <EOL> else : <EOL> hint = '<STR_LIT>' % ( <EOL> object_type_repr ( self . _undefined_obj ) , <EOL> self . _undefined_name <EOL> ) <EOL> else : <EOL> hint = self . _undefined_hint <EOL> raise self . _undefined_exception ( hint ) <EOL> __add__ = __radd__ = __mul__ = __rmul__ = __div__ = __rdiv__ = __truediv__ = __rtruediv__ = __floordiv__ = __rfloordiv__ = __mod__ = __rmod__ = __pos__ = __neg__ = __call__ = __getattr__ = __getitem__ = __lt__ = __le__ = __gt__ = __ge__ = __int__ = __float__ = __complex__ = __pow__ = __rpow__ = _fail_with_undefined_error <EOL> def __str__ ( self ) : <EOL> return unicode ( self ) . encode ( '<STR_LIT:utf-8>' ) <EOL> def __unicode__ ( self ) : <EOL> return u'<STR_LIT>' <EOL> def __len__ ( self ) : <EOL> return <NUM_LIT:0> <EOL> def __iter__ ( self ) : <EOL> if <NUM_LIT:0> : <EOL> yield None <EOL> def __nonzero__ ( self ) : <EOL> return False <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' <EOL> class DebugUndefined ( Undefined ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = ( ) <EOL> def __unicode__ ( self ) : <EOL> if self . _undefined_hint is None : <EOL> if self . _undefined_obj is missing : <EOL> return u'<STR_LIT>' % self . _undefined_name <EOL> return '<STR_LIT>' % ( <EOL> object_type_repr ( self . _undefined_obj ) , <EOL> self . _undefined_name <EOL> ) <EOL> return u'<STR_LIT>' % self . _undefined_hint <EOL> class StrictUndefined ( Undefined ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = ( ) <EOL> __iter__ = __unicode__ = __str__ = __len__ = __nonzero__ = __eq__ = __ne__ = __bool__ = Undefined . _fail_with_undefined_error <EOL> del Undefined . __slots__ , DebugUndefined . __slots__ , StrictUndefined . __slots__ </s>
