y`?dZddlZddlmZddlmZGddZGddZGd d eZGd d ZGd deZ dS)zjutilities for analyzing expressions and blocks of Python code, as well as generating Python from AST nodesN) exceptions)pyparserceZdZdZdZdS) PythonCodez$++--LL;KLLDDD  $T > >-= > >  N__name__ __module__ __qualname____doc__rrrrrs)FFrrceZdZdZdZdS) ArgumentListzBparses a fragment of code as a comma-separated list of expressionsc |g|_g|_t|_t|_t |t rCtjd|rtjd|s|dz }tj |dfi|}n|}tj |tfi|}| |dS)Nz\Sz,\s*$,r)codeargsargsr r r r rrematchrr FindTuplerrrs rrzArgumentList.__init__6s  $'EE!&)ee# dC  xt$$ RXh-E-E  >$CC2BCCDDD  tZ D D3C D D  rNrr rrr"r"2s)LLrr"c"eZdZdZfdZxZS)PythonFragmentzextends PythonCode to provide identifier lookups in partial control statements e.g.:: for x in 5: elif y==9: except (MyException, e): c tjd|tj}|st jd|zfi||dr|d|d}|dd\}}|dvr|dz}nI|dkr|d z}n=|d vr d |zdz}n0|d kr d |zdz}n!|dkr|dz}nt jd|zfi|tj |fi|dS)Nz^(\w+)(?:\s+(.*?))?:\s*(#|$)z0Fragment '%s' is not a partial control statement)forifwhilepasstryzpass except:pass)elifelsezif False:pass exceptz try:pass withz!Unsupported control keyword: '%s') r'r(stripSrCompileExceptiongroupstartsuperr)rr rmkeywordr __class__s rrzPythonFragment.__init__Usd H4djjllBD I I -BTI"  771:: & !''!** %D''!Q--$ , , ,&=DD   --DD ( ( ($t+f4DD  $&/DD   &=DD-3g="  22!122222rrrrrr __classcell__rAs@rr+r+HsB  333333333rr+c8eZdZdZddZd dZedZdS) FunctionDeclzfunction declarationTc (||_tj|dfi|}tj|fi|}||t |dst jd|zfi||s'|jr"t jd|j dzfi|dSdS)Nrfuncnamez'Code '%s' is not a function declarationz('**%s' keyword argument not allowed here) r rr ParseFuncrhasattrrr;kwargs kwargnames)rr allow_kwargsrrrs rrzFunctionDecl.__init__us ~dF??.>??  t 8 8'7 8 8  tZ(( -9D@"    -:/"%&#     rFcg}|jddd}|jddd}|jddd}|jddd}|jr+|d|dz|D]}|r||d||rl|d}|||N||dtj| |||j r+|d|dz|D]o}|s|s|||d}||dtj| p| |S)aEReturn 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). NrIz**r=*) argnamesrMdefaults kwdefaultsrLappendpoprExpressionGeneratorvaluevarargsreverse) ras_call namedeclsrRrMrSrTnamedefaults rget_argument_expressionsz%FunctionDecl.get_argument_expressionss( =2&_TTrT* =2&_TTrT*  ; 7   TJNN1$5$55 6 6 6 ' 'D '  DDD$$!78888 '$..++?$$T****$$44!=g!F!F!L!L!N!N!NP   &&&& < 4   S8<<??2 3 3 3  D h   &&&&",,q//  ttX9'BBHHJJJL rcTt|jt|jzS)N)tuplerRrM)rs r allargnameszFunctionDecl.allargnamess!T]##eDO&<&<<r)rr rLrAs rrzFunctionArgs.__init__s.,t3>>v>>>>>rrBrDs@rreres>88?????????rre) rr'makorrrr"r+rFrer rrrhs55 D,&3&3&3&3&3Z&3&3&3RQ=Q=Q=Q=Q=Q=Q=Q=h?????<?????r