<s> """<STR_LIT>""" <EOL> from mako import exceptions , ast , util , filters <EOL> import re <EOL> class Node ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , source , lineno , pos , filename ) : <EOL> self . source = source <EOL> self . lineno = lineno <EOL> self . pos = pos <EOL> self . filename = filename <EOL> @ property <EOL> def exception_kwargs ( self ) : <EOL> return { '<STR_LIT:source>' : self . source , '<STR_LIT>' : self . lineno , <EOL> '<STR_LIT>' : self . pos , '<STR_LIT:filename>' : self . filename } <EOL> def get_children ( self ) : <EOL> return [ ] <EOL> def accept_visitor ( self , visitor ) : <EOL> def traverse ( node ) : <EOL> for n in node . get_children ( ) : <EOL> n . accept_visitor ( visitor ) <EOL> method = getattr ( visitor , "<STR_LIT>" + self . __class__ . __name__ , traverse ) <EOL> method ( self ) <EOL> class TemplateNode ( Node ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , filename ) : <EOL> super ( TemplateNode , self ) . __init__ ( '<STR_LIT>' , <NUM_LIT:0> , <NUM_LIT:0> , filename ) <EOL> self . nodes = [ ] <EOL> self . page_attributes = { } <EOL> def get_children ( self ) : <EOL> return self . nodes <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( <EOL> util . sorted_dict_repr ( self . page_attributes ) , <EOL> self . nodes ) <EOL> class ControlLine ( Node ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , keyword , isend , text , ** kwargs ) : <EOL> super ( ControlLine , self ) . __init__ ( ** kwargs ) <EOL> self . text = text <EOL> self . keyword = keyword <EOL> self . isend = isend <EOL> self . is_primary = keyword in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if self . isend : <EOL> self . _declared_identifiers = [ ] <EOL> self . _undeclared_identifiers = [ ] <EOL> else : <EOL> code = ast . PythonFragment ( text , ** self . exception_kwargs ) <EOL> self . _declared_identifiers = code . declared_identifiers <EOL> self . _undeclared_identifiers = code . undeclared_identifiers <EOL> def declared_identifiers ( self ) : <EOL> return self . _declared_identifiers <EOL> def undeclared_identifiers ( self ) : <EOL> return self . _undeclared_identifiers <EOL> def is_ternary ( self , keyword ) : <EOL> """<STR_LIT>""" <EOL> return keyword in { <EOL> '<STR_LIT>' : set ( [ '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> '<STR_LIT>' : set ( [ '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> '<STR_LIT>' : set ( [ '<STR_LIT>' ] ) <EOL> } . get ( self . keyword , [ ] ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( <EOL> self . keyword , <EOL> self . text , <EOL> self . isend , <EOL> ( self . lineno , self . pos ) <EOL> ) <EOL> class Text ( Node ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , content , ** kwargs ) : <EOL> super ( Text , self ) . __init__ ( ** kwargs ) <EOL> self . content = content <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . content , ( self . lineno , self . pos ) ) <EOL> class Code ( Node ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , text , ismodule , ** kwargs ) : <EOL> super ( Code , self ) . __init__ ( ** kwargs ) <EOL> self . text = text <EOL> self . ismodule = ismodule <EOL> self . code = ast . PythonCode ( text , ** self . exception_kwargs ) <EOL> def declared_identifiers ( self ) : <EOL> return self . code . declared_identifiers <EOL> def undeclared_identifiers ( self ) : <EOL> return self . code . undeclared_identifiers <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( <EOL> self . text , <EOL> self . ismodule , <EOL> ( self . lineno , self . pos ) <EOL> ) <EOL> class Comment ( Node ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , text , ** kwargs ) : <EOL> super ( Comment , self ) . __init__ ( ** kwargs ) <EOL> self . text = text <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . text , ( self . lineno , self . pos ) ) <EOL> class Expression ( Node ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , text , escapes , ** kwargs ) : <EOL> super ( Expression , self ) . __init__ ( ** kwargs ) <EOL> self . text = text <EOL> self . escapes = escapes <EOL> self . escapes_code = ast . ArgumentList ( escapes , ** self . exception_kwargs ) <EOL> self . code = ast . PythonCode ( text , ** self . exception_kwargs ) <EOL> def declared_identifiers ( self ) : <EOL> return [ ] <EOL> def undeclared_identifiers ( self ) : <EOL> return self . code . undeclared_identifiers . union ( <EOL> self . escapes_code . undeclared_identifiers . difference ( <EOL> set ( filters . DEFAULT_ESCAPES . keys ( ) ) <EOL> ) <EOL> ) . difference ( self . code . declared_identifiers ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( <EOL> self . text , <EOL> self . escapes_code . args , <EOL> ( self . lineno , self . pos ) <EOL> ) <EOL> class _TagMeta ( type ) : <EOL> """<STR_LIT>""" <EOL> _classmap = { } <EOL> def __init__ ( cls , clsname , bases , dict ) : <EOL> if cls . __keyword__ is not None : <EOL> cls . _classmap [ cls . __keyword__ ] = cls <EOL> super ( _TagMeta , cls ) . __init__ ( clsname , bases , dict ) <EOL> def __call__ ( cls , keyword , attributes , ** kwargs ) : <EOL> if "<STR_LIT::>" in keyword : <EOL> ns , defname = keyword . split ( '<STR_LIT::>' ) <EOL> return type . __call__ ( CallNamespaceTag , ns , defname , <EOL> attributes , ** kwargs ) <EOL> try : <EOL> cls = _TagMeta . _classmap [ keyword ] <EOL> except KeyError : <EOL> raise exceptions . CompileException ( <EOL> "<STR_LIT>" % keyword , <EOL> source = kwargs [ '<STR_LIT:source>' ] , <EOL> lineno = kwargs [ '<STR_LIT>' ] , <EOL> pos = kwargs [ '<STR_LIT>' ] , <EOL> filename = kwargs [ '<STR_LIT:filename>' ] <EOL> ) <EOL> return type . __call__ ( cls , keyword , attributes , ** kwargs ) <EOL> class Tag ( Node ) : <EOL> """<STR_LIT>""" <EOL> __metaclass__ = _TagMeta <EOL> __keyword__ = None <EOL> def __init__ ( self , keyword , attributes , expressions , <EOL> nonexpressions , required , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( Tag , self ) . __init__ ( ** kwargs ) <EOL> self . keyword = keyword <EOL> self . attributes = attributes <EOL> self . _parse_attributes ( expressions , nonexpressions ) <EOL> missing = [ r for r in required if r not in self . parsed_attributes ] <EOL> if len ( missing ) : <EOL> raise exceptions . CompileException ( <EOL> "<STR_LIT>" % <EOL> "<STR_LIT:U+002C>" . join ( [ repr ( m ) for m in missing ] ) , <EOL> ** self . exception_kwargs ) <EOL> self . parent = None <EOL> self . nodes = [ ] <EOL> def is_root ( self ) : <EOL> return self . parent is None <EOL> def get_children ( self ) : <EOL> return self . nodes <EOL> def _parse_attributes ( self , expressions , nonexpressions ) : <EOL> undeclared_identifiers = set ( ) <EOL> self . parsed_attributes = { } <EOL> for key in self . attributes : <EOL> if key in expressions : <EOL> expr = [ ] <EOL> for x in re . compile ( r'<STR_LIT>' , <EOL> re . S ) . split ( self . attributes [ key ] ) : <EOL> m = re . compile ( r'<STR_LIT>' , re . S ) . match ( x ) <EOL> if m : <EOL> code = ast . PythonCode ( m . group ( <NUM_LIT:1> ) . rstrip ( ) , <EOL> ** self . exception_kwargs ) <EOL> undeclared_identifiers = undeclared_identifiers . union ( <EOL> code . undeclared_identifiers ) <EOL> expr . append ( '<STR_LIT>' % m . group ( <NUM_LIT:1> ) ) <EOL> else : <EOL> if x : <EOL> expr . append ( repr ( x ) ) <EOL> self . parsed_attributes [ key ] = "<STR_LIT>" . join ( expr ) or repr ( '<STR_LIT>' ) <EOL> elif key in nonexpressions : <EOL> if re . search ( r'<STR_LIT>' , self . attributes [ key ] ) : <EOL> raise exceptions . CompileException ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( key , self . keyword ) , <EOL> ** self . exception_kwargs ) <EOL> self . parsed_attributes [ key ] = repr ( self . attributes [ key ] ) <EOL> else : <EOL> raise exceptions . CompileException ( <EOL> "<STR_LIT>" % <EOL> ( self . keyword , key ) , <EOL> ** self . exception_kwargs ) <EOL> self . expression_undeclared_identifiers = undeclared_identifiers <EOL> def declared_identifiers ( self ) : <EOL> return [ ] <EOL> def undeclared_identifiers ( self ) : <EOL> return self . expression_undeclared_identifiers <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . __class__ . __name__ , <EOL> self . keyword , <EOL> util . sorted_dict_repr ( self . attributes ) , <EOL> ( self . lineno , self . pos ) , <EOL> self . nodes <EOL> ) <EOL> class IncludeTag ( Tag ) : <EOL> __keyword__ = '<STR_LIT>' <EOL> def __init__ ( self , keyword , attributes , ** kwargs ) : <EOL> super ( IncludeTag , self ) . __init__ ( <EOL> keyword , <EOL> attributes , <EOL> ( '<STR_LIT:file>' , '<STR_LIT>' , '<STR_LIT:args>' ) , <EOL> ( ) , ( '<STR_LIT:file>' , ) , ** kwargs ) <EOL> self . page_args = ast . PythonCode ( <EOL> "<STR_LIT>" % attributes . get ( '<STR_LIT:args>' , '<STR_LIT>' ) , <EOL> ** self . exception_kwargs ) <EOL> def declared_identifiers ( self ) : <EOL> return [ ] <EOL> def undeclared_identifiers ( self ) : <EOL> identifiers = self . page_args . undeclared_identifiers . difference ( set ( [ "<STR_LIT>" ] ) ) . difference ( self . page_args . declared_identifiers ) <EOL> return identifiers . union ( super ( IncludeTag , self ) . <EOL> undeclared_identifiers ( ) ) <EOL> class NamespaceTag ( Tag ) : <EOL> __keyword__ = '<STR_LIT>' <EOL> def __init__ ( self , keyword , attributes , ** kwargs ) : <EOL> super ( NamespaceTag , self ) . __init__ ( <EOL> keyword , attributes , <EOL> ( '<STR_LIT:file>' , ) , <EOL> ( '<STR_LIT:name>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( ) , ** kwargs ) <EOL> self . name = attributes . get ( '<STR_LIT:name>' , '<STR_LIT>' % hex ( abs ( id ( self ) ) ) ) <EOL> if not '<STR_LIT:name>' in attributes and not '<STR_LIT>' in attributes : <EOL> raise exceptions . CompileException ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> ** self . exception_kwargs ) <EOL> if '<STR_LIT:file>' in attributes and '<STR_LIT>' in attributes : <EOL> raise exceptions . CompileException ( <EOL> "<STR_LIT>" , <EOL> ** self . exception_kwargs <EOL> ) <EOL> def declared_identifiers ( self ) : <EOL> return [ ] <EOL> class TextTag ( Tag ) : <EOL> __keyword__ = '<STR_LIT:text>' <EOL> def __init__ ( self , keyword , attributes , ** kwargs ) : <EOL> super ( TextTag , self ) . __init__ ( <EOL> keyword , <EOL> attributes , ( ) , <EOL> ( '<STR_LIT>' ) , ( ) , ** kwargs ) <EOL> self . filter_args = ast . ArgumentList ( <EOL> attributes . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ** self . exception_kwargs ) <EOL> class DefTag ( Tag ) : <EOL> __keyword__ = '<STR_LIT>' <EOL> def __init__ ( self , keyword , attributes , ** kwargs ) : <EOL> super ( DefTag , self ) . __init__ ( <EOL> keyword , <EOL> attributes , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:name>' , ) , <EOL> ** kwargs ) <EOL> name = attributes [ '<STR_LIT:name>' ] <EOL> if re . match ( r'<STR_LIT>' , name ) : <EOL> raise exceptions . CompileException ( <EOL> "<STR_LIT>" , <EOL> ** self . exception_kwargs ) <EOL> self . function_decl = ast . FunctionDecl ( "<STR_LIT>" + name + "<STR_LIT>" , <EOL> ** self . exception_kwargs ) <EOL> self . name = self . function_decl . funcname <EOL> self . decorator = attributes . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . filter_args = ast . ArgumentList ( <EOL> attributes . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ** self . exception_kwargs ) <EOL> is_anonymous = False <EOL> is_block = False <EOL> @ property <EOL> def funcname ( self ) : <EOL> return self . function_decl . funcname <EOL> def get_argument_expressions ( self , ** kw ) : <EOL> return self . function_decl . get_argument_expressions ( ** kw ) <EOL> def declared_identifiers ( self ) : <EOL> return self . function_decl . argnames <EOL> def undeclared_identifiers ( self ) : <EOL> res = [ ] <EOL> for c in self . function_decl . defaults : <EOL> res += list ( ast . PythonCode ( c , ** self . exception_kwargs ) . <EOL> undeclared_identifiers ) <EOL> return res + list ( self . filter_args . undeclared_identifiers . difference ( filters . DEFAULT_ESCAPES . keys ( ) ) <EOL> ) <EOL> class BlockTag ( Tag ) : <EOL> __keyword__ = '<STR_LIT>' <EOL> def __init__ ( self , keyword , attributes , ** kwargs ) : <EOL> super ( BlockTag , self ) . __init__ ( <EOL> keyword , <EOL> attributes , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:args>' ) , <EOL> ( '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( ) , <EOL> ** kwargs ) <EOL> name = attributes . get ( '<STR_LIT:name>' ) <EOL> if name and not re . match ( r'<STR_LIT>' , name ) : <EOL> raise exceptions . CompileException ( <EOL> "<STR_LIT>" , <EOL> ** self . exception_kwargs ) <EOL> if not name and attributes . get ( '<STR_LIT:args>' , None ) : <EOL> raise exceptions . CompileException ( <EOL> "<STR_LIT>" , <EOL> ** self . exception_kwargs <EOL> ) <EOL> self . body_decl = ast . FunctionArgs ( attributes . get ( '<STR_LIT:args>' , '<STR_LIT>' ) , <EOL> ** self . exception_kwargs ) <EOL> self . name = name <EOL> self . decorator = attributes . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . filter_args = ast . ArgumentList ( <EOL> attributes . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ** self . exception_kwargs ) <EOL> is_block = True <EOL> @ property <EOL> def is_anonymous ( self ) : <EOL> return self . name is None <EOL> @ property <EOL> def funcname ( self ) : <EOL> return self . name or "<STR_LIT>" % ( self . lineno , ) <EOL> def get_argument_expressions ( self , ** kw ) : <EOL> return self . body_decl . get_argument_expressions ( ** kw ) <EOL> def declared_identifiers ( self ) : <EOL> return self . body_decl . argnames <EOL> def undeclared_identifiers ( self ) : <EOL> return [ ] <EOL> class CallTag ( Tag ) : <EOL> __keyword__ = '<STR_LIT>' <EOL> def __init__ ( self , keyword , attributes , ** kwargs ) : <EOL> super ( CallTag , self ) . __init__ ( keyword , attributes , <EOL> ( '<STR_LIT:args>' ) , ( '<STR_LIT>' , ) , ( '<STR_LIT>' , ) , ** kwargs ) <EOL> self . expression = attributes [ '<STR_LIT>' ] <EOL> self . code = ast . PythonCode ( self . expression , ** self . exception_kwargs ) <EOL> self . body_decl = ast . FunctionArgs ( attributes . get ( '<STR_LIT:args>' , '<STR_LIT>' ) , <EOL> ** self . exception_kwargs ) <EOL> def declared_identifiers ( self ) : <EOL> return self . code . declared_identifiers . union ( self . body_decl . argnames ) <EOL> def undeclared_identifiers ( self ) : <EOL> return self . code . undeclared_identifiers . difference ( self . code . declared_identifiers ) <EOL> class CallNamespaceTag ( Tag ) : <EOL> def __init__ ( self , namespace , defname , attributes , ** kwargs ) : <EOL> super ( CallNamespaceTag , self ) . __init__ ( <EOL> namespace + "<STR_LIT::>" + defname , <EOL> attributes , <EOL> tuple ( attributes . keys ( ) ) + ( '<STR_LIT:args>' , ) , <EOL> ( ) , <EOL> ( ) , <EOL> ** kwargs ) <EOL> self . expression = "<STR_LIT>" % ( <EOL> namespace , <EOL> defname , <EOL> "<STR_LIT:U+002C>" . join ( [ "<STR_LIT>" % ( k , v ) for k , v in <EOL> self . parsed_attributes . iteritems ( ) <EOL> if k != '<STR_LIT:args>' ] ) <EOL> ) <EOL> self . code = ast . PythonCode ( self . expression , ** self . exception_kwargs ) <EOL> self . body_decl = ast . FunctionArgs ( <EOL> attributes . get ( '<STR_LIT:args>' , '<STR_LIT>' ) , <EOL> ** self . exception_kwargs ) <EOL> def declared_identifiers ( self ) : <EOL> return self . code . declared_identifiers . union ( self . body_decl . argnames ) <EOL> def undeclared_identifiers ( self ) : <EOL> return self . code . undeclared_identifiers . difference ( self . code . declared_identifiers ) <EOL> class InheritTag ( Tag ) : <EOL> __keyword__ = '<STR_LIT>' <EOL> def __init__ ( self , keyword , attributes , ** kwargs ) : <EOL> super ( InheritTag , self ) . __init__ ( <EOL> keyword , attributes , <EOL> ( '<STR_LIT:file>' , ) , ( ) , ( '<STR_LIT:file>' , ) , ** kwargs ) <EOL> class PageTag ( Tag ) : <EOL> __keyword__ = '<STR_LIT>' <EOL> def __init__ ( self , keyword , attributes , ** kwargs ) : <EOL> super ( PageTag , self ) . __init__ ( <EOL> keyword , <EOL> attributes , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT:args>' , '<STR_LIT>' ) , <EOL> ( ) , <EOL> ( ) , <EOL> ** kwargs ) <EOL> self . body_decl = ast . FunctionArgs ( attributes . get ( '<STR_LIT:args>' , '<STR_LIT>' ) , <EOL> ** self . exception_kwargs ) <EOL> self . filter_args = ast . ArgumentList ( <EOL> attributes . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ** self . exception_kwargs ) <EOL> def declared_identifiers ( self ) : <EOL> return self . body_decl . argnames </s>
