
¦Ñ®hò  ã               @   s›   d  Z  d d l Z d d l m Z d d l m Z Gd d „  d ƒ Z Gd d „  d ƒ Z Gd	 d
 „  d
 e ƒ Z Gd d „  d ƒ Z Gd d „  d e ƒ Z	 d S)zjutilities for analyzing expressions and blocks of Python
code, as well as generating Python from AST nodesé    N)Ú
exceptions)Úpyparserc               @   s"   e  Z d  Z d Z d d „  Z d S)Ú
PythonCodez<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)NÚexec)ÚcodeÚsetÚdeclared_identifiersÚundeclared_identifiersÚ
isinstanceÚstrr   ÚparseÚlstripZFindIdentifiersÚvisit)Úselfr   Úexception_kwargsÚexprÚf© r   úZ/home/www/academy-backend.kofcorporation.com/venv/lib/python3.12/site-packages/mako/ast.pyÚ__init__   s    	zPythonCode.__init__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      s   r   c               @   s"   e  Z d  Z d Z d d „  Z d S)ÚArgumentListzBparses a fragment of code as a comma-separated list of expressionsc             K   s¬   g  |  _  g  |  _ t ƒ  |  _ t ƒ  |  _ t | t ƒ r€ t j d | ƒ rh t j d | ƒ rh | d 7} t	 j
 | d |  } n | } t	 j |  t |  } | j | ƒ d  S)Nz\Sz,\s*$ú,r   )ZcodeargsÚargsr   r   r	   r
   r   ÚreÚmatchr   r   Z	FindTupler   r   )r   r   r   r   r   r   r   r   r   6   s    		%
zArgumentList.__init__N)r   r   r   r   r   r   r   r   r   r   2   s   r   c                   s(   e  Z d  Z d Z ‡  f d d †  Z ‡  S)ÚPythonFragmentz­extends PythonCode to provide identifier lookups in partial control
    statements

    e.g.::

        for x in 5:
        elif y==9:
        except (MyException, e):

    c                s,  t  j d | j ƒ  t  j ƒ } | s: t j d | |  ‚ | j d ƒ rb | d  | j d ƒ … } | j d d ƒ \ } } | d k r“ | d	 } n‚ | d
 k r¬ | d } ni | d k rÉ d | d	 } nL | d k ræ d | d	 } n/ | d k rÿ | d	 } n t j d | |  ‚ t ƒ  j	 | |  d  S)Nz^(\w+)(?:\s+(.*?))?:\s*(#|$)z0Fragment '%s' is not a partial control statementé   é   é   ÚforÚifÚwhileZpassZtryzpass
except:passÚelifÚelsezif False:pass
Zexceptz	try:pass
Zwithz!Unsupported control keyword: '%s')r#   r$   r%   )r&   r'   )
r   r   ÚstripÚSr   ÚCompileExceptionÚgroupÚstartÚsuperr   )r   r   r   ÚmZkeywordr   )Ú	__class__r   r   r   U   s,    		zPythonFragment.__init__)r   r   r   r   r   r   r   )r/   r   r   H   s   r   c               @   sF   e  Z d  Z d Z d d d „ Z d d d „ Z e d d	 „  ƒ Z d
 S)ÚFunctionDeclzfunction declarationTc             K   s“   | |  _  t j | d |  } t j |  |  } | j | ƒ t |  d ƒ sb t j d | |  ‚ | r |  j r t j d |  j	 d |  ‚ d  S)Nr   Úfuncnamez'Code '%s' is not a function declarationz('**%s' keyword argument not allowed herer!   éÿÿÿÿ)
r   r   r   Z	ParseFuncr   Úhasattrr   r*   ÚkwargsÚ
kwargnames)r   r   Zallow_kwargsr   r   r   r   r   r   r   u   s    		zFunctionDecl.__init__Fc       	      C   s­  g  } |  j  d d d … } |  j d d d … } |  j d d d	 … } |  j d d d
 … } |  j r | j d | j d ƒ ƒ x• | D] } | r® | j d | | f ƒ qˆ | r| j d ƒ } | d k rß | j | ƒ q| j d | t j | ƒ j	 ƒ  f ƒ qˆ | j | ƒ qˆ W|  j
 r<| j d | j d ƒ ƒ x` | D]X } | sV| rf| j | ƒ qC| j d ƒ } | j d | t j | ƒ j	 ƒ  f ƒ qCW| j ƒ  | S)aE  Return the argument declarations of this FunctionDecl as a printable
        list.

        By default the return value is appropriate for writing in a ``def``;
        set `as_call` to true to build arguments to be passed to the function
        instead (assuming locals with the same names as the arguments exist).
        Nr!   z**r   z%s=%sÚ*r2   r2   r2   r2   )Úargnamesr5   ÚdefaultsÚ
kwdefaultsr4   ÚappendÚpopr   ZExpressionGeneratorÚvalueZvarargsÚreverse)	r   Zas_callZ	namedeclsr7   r5   r8   r9   ÚnameÚdefaultr   r   r   Úget_argument_expressions‡   s:    		 	!
z%FunctionDecl.get_argument_expressionsc             C   s   t  |  j ƒ t  |  j ƒ S)N)Útupler7   r5   )r   r   r   r   ÚallargnamesÀ   s    zFunctionDecl.allargnamesN)r   r   r   r   r   r@   ÚpropertyrB   r   r   r   r   r0   q   s   9r0   c                   s(   e  Z d  Z d Z ‡  f d d †  Z ‡  S)ÚFunctionArgsz.the argument portion of a function declarationc                s   t  ƒ  j d | |  d  S)Nzdef ANON(%s):pass)r-   r   )r   r   r4   )r/   r   r   r   É   s    zFunctionArgs.__init__)r   r   r   r   r   r   r   )r/   r   rD   Å   s   rD   )
r   r   Úmakor   r   r   r   r   r0   rD   r   r   r   r   Ú<module>   s   ")T