ó
ži‚Nc        	   @   sÃ   d  Z  d d l Z d d l Z d d l m Z d d l m Z m Z m Z m	 Z	 m
 Z
 d Z e e e e e e e e d „ Z d e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d e f d „  ƒ  YZ d S(   sV   provides functionality for rendering a parsetree constructing into module source code.iÿÿÿÿN(   t   PythonPrinter(   t   utilt   astt	   parsetreet   filterst
   exceptionsi   c
         C   s{   t  j r+ t | t ƒ r+ | j | ƒ } n  t  j ƒ  }
 t |
 ƒ } t | t | | | | | | | | |	 ƒ	 |  ƒ |
 j	 ƒ  S(   s\   Generate module source code given a parsetree node, 
      uri, and optional source filename(
   R   t   py3kt
   isinstancet   unicodet   encodet   FastEncodingBufferR    t   _GenerateRenderMethodt   _CompileContextt   getvalue(   t   nodet   urit   filenamet   default_filterst   buffer_filterst   importst   source_encodingt   generate_magic_commentt   disable_unicodet   strict_undefinedt   buft   printer(    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyt   compile   s     R   c           B   s   e  Z d  „  Z RS(   c
   
      C   sU   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ |	 |  _ d  S(   N(	   R   R   R   R   R   R   R   R   R   (
   t   selfR   R   R   R   R   R   R   R   R   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyt   __init__7   s    
								(   t   __name__t
   __module__R   (    (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyR   6   s   R   c           B   s  e  Z d  Z d „  Z e d „  ƒ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 e d d „ Z d	 „  Z d
 „  Z d „  Z e d „ Z e e d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s_   A template visitor object which generates the 
       full module source for a template.
 
    c      	   C   s
  | |  _  d |  _ | |  _ | |  _ d  g |  _ t | t j t j	 f ƒ |  _
 |  j
 rð d | j } | j ƒ  } t | j j ƒ d k } t | j j d d ƒ ƒ } t | j j d d ƒ ƒ } d  }	 d  }
 | j r|| j r|| d g 7} q|nŒ |  j ƒ  }	 |  j j }
 d } |
 d  k	 rc|
 j j ƒ  } |
 j j sE| d g 7} n  t |
 j j d d ƒ ƒ } n d g } t } t } } | d  k r”d	 g } n  g  d	 g | D] } | ^ q¢} |  j |
 pÃ| | | | | | ƒ |	 d  k	 rx! |	 D] } t | | | ƒ qéWn  d  S(
   Niÿÿÿÿs	   render_%si    t   bufferedt   Falset   cacheds
   **pageargst   render_bodyt   context(   R   t   last_source_linet   compilerR   t   Nonet   identifier_stackR   R   t   DefTagt   BlockTagt   in_deft   funcnamet   get_argument_expressionst   lent   filter_argst   argst   evalt
   attributest   gett   is_blockt   is_anonymoust   write_toplevelt   pagetagt	   body_declt   kwargsR    t   write_render_callableR   (   R   R   R%   R   t   nameR/   t   filteredR   R!   t   defsR6   t   a(    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyR   P   sJ    						
 	c         C   s   |  j  d S(   Niÿÿÿÿ(   R'   (   R   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyt   identifiers~   s    c            sU  g  ‰ i  ‰  g  ‰ d g } d ˆ j _ d t f ‡ ‡ ‡ ‡  f d †  ƒ  Y} | ƒ  } x! ˆ j j D] } | j | ƒ qb Wˆ  ˆ j _ t ƒ  } x# ˆ D] } | j	 | j
 ƒ  ƒ } q• Wt ƒ  } | | _ ˆ j j rû ˆ j j rû ˆ j j d ˆ j j ƒ n  ˆ j j d ƒ ˆ j j d ƒ ˆ j j d ƒ ˆ j j d ƒ ˆ j j d t ƒ ˆ j j d	 t j ƒ  ƒ ˆ j j d
 ˆ j j ƒ ˆ j j d ˆ j j ƒ ˆ j j d ƒ ˆ j j d ˆ j j ƒ ˆ j j r8d } x2 ˆ j j D]$ } | | d 7} ˆ j j | ƒ qæWt j | d d d d d d d d ƒ}	 n d }	 | j ˆ j ƒ }
 | j j	 |
 j ƒ | _ | j j d ƒ |	 r”| j j |	 j
 ƒ n  | ˆ j _ ˆ j j d g  |
 j j ƒ  D] } | j ^ q¼ƒ ˆ j j d ƒ t  ˆ ƒ rÿˆ j! ˆ ƒ n  t  ˆ ƒ r,ˆ j" ˆ  ƒ ˆ j# ˆ d ƒ n t  ˆ  ƒ rHˆ j" ˆ  ƒ n  |
 j j ƒ  S(   sy   Traverse a template structure for module-level directives and
        generate the start of module-level code.
 
        t   FindTopLevelc              sD   e  Z ‡ f d  †  Z ‡ f d †  Z ‡ f d †  Z ‡  f d †  Z RS(   c            s   ˆ  j  | ƒ d  S(   N(   t   append(   t   sR   (   t   inherit(    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyt   visitInheritTag   s    c            s   | ˆ  | j  <d  S(   N(   R:   (   RA   R   (   t
   namespaces(    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyt   visitNamespaceTag‘   s    c            s   | ˆ  j  _ d  S(   N(   R%   R6   (   RA   R   (   R   (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyt   visitPageTag“   s    c            s   | j  r ˆ  j | ƒ n  d  S(   N(   t   ismoduleR@   (   RA   R   (   t   module_code(    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyt	   visitCode•   s    	(   R   R   RC   RE   RF   RI   (    (   RH   R   RB   RD   (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyR?   Ž   s   s   # -*- encoding:%s -*-s(   from mako import runtime, filters, caches   UNDEFINED = runtime.UNDEFINEDs   __M_dict_builtin = dicts   __M_locals_builtin = localss   _magic_number = %rs   _modified_time = %rs   _template_filename=%rs   _template_uri=%rs5   _template_cache=cache.Cache(__name__, _modified_time)s   _source_encoding=%rt    s   
t   sourcet   linenoi    t   posR   s   template defined importst	   UNDEFINEDs   _exports = %rs   

iÿÿÿÿN($   R&   R%   R6   t   objectR   t   nodest   accept_visitorRD   t   sett   uniont   declared_identifierst   _Identifierst   declaredR   R   R   t	   writelinet   MAGIC_NUMBERt   timeR   R   R   R   t
   PythonCodet   brancht   topleveldefst   addt   updateR>   t   valuesR:   t   writeR-   t   write_module_codet   write_namespacest   write_inherit(   R   t   encodingR?   t   ft   nt   module_identt   module_identifiersR   t   impt   impcodet   main_identifiers(    (   RD   RH   R   RB   s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyR5   ‚   s|    	%								$c   
      C   sý  |  j  r2 | j } | r2 |  j j d | ƒ q2 n  |  j j d | d j | ƒ f d d ƒ | sm | sm | r€ |  j j d ƒ n  |  j j |  j j	 j
 |  j ƒ ƒ |  j  s¸ |  j j rÞ d | k rÞ |  j d j j d	 ƒ n  |  j  r[t |  j	 j ƒ d
 k st |  j	 j ƒ d
 k r[|  j j d d j g  |  j	 j D] } d | | f ^ q7ƒ ƒ n  |  j |  j	 d t ƒx! |  j j D] }	 |	 j |  ƒ q~W|  j |  j | | | ƒ |  j j d ƒ |  j j d ƒ | rù|  j | | | | |  j	 d t ƒn  d S(   so   write a top-level render callable.
 
        this could be the main render() method or that of a top-level def.s   @runtime._decorate_toplevel(%s)s   def %s(%s):t   ,s"   context.caller_stack._push_frame()s   try:s   context._push_buffer()s
   **pageargsiÿÿÿÿt   pageargsi    s!   __M_locals = __M_dict_builtin(%s)s   %s=%st   toplevels   

N(   R*   t	   decoratorR   RW   t
   writelinest   joinR'   R@   R%   R>   R[   R   R3   t   argument_declaredR]   R-   t   locally_assignedt   write_variable_declarest   TrueRP   RQ   t   write_def_finishR&   R`   t   write_cache_decorator(
   R   R   R:   R/   R   R;   R!   Ro   t   xRf   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyR9   à   s>    			""
.c         C   s5   x. | D]& } |  j  | ƒ |  j j | j ƒ q Wd S(   sf   write module-level template code, i.e. that which 
        is enclosed in <%! %> tags in the template.N(   t   write_source_commentR   t   write_indented_blockt   text(   R   RH   Rf   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyRa     s    c         C   s(   |  j  j d d d | j d d ƒ d S(   s:   write the module-level inheritance-determination callable.s%   def _mako_inherit(template, context):s"   _mako_generate_namespaces(context)s8   return runtime._inherit_from(context, %s, _template_uri)t   fileN(   R   Rp   t   parsed_attributesR&   (   R   R   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyRc     s    	c      	      s‚  ˆ  j  j d d d d d d d d ƒ ˆ  j  j d ƒ x| j ƒ  D]	} | j j d ƒ ri t ˆ  j _	 n  ˆ  j
 | ƒ t | j ƒ rDˆ  j  j d ƒ g  ‰ ˆ  j j j | ƒ ‰ t ˆ  _ d	 t f ‡  ‡ ‡ f d
 †  ƒ  Y} | ƒ  } x | j D] } | j | ƒ qî Wˆ  j  j d d j ˆ ƒ ƒ ˆ  j  j d ƒ t ˆ  _ d } n d } d | j k r‹ˆ  j  j d | j | j j d d ƒ | f ƒ n^ d | j k rÌˆ  j  j d | j | | j j d d ƒ f ƒ n ˆ  j  j d | j | f ƒ t | j j d d ƒ ƒ rˆ  j  j d | j ƒ n  ˆ  j  j d t | j ƒ ƒ ˆ  j  j d ƒ qB Wt | ƒ snˆ  j  j d ƒ n  ˆ  j  j d ƒ d S(   s5   write the module-level namespace-generating callable.s'   def _mako_get_namespace(context, name):s   try:s+   return context.namespaces[(__name__, name)]s   except KeyError:s"   _mako_generate_namespaces(context)s'   def _mako_generate_namespaces(context):t   imports   def make_namespace():t   NSDefVisitorc              s/   e  Z d  „  Z d „  Z ‡  ‡ ‡ f d †  Z RS(   c         S   s   |  j  | ƒ d  S(   N(   t   visitDefOrBase(   RA   R   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyt   visitDefTag8  s    c         S   s   |  j  | ƒ d  S(   N(   R€   (   RA   R   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyt   visitBlockTag;  s    c            sK   | j  r! t j d | j  ‚ n  ˆ  j | ˆ d t ƒˆ j | j ƒ d  S(   Ns.   Can't put anonymous blocks inside <%namespace>t   nested(   R4   R   t   CompileExceptiont   exception_kwargst   write_inline_defR    R@   R+   (   RA   R   (   R   R>   t   export(    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyR€   >  s    	(   R   R   R   R‚   R€   (    (   R   R>   R‡   (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyR   7  s   		s   return [%s]Rl   s   make_namespace()R&   R|   s€   ns = runtime.TemplateNamespace(%r, context._clean_inheritance_tokens(), templateuri=%s, callables=%s, calling_uri=_template_uri)t   modulesy   ns = runtime.ModuleNamespace(%r, context._clean_inheritance_tokens(), callables=%s, calling_uri=_template_uri, module=%s)sh   ns = runtime.Namespace(%r, context._clean_inheritance_tokens(), callables=%s, calling_uri=_template_uri)t   inheritableR    s   context['self'].%s = nss'   context.namespaces[(__name__, %s)] = nss   
t   passN(   R   Rp   R&   RW   R_   R1   t   has_keyRu   R%   t   has_ns_importsRy   R-   RP   R>   R[   R*   RO   RQ   Rq   R    R}   R:   R2   R0   t   reprR`   (   R   RD   R   R   t   visRf   t   callable_name(    (   R   R>   R‡   s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyRb      sd    	
	"						c   
      C   s  t  g  | j D] } | j | f ^ q ƒ } t ƒ  } | j | j ƒ } | j g  | j j ƒ  D] } | j ^ q\ ƒ } | j | j	 ƒ } | j | j
 ƒ } | d k	 r¶ | j | ƒ } n  | rUt |  j d t ƒ rU|  j j d ƒ t |  j _ xe |  j j j ƒ  D]N \ } } | j j d ƒ r |  j j d | t j d | j d ƒ f ƒ q q Wn  x¡| D]™} | | k rî| | }	 |	 j r¶|	 j s|  j |	 | ƒ që|  j |	 | d t ƒqõ|	 j ƒ  rÕ|  j |	 | ƒ qõ|  j |	 | d t ƒq\| |  j j k r|  j j d | | f ƒ q\t |  j d t ƒ r¢|  j j r‚|  j j  d | | f d	 | d
 d | | f d d | d d ƒ qõ|  j j d | | | f ƒ q\|  j j rÛ|  j j  d
 d | | f d d | d ƒ q\|  j j d | | f ƒ q\W|  j j d ƒ d S(   s  write variable declarations at the top of a function.
 
        the variable declarations are in the form of callable
        definitions for defs and/or name lookup within the
        function's context argument. the names declared are based
        on the names that are referenced in the function body,
        which don't otherwise have any explicit assignment
        operation. names that are assigned within the body are
        assumed to be locally-scoped variables and are not
        separately declared.
 
        for def callable definitions, if the def is a top-level
        callable then a 'stub' callable is generated which wraps
        the current Context into a closure. if the def is not
        top-level, it is fully rendered as a local closure.
 
        RŒ   s   _import_ns = {}R~   s:   _mako_get_namespace(context, %r)._populate(_import_ns, %r)s   \s*,\s*Rƒ   s%   %s = _mako_get_namespace(context, %r)s"   %s = _import_ns.get(%r, UNDEFINED)s   if %s is UNDEFINED:s   try:s   %s = context[%r]s   except KeyError:s&   raise NameError("'%s' is not defined")s3   %s = _import_ns.get(%r, context.get(%r, UNDEFINED))s   %s = context.get(%r, UNDEFINED)s   __M_writer = context.writer()N(!   t   dictR<   R+   RR   RS   t
   undeclaredt   closuredefsR_   t
   differenceRr   t   locally_declaredR&   t   intersectiont   getattrR%   R    R   RW   Ru   t   has_importsRD   t	   iteritemsR1   R‹   t   ret   splitR3   R4   t   write_def_declR†   t   is_rootR   Rp   (
   R   R>   Rn   t   limitt   ct   comp_identst   to_writet   identt   nst   comp(    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyRt   v  sr    +	.	(
				
		
	c         C   s<   |  j  | j k r8 |  j j d | j ƒ | j |  _  n  d S(   sU   write a source comment containing the line number of the corresponding template line.s   # SOURCE LINE %dN(   R$   RL   R   RW   (   R   R   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyRy   æ  s    c         C   sÞ   | j  } | j ƒ  } | j d t ƒ } |  j rt t |  j j ƒ d k sa t |  j j ƒ d k rt | j d d ƒ n | j d d ƒ |  j	 j
 d | d j | ƒ f ƒ |  j	 j
 d | d j | ƒ f ƒ |  j	 j
 d ƒ d S(	   s>   write a locally-available callable referencing a top-level deft   include_defaultsi    s   context.locals_(__M_locals)R#   s   def %s(%s):Rl   s   return render_%s(%s)N(   R+   R,   R    R*   R-   R>   Rs   Rr   t   insertR   RW   Rq   R&   (   R   R   R>   R+   t	   namedeclst   nameargs(    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyR›   ì  s    	
##c   
      C   s™  | j  ƒ  } | j } | r2 |  j j d | ƒ n  |  j j d | j d j | ƒ f ƒ t | j j ƒ d k } t	 | j
 j d d ƒ ƒ } t	 | j
 j d d ƒ ƒ } |  j j d d	 ƒ | sË | sË | rÞ |  j j d
 ƒ n  | j | d | ƒ} |  j | ƒ |  j j | ƒ x | j D] }	 |	 j |  ƒ qW|  j j ƒ  |  j | | | | ƒ |  j j d ƒ | r•|  j | | j | t | d t d t ƒn  d S(   s?   write a locally-available def callable inside an enclosing def.s&   @runtime._decorate_inline(context, %s)s   def %s(%s):Rl   i    R   R    R!   s"   context.caller_stack._push_frame()s   try:s   context._push_buffer()Rƒ   t   inlineRn   N(   R,   Ro   R   RW   R+   Rq   R-   R.   R/   R0   R1   R2   Rp   R[   Rt   R'   R@   RP   RQ   t   popRv   R&   Rw   R    Ru   (
   R   R   R>   Rƒ   R¦   Ro   R;   R   R!   Rf   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyR†   ü  s4    	&		
c      
   C   sM  | rG | rG | rG |  j  j d ƒ | rG |  j  j d d d	 ƒ qG n  | sY | sY | rI| se | r{ |  j  j d d ƒ n |  j  j d d ƒ | r§ |  j  j d ƒ n  d } | rÑ |  j | j j | t ƒ } n  |  j  j d	 ƒ | r| r|  j |  j j	 | t ƒ } n  | s| r/|  j  j d | ƒ qI|  j  j d | d ƒ n  d	 S(
   s;  write the end section of a rendering function, either outermost or inline.
 
        this takes into account if the rendering function was filtered, buffered, etc.
        and closes the corresponding try: block if any, and writes code to retrieve 
        captured content, apply filters, send proper return value.s	   return ''s   finally:s!   context.caller_stack._pop_frame()s   __M_buf = context._pop_buffer()s6   __M_buf, __M_writer = context._pop_buffer_and_writer()s   __M_buf.getvalue()s	   return %ss   __M_writer(%s)N(
   R   RW   Rp   R&   t   create_filter_callableR.   R/   R    R%   R   (   R   R   R   R;   R!   t	   callstackRA   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyRv   !  s8    		
		c      
   C   s¹  |  j  j d | | f ƒ | j j d t | ƒ ƒ } i  }	 xÿ d d d d f D]ë }
 | j j |
 d d ƒ } | d k	 r· |
 d d k r¦ t t | ƒ ƒ |	 |
 d <q9| |	 |
 d <qN |  j j	 d k	 rN |  j j	 j j |
 d d ƒ } | d k	 r9|
 d d k r%|	 |
 d t t | ƒ ƒ k q6| |	 |
 d <q9qN qN W|  j  j d | d j
 | ƒ f ƒ g  | D]6 } d | k r—d | j d ƒ d f d pš| ^ qg} |  j | d | d | j ƒ  ƒ| rQd | | d j
 g  |	 j ƒ  D] \ } } d | | f ^ qäƒ | d j
 | ƒ f } |  j |  j j | t ƒ } |  j  j d | d ƒ nd |  j  j d | | d j
 g  |	 j ƒ  D] \ } } d | | f ^ qvƒ | d j
 | ƒ f d d ƒ d S(   sm   write a post-function decorator to replace a rendering 
            callable with a cached version of itself.s   __M_%s = %st	   cache_keyt
   cache_typet   typet	   cache_dirt   data_dirt   cache_timeoutt
   expiretimet	   cache_urlt   urli    i   s   def %s(%s):Rl   t   =s   %s=%si   Rn   R   sO   context.get('local').get_cached(%s, defname=%r, %screatefunc=lambda:__M_%s(%s))RJ   s   %s=%s, s   return s[   __M_writer(context.get('local').get_cached(%s, defname=%r, %screatefunc=lambda:__M_%s(%s)))s	   return ''N(   R­   s   type(   R¯   R°   (   R±   R²   (   R³   R´   (   R   RW   R}   R2   R   R&   t   intR0   R%   R6   Rq   Rš   Rt   t   undeclared_identifiersR˜   Rª   R   R    Rp   (   R   t   node_or_pagetagR:   R/   R   R>   R¨   Rn   t   cachekeyt	   cacheargst   argt   valR=   t	   pass_argst   kt   vRA   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyRw   R  sL    !#@5	5c            s  ‡  f d †  } d | k rk | rk ˆ  j  j rF ˆ  j  j j j | } n  ˆ  j  j rh ˆ  j  j | } qh qk n  x | D]• } | d k rŠ qr n  t j d | ƒ } | rÓ | j d d ƒ \ } } | | ƒ }	 |	 | } n$ | }
 | | ƒ } | d k	 s÷ t	 ‚ d | | f } qr W| S(   s©   write a filter-applying expression based on the filters 
        present in the given filter names, adjusting for the global 
        'default' filter aliases as needed.c            sP   t  j d |  ƒ r d |  Sˆ  j j r9 t j j |  |  ƒ St j j |  |  ƒ Sd  S(   Ns
   decode\..+s   filters.(   R™   t   matchR%   R   R   t   NON_UNICODE_ESCAPESR2   t   DEFAULT_ESCAPES(   R:   (   R   (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyt   locate_encode“  s
    Rf   s   (.+?)(\(.*\))i   i   s   %s(%s)N(
   R%   R6   R.   R/   R   R™   RÀ   t   groupR&   t   AssertionError(   R   R/   t   targett   is_expressionRÃ   t   et   mR¡   t   fargsRe   Rx   (    (   R   s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyRª   Ž  s(    c         C   s¬   |  j  | ƒ t | j ƒ sX |  j j d  k	 rF t |  j j j j ƒ sX t |  j j ƒ r‘ |  j	 | j
 j d | j t ƒ } |  j j d | ƒ n |  j j d | j ƒ d  S(   Ns   %ss   __M_writer(%s)(   Ry   R-   t   escapesR%   R6   R&   R.   R/   R   Rª   t   escapes_codeR{   Ru   R   RW   (   R   R   RA   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyt   visitExpression±  s    "c         C   s_   | j  r; | j ƒ  s( |  j j d ƒ n  |  j j d  ƒ n  |  j | ƒ |  j j | j ƒ d  S(   NRŠ   (   t   isendt   get_childrenR   RW   R&   Ry   R{   (   R   R   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyt   visitControlLine¿  s    	c         C   s.   |  j  | ƒ |  j j d t | j ƒ ƒ d  S(   Ns   __M_writer(%s)(   Ry   R   RW   R   t   content(   R   R   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyt	   visitTextÈ  s    c         C   s”   t  | j j ƒ d k } | r4 |  j j d d ƒ n  x | j D] } | j |  ƒ q> W| r |  j j d d d |  j | j j d t ƒ d  ƒ n  d  S(   Ni    s#   __M_writer = context._push_writer()s   try:s   finally:s6   __M_buf, __M_writer = context._pop_buffer_and_writer()s   __M_writer(%s)s   __M_buf.getvalue()(
   R-   R.   R/   R   Rp   RP   RQ   Rª   R    R&   (   R   R   R;   Rf   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyt   visitTextTagÌ  s"    	
		c         C   s¡   | j  s |  j | ƒ |  j j | j ƒ |  j r t |  j j ƒ d k r |  j j	 d ƒ |  j j	 d d j
 g  | j ƒ  D] } t | ƒ ^ qz ƒ ƒ q n  d  S(   Ni    s0   __M_locals_builtin_stored = __M_locals_builtin()s   __M_locals.update(__M_dict_builtin([(__M_key, __M_locals_builtin_stored[__M_key]) for __M_key in [%s] if __M_key in __M_locals_builtin_stored]))Rl   (   RG   Ry   R   Rz   R{   R*   R-   R>   Rs   RW   Rq   RT   R   (   R   R   Rx   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyRI   á  s    	"	c         C   sh   |  j  | ƒ | j j d ƒ } | rI |  j j d | j d | f ƒ n |  j j d | j d ƒ d  S(   NR/   s5   runtime._include_file(context, %s, _template_uri, %s)R|   s1   runtime._include_file(context, %s, _template_uri)(   Ry   R1   R2   R   RW   R}   (   R   R   R/   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyt   visitIncludeTagò  s    		c         C   s   d  S(   N(    (   R   R   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyRE   þ  s    c         C   s   d  S(   N(    (   R   R   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyR     s    c         C   s“   | j  r# |  j j d | j ƒ nl | j d t ƒ } | d g 7} |  j j d | j ƒ |  j j d | j d j | ƒ f ƒ |  j j d ƒ d  S(   Ns   %s()R¤   s
   **pageargssO   if 'parent' not in context._data or not hasattr(context._data['parent'], '%s'):s   context['self'].%s(%s)Rl   s   
(   R4   R   RW   R+   R,   R    Rq   (   R   R   R§   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyR‚     s    	&c         C   s   |  j  | ƒ d  S(   N(   t   visitCallTag(   R   R   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyt   visitCallNamespaceTag  s    c            sí  ˆ j  j d ƒ d g ‰ ˆ j j | d t ƒ‰ ˆ j | d t ƒ‰  ˆ  j d ƒ ˆ j j ˆ  ƒ d t	 f ‡  ‡ ‡ ‡ f d †  ƒ  Y} | ƒ  } x | j
 D] } | j | ƒ q› Wˆ j j ƒ  | j j ƒ  } ˆ j  j d d j | ƒ ƒ t } | rˆ j  j d	 d
 ƒ n  ˆ j ˆ  ƒ ˆ j j ˆ  ƒ x | j
 D] } | j ˆ ƒ q4Wˆ j j ƒ  ˆ j | | t t d t ƒˆ j  j d  d d j ˆ ƒ d  ƒ ˆ j  j d d d
 ƒ ˆ j | ƒ ˆ j  j d ˆ j g  | j t ƒ d d d  ƒ d  S(   Ns   def ccall(caller):t   bodyRƒ   t   callert
   DefVisitorc              s2   e  Z d  „  Z d „  Z ‡  ‡ ‡ ‡ f d †  Z RS(   c         S   s   |  j  | ƒ d  S(   N(   R€   (   RA   R   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyR   #  s    c         S   s   |  j  | ƒ d  S(   N(   R€   (   RA   R   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyR‚   &  s    c            sX   ˆ j  | ˆ d t ƒ| j s2 ˆ j | j ƒ n  | j ˆ  j k rT ˆ  j | j =n  d  S(   NRƒ   (   R†   R    R4   R@   R+   R’   (   RA   R   (   t   body_identifiersR   R‡   t   callable_identifiers(    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyR€   )  s
    	(   R   R   R   R‚   R€   (    (   RÚ   R   R‡   RÛ   (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyRÙ   "  s   		s   def body(%s):Rl   s   context._push_buffer()s   try:R«   s   return [%s]s/   __M_caller = context.caller_stack._get_caller()sc   context.caller_stack.nextcaller = runtime.Namespace('caller', context, callables=ccall(__M_caller))s   __M_writer(%s)s   finally:s&   context.caller_stack.nextcaller = None(   R   RW   R>   R[   Ru   R    t   add_declaredR'   R@   RO   RP   RQ   R©   R7   R,   Rq   Rp   Rt   Rv   R&   Ry   Rª   t
   expression(   R   R   RÙ   RŽ   Rf   t   bodyargsR   (    (   RÚ   R   R‡   RÛ   s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyRÕ     sL    	%		
			N(    R   R   t   __doc__R   t   propertyR>   R5   R9   Ra   Rc   Rb   R    R&   Rt   Ry   R›   R†   Ru   Rv   Rw   Rª   RÍ   RÐ   RÒ   RÓ   RI   RÔ   RE   R   R‚   RÖ   RÕ   (    (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyR   K   s4   	.	^	.			Vp			%3:	#											RU   c           B   s¶   e  Z d  Z d d e d „ Z d „  Z e d „  ƒ Z d „  Z	 d „  Z
 d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sC   tracks the status of identifier names as template code is rendered.c         C   sJ  | d  k	 rÇ t | t j ƒ r< t ƒ  |  _ t j ƒ  |  _ qâ t | j ƒ j	 g  | j
 j ƒ  D] } | j ^ q[ ƒ j	 | j ƒ j	 | j ƒ |  _ | r¯ |  j j	 | j ƒ |  _ n  t j | j   |  _ n t ƒ  |  _ t j ƒ  |  _ t ƒ  |  _ t ƒ  |  _ t ƒ  |  _ t ƒ  |  _ t j ƒ  |  _
 | |  _ | d  k	 rF| j |  ƒ n  d  S(   N(   R&   R   R   t   NamespaceTagRR   RV   R   t   SetLikeDictR\   RS   R’   R_   R:   R”   Rr   R‘   Rs   R   RQ   (   R   R   t   parentRƒ   Rž   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyR   b  s*    (	c         K   s   t  | |  |  S(   sX   create a new Identifiers for a new Node, with 
          this Identifiers as the parent.(   RU   (   R   R   R8   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyR[   ™  s    c         C   s   t  |  j j |  j ƒ j ƒ  ƒ S(   N(   RR   R\   RS   R’   R_   (   R   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyR<   Ÿ  s    c         C   sv   d t  |  j ƒ t  |  j ƒ t  |  j ƒ g  |  j j ƒ  D] } | j ^ q7 g  |  j j ƒ  D] } | j ^ qY |  j f S(   Nsr   Identifiers(declared=%r, locally_declared=%r, undeclared=%r, topleveldefs=%r, closuredefs=%r, argumentdeclared=%r)(	   t   listRV   R”   R‘   R\   R_   R:   R’   Rr   (   R   Rž   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyt   __repr__£  s    ""c         C   s|   xN | j  ƒ  D]@ } | d k r | |  j j |  j ƒ k r |  j j | ƒ q q Wx$ | j ƒ  D] } |  j j | ƒ q^ Wd S(   sq   update the state of this Identifiers with the undeclared 
            and declared identifiers of the given node.R#   N(   R·   RV   RS   R”   R‘   R]   RT   (   R   R   R¡   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyt   check_declared®  s
    'c         C   s6   |  j  j | ƒ | |  j k r2 |  j j | ƒ n  d  S(   N(   RV   R]   R‘   t   remove(   R   R¡   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyRÜ   ¸  s    c         C   s   |  j  | ƒ d  S(   N(   Ræ   (   R   R   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyRÍ   ½  s    c         C   s   |  j  | ƒ d  S(   N(   Ræ   (   R   R   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyRÐ   À  s    c         C   s8   | j  s4 |  j | ƒ |  j j | j ƒ  ƒ |  _ n  d  S(   N(   RG   Ræ   Rs   RS   RT   (   R   R   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyRI   Ã  s    	c         C   s7   |  j  | k r3 x! | j D] } | j |  ƒ q Wn  d  S(   N(   R   RP   RQ   (   R   R   Rf   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyRE   È  s    c         C   sl   | j  | j ƒ } | | | j <| d  k	 rh | | k	 rh | j sI | j rh t j d | j | j  ‚ n  d  S(   Ns<   %%def or %%block named '%s' already exists in this template.(   R2   R+   R&   R3   R   R„   R…   (   R   t
   collectionR   t   existing(    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyt   _check_name_existsÐ  s    c         C   s   | j  ƒ  r, | j r, |  j |  j | ƒ n% | |  j k	 rQ |  j |  j | ƒ n  xN | j ƒ  D]@ } | d k r^ | |  j j |  j	 ƒ k r^ |  j
 j | ƒ q^ q^ W| |  j k rü x$ | j ƒ  D] } |  j j | ƒ q¾ Wx! | j D] } | j |  ƒ qâ Wn  d  S(   NR#   (   Rœ   R4   Rê   R\   R   R’   R·   RV   RS   R”   R‘   R]   RT   Rr   RP   RQ   (   R   R   R¡   Rf   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyR   Û  s    'c         C   s?  | |  j  k	 rœ | j rœ t |  j  t j ƒ rY t j d | j |  j  j f | j  ‚ qœ t |  j  t j	 t j
 f ƒ rœ t j d | j f | j  ‚ qœ n  | j sÎ |  j |  j | ƒ |  j j | j ƒ n% | |  j  k	 ró |  j |  j | ƒ n  x$ | j ƒ  D] } |  j j | ƒ q Wx | j D] } | j |  ƒ q$Wd  S(   Ns/   Named block '%s' not allowed inside of def '%s's3   Named block '%s' not allowed inside of <%%call> tag(   R   R4   R   R   R(   R   R„   R:   R…   t   CallTagt   CallNamespaceTagRê   R\   R‘   R]   R+   R’   RT   Rr   RP   RQ   (   R   R   R¡   Rf   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyR‚   ì  s&    
"	c         C   s   |  j  | ƒ d  S(   N(   Ræ   (   R   R   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyRÔ     s    c         C   s8   x$ | j  ƒ  D] } |  j j | ƒ q W|  j | ƒ d  S(   N(   RT   Rr   R]   Ræ   (   R   R   R¡   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyRF     s    c         C   s   |  j  | ƒ d  S(   N(   RÕ   (   R   R   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyRÖ     s    c         C   s   | |  j  k r« xN | j ƒ  D]@ } | d k r | |  j j |  j ƒ k r |  j j | ƒ q q Wx$ | j ƒ  D] } |  j j | ƒ qm Wxr | j	 D] } | j
 |  ƒ q‘ WnQ xN | j ƒ  D]@ } | d k r¸ | |  j j |  j ƒ k r¸ |  j j | ƒ q¸ q¸ Wd  S(   NR#   (   R   R·   RV   RS   R”   R‘   R]   RT   Rr   RP   RQ   (   R   R   R¡   Rf   (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyRÕ     s    ''N(   R   R   Rß   R&   R    R   R[   Rà   R<   Rå   Ræ   RÜ   RÍ   RÐ   RI   RE   Rê   R   R‚   RÔ   RF   RÖ   RÕ   (    (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyRU   _  s$   7			
											(   Rß   RY   R™   t
   mako.pygenR    t   makoR   R   R   R   R   RX   R&   Ru   R    R   RO   R   R   RU   (    (    (    s0   /usr/lib/python2.7/dist-packages/mako/codegen.pyt   <module>   s&   (ÿ ÿ ÿ 