Current Dir: /snap/core22/2955/usr/lib/python3.10/
[DIR] asyncio [ delete | rename ]
[DIR] collections [ delete | rename ]
[DIR] concurrent [ delete | rename ]
[DIR] ctypes [ delete | rename ]
[DIR] curses [ delete | rename ]
[DIR] dbm [ delete | rename ]
[DIR] distutils [ delete | rename ]
[DIR] email [ delete | rename ]
[DIR] encodings [ delete | rename ]
[DIR] html [ delete | rename ]
[DIR] http [ delete | rename ]
[DIR] importlib [ delete | rename ]
[DIR] json [ delete | rename ]
[DIR] lib-dynload [ delete | rename ]
[DIR] lib2to3 [ delete | rename ]
[DIR] logging [ delete | rename ]
[DIR] multiprocessing [ delete | rename ]
[DIR] pydoc_data [ delete | rename ]
[DIR] sqlite3 [ delete | rename ]
[DIR] test [ delete | rename ]
[DIR] unittest [ delete | rename ]
[DIR] urllib [ delete | rename ]
[DIR] venv [ delete | rename ]
[DIR] wsgiref [ delete | rename ]
[DIR] xml [ delete | rename ]
[DIR] xmlrpc [ delete | rename ]
[DIR] zoneinfo [ delete | rename ]
[DIR] __pycache__ [ delete | rename ]
[FILE] abc.py [ edit | delete | rename ]
[FILE] aifc.py [ edit | delete | rename ]
[FILE] antigravity.py [ edit | delete | rename ]
[FILE] argparse.py [ edit | delete | rename ]
[FILE] ast.py [ edit | delete | rename ]
[FILE] asynchat.py [ edit | delete | rename ]
[FILE] asyncore.py [ edit | delete | rename ]
[FILE] base64.py [ edit | delete | rename ]
[FILE] bdb.py [ edit | delete | rename ]
[FILE] binhex.py [ edit | delete | rename ]
[FILE] bisect.py [ edit | delete | rename ]
[FILE] bz2.py [ edit | delete | rename ]
[FILE] calendar.py [ edit | delete | rename ]
[FILE] cgi.py [ edit | delete | rename ]
[FILE] cgitb.py [ edit | delete | rename ]
[FILE] chunk.py [ edit | delete | rename ]
[FILE] cmd.py [ edit | delete | rename ]
[FILE] code.py [ edit | delete | rename ]
[FILE] codecs.py [ edit | delete | rename ]
[FILE] codeop.py [ edit | delete | rename ]
[FILE] colorsys.py [ edit | delete | rename ]
[FILE] compileall.py [ edit | delete | rename ]
[FILE] configparser.py [ edit | delete | rename ]
[FILE] contextlib.py [ edit | delete | rename ]
[FILE] contextvars.py [ edit | delete | rename ]
[FILE] copy.py [ edit | delete | rename ]
[FILE] copyreg.py [ edit | delete | rename ]
[FILE] cProfile.py [ edit | delete | rename ]
[FILE] crypt.py [ edit | delete | rename ]
[FILE] csv.py [ edit | delete | rename ]
[FILE] dataclasses.py [ edit | delete | rename ]
[FILE] datetime.py [ edit | delete | rename ]
[FILE] decimal.py [ edit | delete | rename ]
[FILE] difflib.py [ edit | delete | rename ]
[FILE] dis.py [ edit | delete | rename ]
[FILE] doctest.py [ edit | delete | rename ]
[FILE] enum.py [ edit | delete | rename ]
[FILE] filecmp.py [ edit | delete | rename ]
[FILE] fileinput.py [ edit | delete | rename ]
[FILE] fnmatch.py [ edit | delete | rename ]
[FILE] fractions.py [ edit | delete | rename ]
[FILE] ftplib.py [ edit | delete | rename ]
[FILE] functools.py [ edit | delete | rename ]
[FILE] genericpath.py [ edit | delete | rename ]
[FILE] getopt.py [ edit | delete | rename ]
[FILE] getpass.py [ edit | delete | rename ]
[FILE] gettext.py [ edit | delete | rename ]
[FILE] glob.py [ edit | delete | rename ]
[FILE] graphlib.py [ edit | delete | rename ]
[FILE] gzip.py [ edit | delete | rename ]
[FILE] hashlib.py [ edit | delete | rename ]
[FILE] heapq.py [ edit | delete | rename ]
[FILE] hmac.py [ edit | delete | rename ]
[FILE] imaplib.py [ edit | delete | rename ]
[FILE] imghdr.py [ edit | delete | rename ]
[FILE] imp.py [ edit | delete | rename ]
[FILE] inspect.py [ edit | delete | rename ]
[FILE] io.py [ edit | delete | rename ]
[FILE] ipaddress.py [ edit | delete | rename ]
[FILE] keyword.py [ edit | delete | rename ]
[FILE] LICENSE.txt [ edit | delete | rename ]
[FILE] linecache.py [ edit | delete | rename ]
[FILE] locale.py [ edit | delete | rename ]
[FILE] lzma.py [ edit | delete | rename ]
[FILE] mailbox.py [ edit | delete | rename ]
[FILE] mailcap.py [ edit | delete | rename ]
[FILE] mimetypes.py [ edit | delete | rename ]
[FILE] modulefinder.py [ edit | delete | rename ]
[FILE] netrc.py [ edit | delete | rename ]
[FILE] nntplib.py [ edit | delete | rename ]
[FILE] ntpath.py [ edit | delete | rename ]
[FILE] nturl2path.py [ edit | delete | rename ]
[FILE] numbers.py [ edit | delete | rename ]
[FILE] opcode.py [ edit | delete | rename ]
[FILE] operator.py [ edit | delete | rename ]
[FILE] optparse.py [ edit | delete | rename ]
[FILE] os.py [ edit | delete | rename ]
[FILE] pathlib.py [ edit | delete | rename ]
[FILE] pdb.py [ edit | delete | rename ]
[FILE] pickle.py [ edit | delete | rename ]
[FILE] pickletools.py [ edit | delete | rename ]
[FILE] pipes.py [ edit | delete | rename ]
[FILE] pkgutil.py [ edit | delete | rename ]
[FILE] platform.py [ edit | delete | rename ]
[FILE] plistlib.py [ edit | delete | rename ]
[FILE] poplib.py [ edit | delete | rename ]
[FILE] posixpath.py [ edit | delete | rename ]
[FILE] pprint.py [ edit | delete | rename ]
[FILE] profile.py [ edit | delete | rename ]
[FILE] pstats.py [ edit | delete | rename ]
[FILE] pty.py [ edit | delete | rename ]
[FILE] pyclbr.py [ edit | delete | rename ]
[FILE] pydoc.py [ edit | delete | rename ]
[FILE] py_compile.py [ edit | delete | rename ]
[FILE] queue.py [ edit | delete | rename ]
[FILE] quopri.py [ edit | delete | rename ]
[FILE] random.py [ edit | delete | rename ]
[FILE] re.py [ edit | delete | rename ]
[FILE] reprlib.py [ edit | delete | rename ]
[FILE] rlcompleter.py [ edit | delete | rename ]
[FILE] runpy.py [ edit | delete | rename ]
[FILE] sched.py [ edit | delete | rename ]
[FILE] secrets.py [ edit | delete | rename ]
[FILE] selectors.py [ edit | delete | rename ]
[FILE] shelve.py [ edit | delete | rename ]
[FILE] shlex.py [ edit | delete | rename ]
[FILE] shutil.py [ edit | delete | rename ]
[FILE] signal.py [ edit | delete | rename ]
[FILE] site.py [ edit | delete | rename ]
[FILE] sitecustomize.py [ edit | delete | rename ]
[FILE] smtpd.py [ edit | delete | rename ]
[FILE] smtplib.py [ edit | delete | rename ]
[FILE] sndhdr.py [ edit | delete | rename ]
[FILE] socket.py [ edit | delete | rename ]
[FILE] socketserver.py [ edit | delete | rename ]
[FILE] sre_compile.py [ edit | delete | rename ]
[FILE] sre_constants.py [ edit | delete | rename ]
[FILE] sre_parse.py [ edit | delete | rename ]
[FILE] ssl.py [ edit | delete | rename ]
[FILE] stat.py [ edit | delete | rename ]
[FILE] statistics.py [ edit | delete | rename ]
[FILE] string.py [ edit | delete | rename ]
[FILE] stringprep.py [ edit | delete | rename ]
[FILE] struct.py [ edit | delete | rename ]
[FILE] subprocess.py [ edit | delete | rename ]
[FILE] sunau.py [ edit | delete | rename ]
[FILE] symtable.py [ edit | delete | rename ]
[FILE] sysconfig.py [ edit | delete | rename ]
[FILE] tabnanny.py [ edit | delete | rename ]
[FILE] tarfile.py [ edit | delete | rename ]
[FILE] telnetlib.py [ edit | delete | rename ]
[FILE] tempfile.py [ edit | delete | rename ]
[FILE] textwrap.py [ edit | delete | rename ]
[FILE] this.py [ edit | delete | rename ]
[FILE] threading.py [ edit | delete | rename ]
[FILE] timeit.py [ edit | delete | rename ]
[FILE] token.py [ edit | delete | rename ]
[FILE] tokenize.py [ edit | delete | rename ]
[FILE] trace.py [ edit | delete | rename ]
[FILE] traceback.py [ edit | delete | rename ]
[FILE] tracemalloc.py [ edit | delete | rename ]
[FILE] tty.py [ edit | delete | rename ]
[FILE] turtle.py [ edit | delete | rename ]
[FILE] types.py [ edit | delete | rename ]
[FILE] typing.py [ edit | delete | rename ]
[FILE] uu.py [ edit | delete | rename ]
[FILE] uuid.py [ edit | delete | rename ]
[FILE] warnings.py [ edit | delete | rename ]
[FILE] wave.py [ edit | delete | rename ]
[FILE] weakref.py [ edit | delete | rename ]
[FILE] webbrowser.py [ edit | delete | rename ]
[FILE] xdrlib.py [ edit | delete | rename ]
[FILE] zipapp.py [ edit | delete | rename ]
[FILE] zipfile.py [ edit | delete | rename ]
[FILE] zipimport.py [ edit | delete | rename ]
[FILE] _aix_support.py [ edit | delete | rename ]
[FILE] _bootsubprocess.py [ edit | delete | rename ]
[FILE] _collections_abc.py [ edit | delete | rename ]
[FILE] _compat_pickle.py [ edit | delete | rename ]
[FILE] _compression.py [ edit | delete | rename ]
[FILE] _distutils_system_mod.py [ edit | delete | rename ]
[FILE] _markupbase.py [ edit | delete | rename ]
[FILE] _osx_support.py [ edit | delete | rename ]
[FILE] _pydecimal.py [ edit | delete | rename ]
[FILE] _pyio.py [ edit | delete | rename ]
[FILE] _py_abc.py [ edit | delete | rename ]
[FILE] _sitebuiltins.py [ edit | delete | rename ]
[FILE] _strptime.py [ edit | delete | rename ]
[FILE] _sysconfigdata__linux_x86_64-linux-gnu.py [ edit | delete | rename ]
[FILE] _sysconfigdata__x86_64-linux-gnu.py [ edit | delete | rename ]
[FILE] _threading_local.py [ edit | delete | rename ]
[FILE] _weakrefset.py [ edit | delete | rename ]
[FILE] __future__.py [ edit | delete | rename ]
[FILE] __phello__.foo.py [ edit | delete | rename ]
Viewing: /snap/core22/2955/usr/lib/python3.10/codeop.py
r"""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).
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.
"""
import __future__
import warnings
_features = [getattr(__future__, fname)
for fname in __future__.all_feature_names]
__all__ = ["compile_command", "Compile", "CommandCompiler"]
# The following flags match the values from Include/cpython/compile.h
# Caveat emptor: These flags are undocumented on purpose and depending
# on their effect outside the standard library is **unsupported**.
PyCF_DONT_IMPLY_DEDENT = 0x200
PyCF_ALLOW_INCOMPLETE_INPUT = 0x4000
def _maybe_compile(compiler, source, filename, symbol):
# Check for source consisting of only blank lines and comments.
for line in source.split("\n"):
line = line.strip()
if line and line[0] != '#':
break # Leave it alone.
else:
if symbol != "eval":
source = "pass" # Replace it with a 'pass' statement
# Disable compiler warnings when checking for incomplete input.
with warnings.catch_warnings():
warnings.simplefilter("ignore", (SyntaxWarning, DeprecationWarning))
try:
compiler(source, filename, symbol)
except SyntaxError: # Let other compile() errors propagate.
try:
compiler(source + "\n", filename, symbol)
return None
except SyntaxError as e:
if "incomplete input" in str(e):
return None
# fallthrough
return compiler(source, filename, symbol)
def _is_syntax_error(err1, err2):
rep1 = repr(err1)
rep2 = repr(err2)
if "was never closed" in rep1 and "was never closed" in rep2:
return False
if rep1 == rep2:
return True
return False
def _compile(source, filename, symbol):
return compile(source, filename, symbol, PyCF_DONT_IMPLY_DEDENT | PyCF_ALLOW_INCOMPLETE_INPUT)
def compile_command(source, filename="<input>", symbol="single"):
r"""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
"<input>"
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).
"""
return _maybe_compile(_compile, source, filename, symbol)
class Compile:
"""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."""
def __init__(self):
self.flags = PyCF_DONT_IMPLY_DEDENT | PyCF_ALLOW_INCOMPLETE_INPUT
def __call__(self, source, filename, symbol):
codeob = compile(source, filename, symbol, self.flags, True)
for feature in _features:
if codeob.co_flags & feature.compiler_flag:
self.flags |= feature.compiler_flag
return codeob
class 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."""
def __init__(self,):
self.compiler = Compile()
def __call__(self, source, filename="<input>", symbol="single"):
r"""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 "<input>"
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).
"""
return _maybe_compile(self.compiler, source, filename, symbol)