
    YeIi                         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	dS )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dS )
PythonCodez<represents information about a string containing Python codec                 (   || _         t                      | _        t                      | _        t	          |t
                    r&t          j        |                                dfi |}n|}t          j	        | fi |}|
                    |           d S )Nexec)codesetdeclared_identifiersundeclared_identifiers
isinstancestrr   parselstripFindIdentifiersvisitselfr	   exception_kwargsexprfs        M/var/www/html/MCyber-Diagnostic/venv/lib/python3.11/site-packages/mako/ast.py__init__zPythonCode.__init__   s    	 %(EE! '*ee# dC   	>$++--LL;KLLDDD$T>>-=>>	    N__name__
__module____qualname____doc__r    r   r   r   r      s)        FF    r   r   c                       e Zd ZdZd ZdS )ArgumentListzBparses a fragment of code as a comma-separated list of expressionsc                 |   g | _         g | _        t                      | _        t                      | _        t          |t                    rCt          j        d|          rt          j        d|          s|dz  }t          j
        |dfi |}n|}t          j        | t          fi |}|                    |           d S )Nz\Sz,\s*$,r   )codeargsargsr
   r   r   r   r   rematchr   r   	FindTupler   r   r   s        r   r   zArgumentList.__init__6   s    	$'EE!&)ee#dC   	xt$$ RXh-E-E  >$CC2BCCDDDtZDD3CDD	r   Nr   r    r   r   r"   r"   2   s)        L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|                                t           j                  }|st	          j        d|z  fi ||                    d          r|d |                    d                   }|                    dd          \  }}|dv r|dz   }nI|dk    r|d	z   }n=|d
v r	d|z   dz   }n0|dk    r	d|z   dz   }n!|dk    r|dz   }nt	          j        d|z  fi | t                      j	        |fi | d S )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   sd   H4djjllBDII 	-BTI "   771:: 	&!''!**%D''!Q--$,,,&=DD--DD((($t+f4DD  $&/DD&=DD-3g= "   	22!122222r   r   r   r   r   r   __classcell__rA   s   @r   r+   r+   H   sB        	 	3 3 3 3 3 3 3 3 3r   r+   c                   8    e Zd ZdZddZd	dZed             ZdS )
FunctionDeclzfunction declarationTc                 (   || _         t          j        |dfi |}t          j        | fi |}|                    |           t          | d          st          j        d|z  fi ||s'| j        r"t          j        d| j	        d         z  fi |d S d S )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8'788	tZ(( 	-9D@ "    	 	-:/"%&  #  	 	 	 	r   Fc                    g }| j         ddd         }| j        ddd         }| j        ddd         }| j        ddd         }| j        r+|                    d|                    d          z              |D ]}|r|                    |d|           |rl|                    d          }||                    |           N|                    |dt          j        |          	                                           |                    |           | j
        r+|                    d|                    d          z              |D ]o}|s|s|                    |           |                    d          }|                    |dt          j        |          	                                           p|                                 |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&_TTrT*
=2&_TTrT*
 ; 	7TJNN1$5$55666 	' 	'D  '  DDD$$!78888 '$..++? $$T****$$44!=g!F!F!L!L!N!N!NP   
   &&&& < 	4S8<<??2333 	 	D h   &&&&",,q//  ttX9'BBHHJJJL   
 	r   c                 T    t          | j                  t          | j                  z   S )N)tuplerR   rM   )r   s    r   allargnameszFunctionDecl.allargnames   s!    T]##eDO&<&<<<r   N)T)F)r   r   r   r   r   r_   propertyrb   r    r   r   rF   rF   q   s^           $7 7 7 7r = = X= = =r   rF   c                   "     e Zd ZdZ fdZ xZS )FunctionArgsz.the argument portion of a function declarationc                 B     t                      j        d|z  fi | d S )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8? ? ? ? ? ? ? ? ?r   re   )
r   r'   makor   r   r   r"   r+   rF   re   r    r   r   <module>rh      s  5 5 
			                   D       ,&3 &3 &3 &3 &3Z &3 &3 &3RQ= Q= Q= Q= Q= Q= Q= Q=h? ? ? ? ?< ? ? ? ? ?r   