\ddZddlZddlZdejDZgdZdZdZdZdZ d Z dd Z Gd dZ 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 ..\python\lib\codeop.py r &s2 8 8 8Z ' ' 8 8 8)compile_commandCompileCommandCompilerii@c,|dD]&}|}|r|ddkrn '|dkrd}tj5tjdt t f ||||ni#t$r\ ||dz||YddddS#t$r-}dt|vrYd}~YddddSYd}~nd}~wwxYwYnwxYwdddn #1swxYwY||||S)N r#evalpassignorezincomplete input) splitstripwarningscatch_warnings simplefilter SyntaxWarningDeprecationWarning SyntaxErrorstr)compilersourcefilenamesymbollinees r _maybe_compiler$1s T""zz||  DGsNN E V  F  " "   h8J(KLLL HVXv . . . .    $&999            %Q//4444         0//// //                  8FHf - --sl"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+LsF ::D ::DT!!&8D&@&@u t||t 5r c@t|||ttzSN)compilePyCF_DONT_IMPLY_DEDENTPyCF_ALLOW_INCOMPLETE_INPUTrr r!s r _compiler2Us 68V-CFa-a b bbr 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$r2r1s r r r Xs& (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|_dSr-)r/r0flagsselfs r __init__zCompile.__init__rs+.II r ct||||jd}tD]&}|j|jzr|xj|jzc_'|S)NT)r.r8 _featuresco_flags compiler_flag)r:rr r!codeobfeatures r __call__zCompile.__call__usS64:tDD  4 4G!66 4 g33  r N__name__ __module__ __qualname____doc__r;rBrr r r r ms?$$JJJr 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|_dSr-)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:rr r!s r rBzCommandCompiler.__call__s&dmVXvFFFr Nr3r4rCrr r rr|sG$$ """GGGGGGr rrK)rGrrall_feature_namesr=__all__r/r0r$r+r2r r rrr r rNs   D 8 8$6 8 8 8  < ; ; $...6ccc>>>>*        GGGGGGGGGGr