
    +h                         d Z ddlZddlmZ ddlmZ  G d d      Z G d d      Z G d	 d
e      Z G d d      Z G d de      Z	y)zjutilities for analyzing expressions and blocks of Python
code, as well as generating Python from AST nodes    N)
exceptions)pyparserc                       e Zd ZdZd Zy)
PythonCodez<represents information about a string containing Python codec                    || _         t               | _        t               | _        t	        |t
              r&t        j                  |j                         dfi |}n|}t        j                  | fi |}|j                  |       y )Nexec)codesetdeclared_identifiersundeclared_identifiers
isinstancestrr   parselstripFindIdentifiersvisitselfr	   exception_kwargsexprfs        ;/var/www/html/venv/lib/python3.12/site-packages/mako/ast.py__init__zPythonCode.__init__   so    	 %(E! '*e# dC >>$++-L;KLDD$$T>-=>	    N__name__
__module____qualname____doc__r    r   r   r   r      s
    Fr   r   c                       e Zd ZdZd Zy)ArgumentListzBparses a fragment of code as a comma-separated list of expressionsc                 j   g | _         g | _        t               | _        t               | _        t        |t              rIt        j                  d|      rt        j                  d|      s|dz  }t        j                  |dfi |}n|}t        j                  | t        fi |}|j                  |       y )Nz\Sz,\s*$,r   )codeargsargsr
   r   r   r   r   rematchr   r   	FindTupler   r   r   s        r   r   zArgumentList.__init__6   s    	$'E!&)e#dC xxt$RXXh-E >>$C2BCDDtZD3CD	r   Nr   r    r   r   r"   r"   2   s
    Lr   r"   c                   "     e Zd ZdZ fdZ xZS )PythonFragmentzextends PythonCode to provide identifier lookups in partial control
    statements

    e.g.::

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

    c                    t        j                  d|j                         t         j                        }|st	        j
                  d|z  fi ||j                  d      r|d |j                  d       }|j                  dd      \  }}|dv r|dz   }nJ|dk(  r|d	z   }n?|d
v r	d|z   dz   }n2|dk(  r	d|z   dz   }n$|dk(  r|dz   }nt	        j
                  d|z  fi |t        | $  |fi | y )Nz^(\w+)(?:\s+(.*?))?:\s*(#|$)z0Fragment '%s' is not a partial control statement         )forifwhilepasstryzpass
except:pass)elifelsezif False:pass
exceptz	try:pass
withz!Unsupported control keyword: '%s')
r'   r(   stripSr   CompileExceptiongroupstartsuperr   )r   r	   r   mkeywordr   	__class__s         r   r   zPythonFragment.__init__U   s   HH4djjlBDDI--BTI"  771:!''!*%D''!Q-$,,&=D--D(($t+f4D $&/D&=D--3g="  	2!12r   r   r   r   r   r   __classcell__rA   s   @r   r+   r+   H   s    	3 3r   r+   c                   0    e Zd ZdZddZddZed        Zy)FunctionDeclzfunction declarationc                 B   || _         t        j                  |dfi |}t        j                  | fi |}|j	                  |       t        | d      st        j                  d|z  fi ||s3| j                  r&t        j                  d| j                  d   z  fi |y y )Nr   funcnamez'Code '%s' is not a function declarationz('**%s' keyword argument not allowed here)
r	   r   r   	ParseFuncr   hasattrr   r;   kwargs
kwargnames)r   r	   allow_kwargsr   r   r   s         r   r   zFunctionDecl.__init__u   s    	~~dF?.>?t8'78	tZ(--9D@"  --://"%& #  !,|r   c                 `   g }| j                   ddd   }| j                  ddd   }| j                  ddd   }| j                  ddd   }| j                  r#|j                  d|j                  d      z          |D ]  }|r|j                  |d|       |r]|j                  d      }||j                  |       C|j                  |dt        j                  |      j                                {|j                  |        | j                  r#|j                  d|j                  d      z          |D ]`  }|s|s|j                  |       |j                  d      }|j                  |dt        j                  |      j                                b |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).
        NrI   z**r   =*)argnamesrM   defaults
kwdefaultsrL   appendpopr   ExpressionGeneratorvaluevarargsreverse)	r   as_call	namedeclsrR   rM   rS   rT   namedefaults	            r   get_argument_expressionsz%FunctionDecl.get_argument_expressions   s    	 ==2&__TrT*
==2&__TrT*
 ;;TJNN1$556 	'D   D$!78$..+? $$T*$$!=!=g!F!L!L!NP
   &#	'( <<S8<<?23 	Dh  &",,q/  X99'BHHJL	 	r   c                 X    t        | j                        t        | j                        z   S )N)tuplerR   rM   )r   s    r   allargnameszFunctionDecl.allargnames   s    T]]#eDOO&<<<r   N)T)F)r   r   r   r   r   r_   propertyrb   r    r   r   rF   rF   q   s$    $7r = =r   rF   c                   "     e Zd ZdZ fdZ xZS )FunctionArgsz.the argument portion of a function declarationc                 ,    t        |   d|z  fi | y )Nzdef ANON(%s):pass)r>   r   )r   r	   rL   rA   s      r   r   zFunctionArgs.__init__   s    ,t3>v>r   rB   rD   s   @r   re   re      s    8? ?r   re   )
r   r'   makor   r   r   r"   r+   rF   re   r    r   r   <module>rh      sP   5 
   D ,&3Z &3RQ= Q=h?< ?r   