ž ¦ÿfjc@s‘dZddlZdd„ejDƒZdddgZdZd d „Zd d „Zd ddd„ZGdd„dƒZ Gdd„dƒZ dS(u[Utilities 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). Approach: First, check if the source consists entirely of blank lines and comments; if so, replace it with 'pass', because the built-in parser doesn't always do the right thing for these. Compile three times: as is, with \n, and with \n\n appended. If it compiles as is, it's complete. If it compiles with one \n appended, we expect more. If it doesn't compile either way, we compare the error we get when compiling with \n or \n\n appended. If the errors are the same, the code is broken. But if the errors are different, we expect more. Not intuitive; not even guaranteed to hold in future releases; but this matches the compiler's behavior from Python 1.4 through 2.2, at least. Caveat: It is possible (but not likely) that the parser stops parsing with a successful outcome before reaching the end of the source; in this case, trailing symbols may be ignored instead of causing an error. For example, a backslash followed by two newlines may be followed by arbitrary garbage. This will be fixed once the API for the parser is better. 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. iNcCsg|]}tt|ƒ‘qS((ugetattru __future__(u.0ufname((u+/opt/alt/python33/lib64/python3.3/codeop.pyu =s u ucompile_commanduCompileuCommandCompileric .CsuxR|jdƒD],}|jƒ}|r|ddkrPqqW|dkrUd}nd}}}d}} } y||||ƒ}Wn%tk r®}zWYdd}~XnXy||d||ƒ} Wn+tk rö} z | }WYdd} ~ XnXy||d||ƒ} Wn+tk r>} z | }WYdd} ~ XnX|rI|S| rqt|ƒt|ƒkrq|‚ndS(Nu iu#uevalupassu (usplitustripuNoneu SyntaxErrorurepr( ucompilerusourceufilenameusymbolulineuerruerr1uerr2ucodeucode1ucode2ue((u+/opt/alt/python33/lib64/python3.3/codeop.pyu_maybe_compileDs0   u_maybe_compilecCst|||tƒS(N(ucompileuPyCF_DONT_IMPLY_DEDENT(usourceufilenameusymbol((u+/opt/alt/python33/lib64/python3.3/codeop.pyu_compileesu_compileuusinglecCstt|||ƒS(usCompile 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). (u_maybe_compileu_compile(usourceufilenameusymbol((u+/opt/alt/python33/lib64/python3.3/codeop.pyucompile_commandhscBs2|EeZdZdZdd„Zdd„ZdS(uCompileuëInstances 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.cCs t|_dS(N(uPyCF_DONT_IMPLY_DEDENTuflags(uself((u+/opt/alt/python33/lib64/python3.3/codeop.pyu__init__suCompile.__init__cCsUt||||jdƒ}x3tD]+}|j|j@r"|j|jO_q"q"W|S(Ni(ucompileuflagsu _featuresuco_flagsu compiler_flag(uselfusourceufilenameusymbolucodeobufeature((u+/opt/alt/python33/lib64/python3.3/codeop.pyu__call__„s  uCompile.__call__N(u__name__u __module__u __qualname__u__doc__u__init__u__call__(u __locals__((u+/opt/alt/python33/lib64/python3.3/codeop.pyuCompile|s cBs8|EeZdZdZdd„Zdddd„ZdS( uCommandCompileru(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.cCstƒ|_dS(N(uCompileucompiler(uself((u+/opt/alt/python33/lib64/python3.3/codeop.pyu__init__’suCommandCompiler.__init__uusinglecCst|j|||ƒS(uµCompile 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). (u_maybe_compileucompiler(uselfusourceufilenameusymbol((u+/opt/alt/python33/lib64/python3.3/codeop.pyu__call__•suCommandCompiler.__call__N(u__name__u __module__u __qualname__u__doc__u__init__u__call__(u __locals__((u+/opt/alt/python33/lib64/python3.3/codeop.pyuCommandCompiler‹s ( u__doc__u __future__uall_feature_namesu _featuresu__all__uPyCF_DONT_IMPLY_DEDENTu_maybe_compileu_compileucompile_commanduCompileuCommandCompiler(((u+/opt/alt/python33/lib64/python3.3/codeop.pyu9s    !