Utilities to compile possibly incomplete Python source code.
This module provides two interfaces, broadly similar to the
builtin function compile(), which takes program text, a filename
and a 'mode' - 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
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;