ó
ži‚Nc           @   s    d  Z  d d l m Z m Z m Z d d l Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d	 „  ƒ  YZ	 d
 e f d „  ƒ  YZ
 d e
 f d „  ƒ  YZ d S(   sk   utilities for analyzing expressions and blocks of Python 
code, as well as generating Python from AST nodesiÿÿÿÿ(   t
   exceptionst   pyparsert   utilNt
   PythonCodec           B   s   e  Z d  Z d „  Z RS(   s<   represents information about a string containing Python codec         K   sw   | |  _  t ƒ  |  _ t ƒ  |  _ t | t ƒ rN t j | j ƒ  d |  } n | } t j	 |  |  } | j
 | ƒ d  S(   Nt   exec(   t   codet   sett   declared_identifierst   undeclared_identifierst
   isinstancet
   basestringR   t   parset   lstript   FindIdentifierst   visit(   t   selfR   t   exception_kwargst   exprt   f(    (    s,   /usr/lib/python2.7/dist-packages/mako/ast.pyt   __init__   s    	(   t   __name__t
   __module__t   __doc__R   (    (    (    s,   /usr/lib/python2.7/dist-packages/mako/ast.pyR      s   t   ArgumentListc           B   s   e  Z d  Z d „  Z RS(   sB   parses a fragment of code as a comma-separated list of expressionsc         K   s¯   g  |  _  g  |  _ t ƒ  |  _ t ƒ  |  _ t | t ƒ rƒ t j d | ƒ rk t j d | ƒ rk | d 7} n  t	 j
 | d |  } n | } t	 j |  t |  } | j | ƒ d  S(   Ns   \Ss   ,\s*$t   ,R   (   t   codeargst   argsR   R   R   R	   R
   t   ret   matchR   R   t	   FindTupleR   R   (   R   R   R   R   R   (    (    s,   /usr/lib/python2.7/dist-packages/mako/ast.pyR   +   s    		%(   R   R   R   R   (    (    (    s,   /usr/lib/python2.7/dist-packages/mako/ast.pyR   )   s   t   PythonFragmentc           B   s   e  Z d  Z d „  Z RS(   s°   extends PythonCode to provide identifier lookups in partial control statements
 
    e.g. 
        for x in 5:
        elif y==9:
        except (MyException, e):
    etc.
    c         K   s%  t  j d | j ƒ  t  j ƒ } | s= t j d | |  ‚ n  | j d ƒ rb | | j d ƒ  } n  | j d d ƒ \ } } | d k r“ | d	 } nu | d
 k r¬ | d } n\ | d k sÄ | d k rÕ d | d	 } n3 | d k rò d | d	 } n t j d | |  ‚ t t	 |  ƒ j
 | |  d  S(   Ns   ^(\w+)(?:\s+(.*?))?:\s*(#|$)s0   Fragment '%s' is not a partial control statementi   i   i   t   fort   ift   whilet   passt   trys   pass
except:passt   elift   elses   if False:pass
t   excepts	   try:pass
s!   Unsupported control keyword: '%s'(   R   R    R!   (   R   R   t   stript   SR    t   CompileExceptiont   groupt   startt   superR   R   (   R   R   R   t   mt   keywordR   (    (    s,   /usr/lib/python2.7/dist-packages/mako/ast.pyR   E   s(    (   R   R   R   R   (    (    (    s,   /usr/lib/python2.7/dist-packages/mako/ast.pyR   <   s   t   FunctionDeclc           B   s&   e  Z d  Z e d „ Z e d „ Z RS(   s   function declarationc         K   s™   | |  _  t j | d |  } t j |  |  } | j | ƒ t |  d ƒ se t j d | |  ‚ n  | r• |  j r• t j d |  j	 d |  ‚ n  d  S(   NR   t   funcnames'   Code '%s' is not a function declarations(   '**%s' keyword argument not allowed hereiÿÿÿÿ(
   R   R   R   t	   ParseFuncR   t   hasattrR    R)   t   kwargst   argnames(   R   R   t   allow_kwargsR   R   R   (    (    s,   /usr/lib/python2.7/dist-packages/mako/ast.pyR   _   s    	c      
   C   s  g  } g  |  j  D] } | ^ q } |  j } |  j } g  |  j D] } | ^ q> } | j ƒ  x¬ | D]¤ }	 d }
 | r† d |	 }	 t } n7 | rŸ d |	 }	 t } n t | ƒ r· | j ƒ  pº d }
 | rõ |
 rõ | j	 d d |	 t
 j |
 ƒ j ƒ  f ƒ qa | j	 d |	 ƒ qa W| S(   sJ   return the argument declarations of this FunctionDecl as a printable list.s   **t   *i    s   %s=%sN(   t   defaultsR3   t   varargsR4   t   reverset   Nonet   Falset   lent   popt   insertR   t   ExpressionGeneratort   value(   R   t   include_defaultst	   namedeclst   dR7   R3   R8   R   R4   t   argt   default(    (    s,   /usr/lib/python2.7/dist-packages/mako/ast.pyt   get_argument_expressionsn   s*    		

	
	(   R   R   R   t   TrueR   RF   (    (    (    s,   /usr/lib/python2.7/dist-packages/mako/ast.pyR/   ]   s   t   FunctionArgsc           B   s   e  Z d  Z d „  Z RS(   s.   the argument portion of a function declarationc         K   s!   t  t |  ƒ j d | |  d  S(   Ns   def ANON(%s):pass(   R,   RH   R   (   R   R   R3   (    (    s,   /usr/lib/python2.7/dist-packages/mako/ast.pyR   Ž   s    (   R   R   R   R   (    (    (    s,   /usr/lib/python2.7/dist-packages/mako/ast.pyRH   ‹   s   (   R   t   makoR    R   R   R   t   objectR   R   R   R/   RH   (    (    (    s,   /usr/lib/python2.7/dist-packages/mako/ast.pyt   <module>   s   !.