fdZddlZddlZdejDZgdZdZdZdZdZ dd Z dd Z GddZ GddZ dS)aAUtilities to compile possibly incomplete Python source code. This module provides two interfaces, broadly similar to the builtin function compile(), which take program text, a filename and a 'mode' and: - Return code object if the command is complete and valid - Return None if the command is incomplete - Raise SyntaxError, ValueError or OverflowError if the command is a syntax error (OverflowError and ValueError can be produced by malformed literals). The two interfaces are: compile_command(source, filename, symbol): Compiles a single command in the manner described above. CommandCompiler(): Instances of this class have __call__ methods identical in signature to compile_command; the difference is that if the instance compiles program text containing a __future__ statement, the instance 'remembers' and compiles all subsequent program texts with the statement in force. The module also provides another class: Compile(): Instances of this class act like the built-in function compile, but with 'memory' in the sense described above. Nc8g|]}tt|S)getattr __future__).0fnames -/opt/alt/python311/lib64/python3.11/codeop.py r &s2 8 8 8Z ' ' 8 8 8)compile_commandCompileCommandCompilerii@c0|dD]&}|}|r|ddkrn '|dkrd}tj5tjdt t f ||||ni#t$r\ ||dz||YddddS#t$r-}dt|vrYd}~YddddSYd}~nd}~wwxYwYnwxYwdddn #1swxYwY||||d S) N r#evalpassignorezincomplete inputF)incomplete_input) splitstripwarningscatch_warnings simplefilter SyntaxWarningDeprecationWarning SyntaxErrorstr)compilersourcefilenamesymbollinees r _maybe_compiler%1s T""zz||  DGsNN E V  F  " "   h8J(KLLL HVXv . . . .    $&999            %Q//4444         0//// //                  8FHfu E E EEsl"C>; B C> C/B2$C>2 C)<C$ C/C>C/$C))C/,C>.C//C>>DDcft|}t|}d|vrd|vrdS||krdSdS)Nzwas never closedFT)repr)err1err2rep1rep2s r _is_syntax_errorr,KsF ::D ::DT!!&8D&@&@u t||t 5r TcVd}|r|tz}|tz}t||||S)Nr)PyCF_ALLOW_INCOMPLETE_INPUTPyCF_DONT_IMPLY_DEDENTcompile)r r!r"rflagss r _compiler2Ts9 E( ,, '' 68VU 3 33r singlec0tt|||S)aCompile a command and determine whether it is incomplete. Arguments: source -- the source string; may contain \n characters filename -- optional filename from which source was read; default "" symbol -- optional grammar start symbol; "single" (default), "exec" or "eval" Return value / exceptions raised: - Return a code object if the command is complete and valid - Return None if the command is incomplete - Raise SyntaxError, ValueError or OverflowError if the command is a syntax error (OverflowError and ValueError can be produced by malformed literals). )r%r2)r r!r"s r r r [s& (FHf = ==r ceZdZdZdZdZdS)r zInstances of this class behave much like the built-in compile function, but if one is used to compile text containing a future statement, it "remembers" and compiles all subsequent program texts with the statement in force.c.ttz|_dSN)r/r.r1selfs r __init__zCompile.__init__us+.II r c |j}|dddur|tz}|tz}t ||||d}t D]&}|j|jzr|xj|jzc_'|S)NrTF)r1getr/r.r0 _featuresco_flags compiler_flag)r:r r!r"kwargsr1codeobfeatures r __call__zCompile.__call__xs  ::($ / /5 8 8 ,, ,E 11 1E65$??  4 4G!66 4 g33  r N__name__ __module__ __qualname____doc__r;rDrr r r r ps?$$JJJ     r r c eZdZdZdZddZdS)ra(Instances of this class have __call__ methods identical in signature to compile_command; the difference is that if the instance compiles program text containing a __future__ statement, the instance 'remembers' and compiles all subsequent program texts with the statement in force.c,t|_dSr8)r rr9s r r;zCommandCompiler.__init__s  r r3r4c0t|j|||S)aCompile a command and determine whether it is incomplete. Arguments: source -- the source string; may contain \n characters filename -- optional filename from which source was read; default "" symbol -- optional grammar start symbol; "single" (default) or "eval" Return value / exceptions raised: - Return a code object if the command is complete and valid - Return None if the command is incomplete - Raise SyntaxError, ValueError or OverflowError if the command is a syntax error (OverflowError and ValueError can be produced by malformed literals). )r%r)r:r r!r"s r rDzCommandCompiler.__call__s&dmVXvFFFr Nr3r4rErr r rrsG$$ """GGGGGGr r)TrM)rIrrall_feature_namesr>__all__r/r.r%r,r2r r rrr r rPs  D 8 8$6 8 8 8  < ; ; $FFF44444>>>>*&GGGGGGGGGGr