[ SYSTEM ]: Linux srv.persadacompanies.com 4.18.0-553.56.1.el8_10.x86_64 #1 SMP Tue Jun 10 05:00:59 EDT 2025 x86_64
[ SERVER ]: Apache | PHP: 8.4.19
[ USER ]: persadamedika | IP: 45.64.1.108
GEFORCE FILE MANAGER
/
usr
/
lib64
/
python3.6
/
UPLOAD:
NAME
SIZE
QUICK PERMS
ACTIONS
📁 __pycache__
SET
[ DEL ]
📁 asyncio
SET
[ DEL ]
📁 collections
SET
[ DEL ]
📁 concurrent
SET
[ DEL ]
📁 config-3.6m-x86_64-linux-gnu
SET
[ DEL ]
📁 ctypes
SET
[ DEL ]
📁 curses
SET
[ DEL ]
📁 dbm
SET
[ DEL ]
📁 distutils
SET
[ DEL ]
📁 email
SET
[ DEL ]
📁 encodings
SET
[ DEL ]
📁 ensurepip
SET
[ DEL ]
📁 html
SET
[ DEL ]
📁 http
SET
[ DEL ]
📁 importlib
SET
[ DEL ]
📁 json
SET
[ DEL ]
📁 lib-dynload
SET
[ DEL ]
📁 lib2to3
SET
[ DEL ]
📁 logging
SET
[ DEL ]
📁 multiprocessing
SET
[ DEL ]
📁 pydoc_data
SET
[ DEL ]
📁 site-packages
SET
[ DEL ]
📁 sqlite3
SET
[ DEL ]
📁 test
SET
[ DEL ]
📁 unittest
SET
[ DEL ]
📁 urllib
SET
[ DEL ]
📁 venv
SET
[ DEL ]
📁 wsgiref
SET
[ DEL ]
📁 xml
SET
[ DEL ]
📁 xmlrpc
SET
[ DEL ]
📄 __future__.py
4,841 B
SET
[ EDIT ]
|
[ DEL ]
📄 __phello__.foo.py
64 B
SET
[ EDIT ]
|
[ DEL ]
📄 _bootlocale.py
1,301 B
SET
[ EDIT ]
|
[ DEL ]
📄 _collections_abc.py
26,392 B
SET
[ EDIT ]
|
[ DEL ]
📄 _compat_pickle.py
8,749 B
SET
[ EDIT ]
|
[ DEL ]
📄 _compression.py
5,340 B
SET
[ EDIT ]
|
[ DEL ]
📄 _dummy_thread.py
5,118 B
SET
[ EDIT ]
|
[ DEL ]
📄 _markupbase.py
14,598 B
SET
[ EDIT ]
|
[ DEL ]
📄 _osx_support.py
19,138 B
SET
[ EDIT ]
|
[ DEL ]
📄 _pydecimal.py
230,228 B
SET
[ EDIT ]
|
[ DEL ]
📄 _pyio.py
88,097 B
SET
[ EDIT ]
|
[ DEL ]
📄 _sitebuiltins.py
3,115 B
SET
[ EDIT ]
|
[ DEL ]
📄 _strptime.py
24,747 B
SET
[ EDIT ]
|
[ DEL ]
📄 _sysconfigdata_dm_linux_x86_64-linux-gnu.py
30,191 B
SET
[ EDIT ]
|
[ DEL ]
📄 _sysconfigdata_m_linux_x86_64-linux-gnu.py
30,367 B
SET
[ EDIT ]
|
[ DEL ]
📄 _threading_local.py
7,214 B
SET
[ EDIT ]
|
[ DEL ]
📄 _weakrefset.py
5,705 B
SET
[ EDIT ]
|
[ DEL ]
📄 abc.py
8,727 B
SET
[ EDIT ]
|
[ DEL ]
📄 aifc.py
32,454 B
SET
[ EDIT ]
|
[ DEL ]
📄 antigravity.py
477 B
SET
[ EDIT ]
|
[ DEL ]
📄 argparse.py
90,372 B
SET
[ EDIT ]
|
[ DEL ]
📄 ast.py
12,166 B
SET
[ EDIT ]
|
[ DEL ]
📄 asynchat.py
11,328 B
SET
[ EDIT ]
|
[ DEL ]
📄 asyncore.py
20,159 B
SET
[ EDIT ]
|
[ DEL ]
📄 base64.py
20,388 B
SET
[ EDIT ]
|
[ DEL ]
📄 bdb.py
23,556 B
SET
[ EDIT ]
|
[ DEL ]
📄 binhex.py
13,954 B
SET
[ EDIT ]
|
[ DEL ]
📄 bisect.py
2,595 B
SET
[ EDIT ]
|
[ DEL ]
📄 bz2.py
12,478 B
SET
[ EDIT ]
|
[ DEL ]
📄 cProfile.py
5,380 B
SET
[ EDIT ]
|
[ DEL ]
📄 calendar.py
23,213 B
SET
[ EDIT ]
|
[ DEL ]
📄 cgi.py
37,219 B
SET
[ EDIT ]
|
[ DEL ]
📄 cgitb.py
12,018 B
SET
[ EDIT ]
|
[ DEL ]
📄 chunk.py
5,425 B
SET
[ EDIT ]
|
[ DEL ]
📄 cmd.py
14,860 B
SET
[ EDIT ]
|
[ DEL ]
📄 code.py
10,614 B
SET
[ EDIT ]
|
[ DEL ]
📄 codecs.py
36,276 B
SET
[ EDIT ]
|
[ DEL ]
📄 codeop.py
5,994 B
SET
[ EDIT ]
|
[ DEL ]
📄 colorsys.py
4,064 B
SET
[ EDIT ]
|
[ DEL ]
📄 compileall.py
12,125 B
SET
[ EDIT ]
|
[ DEL ]
📄 configparser.py
53,592 B
SET
[ EDIT ]
|
[ DEL ]
📄 contextlib.py
13,162 B
SET
[ EDIT ]
|
[ DEL ]
📄 copy.py
8,815 B
SET
[ EDIT ]
|
[ DEL ]
📄 copyreg.py
7,007 B
SET
[ EDIT ]
|
[ DEL ]
📄 crypt.py
1,864 B
SET
[ EDIT ]
|
[ DEL ]
📄 csv.py
16,180 B
SET
[ EDIT ]
|
[ DEL ]
📄 datetime.py
82,034 B
SET
[ EDIT ]
|
[ DEL ]
📄 decimal.py
320 B
SET
[ EDIT ]
|
[ DEL ]
📄 difflib.py
84,377 B
SET
[ EDIT ]
|
[ DEL ]
📄 dis.py
18,132 B
SET
[ EDIT ]
|
[ DEL ]
📄 doctest.py
104,391 B
SET
[ EDIT ]
|
[ DEL ]
📄 dummy_threading.py
2,815 B
SET
[ EDIT ]
|
[ DEL ]
📄 enum.py
33,606 B
SET
[ EDIT ]
|
[ DEL ]
📄 filecmp.py
9,830 B
SET
[ EDIT ]
|
[ DEL ]
📄 fileinput.py
14,471 B
SET
[ EDIT ]
|
[ DEL ]
📄 fnmatch.py
3,166 B
SET
[ EDIT ]
|
[ DEL ]
📄 formatter.py
15,143 B
SET
[ EDIT ]
|
[ DEL ]
📄 fractions.py
23,639 B
SET
[ EDIT ]
|
[ DEL ]
📄 ftplib.py
35,617 B
SET
[ EDIT ]
|
[ DEL ]
📄 functools.py
31,346 B
SET
[ EDIT ]
|
[ DEL ]
📄 genericpath.py
5,028 B
SET
[ EDIT ]
|
[ DEL ]
📄 getopt.py
7,489 B
SET
[ EDIT ]
|
[ DEL ]
📄 getpass.py
5,994 B
SET
[ EDIT ]
|
[ DEL ]
📄 gettext.py
21,530 B
SET
[ EDIT ]
|
[ DEL ]
📄 glob.py
5,638 B
SET
[ EDIT ]
|
[ DEL ]
📄 gzip.py
20,334 B
SET
[ EDIT ]
|
[ DEL ]
📄 hashlib.py
8,799 B
SET
[ EDIT ]
|
[ DEL ]
📄 heapq.py
22,929 B
SET
[ EDIT ]
|
[ DEL ]
📄 hmac.py
6,381 B
SET
[ EDIT ]
|
[ DEL ]
📄 imaplib.py
53,464 B
SET
[ EDIT ]
|
[ DEL ]
📄 imghdr.py
3,795 B
SET
[ EDIT ]
|
[ DEL ]
📄 imp.py
10,669 B
SET
[ EDIT ]
|
[ DEL ]
📄 inspect.py
116,958 B
SET
[ EDIT ]
|
[ DEL ]
📄 io.py
3,517 B
SET
[ EDIT ]
|
[ DEL ]
📄 ipaddress.py
77,818 B
SET
[ EDIT ]
|
[ DEL ]
📄 keyword.py
2,219 B
SET
[ EDIT ]
|
[ DEL ]
📄 linecache.py
5,312 B
SET
[ EDIT ]
|
[ DEL ]
📄 locale.py
77,300 B
SET
[ EDIT ]
|
[ DEL ]
📄 lzma.py
12,983 B
SET
[ EDIT ]
|
[ DEL ]
📄 macpath.py
5,971 B
SET
[ EDIT ]
|
[ DEL ]
📄 macurl2path.py
2,732 B
SET
[ EDIT ]
|
[ DEL ]
📄 mailbox.py
78,624 B
SET
[ EDIT ]
|
[ DEL ]
📄 mailcap.py
9,067 B
SET
[ EDIT ]
|
[ DEL ]
📄 mimetypes.py
21,042 B
SET
[ EDIT ]
|
[ DEL ]
📄 modulefinder.py
23,027 B
SET
[ EDIT ]
|
[ DEL ]
📄 netrc.py
5,684 B
SET
[ EDIT ]
|
[ DEL ]
📄 nntplib.py
43,078 B
SET
[ EDIT ]
|
[ DEL ]
📄 ntpath.py
23,094 B
SET
[ EDIT ]
|
[ DEL ]
📄 nturl2path.py
2,444 B
SET
[ EDIT ]
|
[ DEL ]
📄 numbers.py
10,243 B
SET
[ EDIT ]
|
[ DEL ]
📄 opcode.py
5,822 B
SET
[ EDIT ]
|
[ DEL ]
📄 operator.py
10,863 B
SET
[ EDIT ]
|
[ DEL ]
📄 optparse.py
60,371 B
SET
[ EDIT ]
|
[ DEL ]
📄 os.py
37,526 B
SET
[ EDIT ]
|
[ DEL ]
📄 pathlib.py
46,238 B
SET
[ EDIT ]
|
[ DEL ]
📄 pdb.py
61,320 B
SET
[ EDIT ]
|
[ DEL ]
📄 pickle.py
55,691 B
SET
[ EDIT ]
|
[ DEL ]
📄 pickletools.py
91,775 B
SET
[ EDIT ]
|
[ DEL ]
📄 pipes.py
8,916 B
SET
[ EDIT ]
|
[ DEL ]
📄 pkgutil.py
21,315 B
SET
[ EDIT ]
|
[ DEL ]
📄 platform.py
47,214 B
SET
[ EDIT ]
|
[ DEL ]
📄 plistlib.py
32,291 B
SET
[ EDIT ]
|
[ DEL ]
📄 poplib.py
15,087 B
SET
[ EDIT ]
|
[ DEL ]
📄 posixpath.py
16,324 B
SET
[ EDIT ]
|
[ DEL ]
📄 pprint.py
20,860 B
SET
[ EDIT ]
|
[ DEL ]
📄 profile.py
22,029 B
SET
[ EDIT ]
|
[ DEL ]
📄 pstats.py
26,564 B
SET
[ EDIT ]
|
[ DEL ]
📄 pty.py
4,763 B
SET
[ EDIT ]
|
[ DEL ]
📄 py_compile.py
7,181 B
SET
[ EDIT ]
|
[ DEL ]
📄 pyclbr.py
13,558 B
SET
[ EDIT ]
|
[ DEL ]
📄 pydoc.py
103,501 B
SET
[ EDIT ]
|
[ DEL ]
📄 queue.py
8,780 B
SET
[ EDIT ]
|
[ DEL ]
📄 quopri.py
7,262 B
SET
[ EDIT ]
|
[ DEL ]
📄 random.py
27,442 B
SET
[ EDIT ]
|
[ DEL ]
📄 re.py
15,552 B
SET
[ EDIT ]
|
[ DEL ]
📄 reprlib.py
5,336 B
SET
[ EDIT ]
|
[ DEL ]
📄 rlcompleter.py
7,097 B
SET
[ EDIT ]
|
[ DEL ]
📄 runpy.py
11,959 B
SET
[ EDIT ]
|
[ DEL ]
📄 sched.py
6,511 B
SET
[ EDIT ]
|
[ DEL ]
📄 secrets.py
2,038 B
SET
[ EDIT ]
|
[ DEL ]
📄 selectors.py
19,438 B
SET
[ EDIT ]
|
[ DEL ]
📄 shelve.py
8,515 B
SET
[ EDIT ]
|
[ DEL ]
📄 shlex.py
12,956 B
SET
[ EDIT ]
|
[ DEL ]
📄 shutil.py
40,829 B
SET
[ EDIT ]
|
[ DEL ]
📄 signal.py
2,123 B
SET
[ EDIT ]
|
[ DEL ]
📄 site.py
21,268 B
SET
[ EDIT ]
|
[ DEL ]
📄 smtpd.py
34,719 B
SET
[ EDIT ]
|
[ DEL ]
📄 smtplib.py
44,218 B
SET
[ EDIT ]
|
[ DEL ]
📄 sndhdr.py
7,088 B
SET
[ EDIT ]
|
[ DEL ]
📄 socket.py
27,443 B
SET
[ EDIT ]
|
[ DEL ]
📄 socketserver.py
27,010 B
SET
[ EDIT ]
|
[ DEL ]
📄 sre_compile.py
19,338 B
SET
[ EDIT ]
|
[ DEL ]
📄 sre_constants.py
6,821 B
SET
[ EDIT ]
|
[ DEL ]
📄 sre_parse.py
36,536 B
SET
[ EDIT ]
|
[ DEL ]
📄 ssl.py
44,509 B
SET
[ EDIT ]
|
[ DEL ]
📄 stat.py
5,038 B
SET
[ EDIT ]
|
[ DEL ]
📄 statistics.py
20,673 B
SET
[ EDIT ]
|
[ DEL ]
📄 string.py
11,795 B
SET
[ EDIT ]
|
[ DEL ]
📄 stringprep.py
12,917 B
SET
[ EDIT ]
|
[ DEL ]
📄 struct.py
257 B
SET
[ EDIT ]
|
[ DEL ]
📄 subprocess.py
62,339 B
SET
[ EDIT ]
|
[ DEL ]
📄 sunau.py
18,095 B
SET
[ EDIT ]
|
[ DEL ]
📄 symbol.py
2,119 B
SET
[ EDIT ]
|
[ DEL ]
📄 symtable.py
7,277 B
SET
[ EDIT ]
|
[ DEL ]
📄 sysconfig.py
24,876 B
SET
[ EDIT ]
|
[ DEL ]
📄 tabnanny.py
11,411 B
SET
[ EDIT ]
|
[ DEL ]
📄 tarfile.py
111,635 B
SET
[ EDIT ]
|
[ DEL ]
📄 telnetlib.py
23,136 B
SET
[ EDIT ]
|
[ DEL ]
📄 tempfile.py
28,066 B
SET
[ EDIT ]
|
[ DEL ]
📄 textwrap.py
19,558 B
SET
[ EDIT ]
|
[ DEL ]
📄 this.py
1,003 B
SET
[ EDIT ]
|
[ DEL ]
📄 threading.py
50,136 B
SET
[ EDIT ]
|
[ DEL ]
📄 timeit.py
13,342 B
SET
[ EDIT ]
|
[ DEL ]
📄 token.py
3,075 B
SET
[ EDIT ]
|
[ DEL ]
📄 tokenize.py
29,496 B
SET
[ EDIT ]
|
[ DEL ]
📄 trace.py
28,733 B
SET
[ EDIT ]
|
[ DEL ]
📄 traceback.py
23,458 B
SET
[ EDIT ]
|
[ DEL ]
📄 tracemalloc.py
16,658 B
SET
[ EDIT ]
|
[ DEL ]
📄 tty.py
879 B
SET
[ EDIT ]
|
[ DEL ]
📄 types.py
8,870 B
SET
[ EDIT ]
|
[ DEL ]
📄 typing.py
80,274 B
SET
[ EDIT ]
|
[ DEL ]
📄 uu.py
6,763 B
SET
[ EDIT ]
|
[ DEL ]
📄 uuid.py
24,020 B
SET
[ EDIT ]
|
[ DEL ]
📄 warnings.py
18,488 B
SET
[ EDIT ]
|
[ DEL ]
📄 wave.py
17,709 B
SET
[ EDIT ]
|
[ DEL ]
📄 weakref.py
20,466 B
SET
[ EDIT ]
|
[ DEL ]
📄 webbrowser.py
22,238 B
SET
[ EDIT ]
|
[ DEL ]
📄 xdrlib.py
5,913 B
SET
[ EDIT ]
|
[ DEL ]
📄 zipapp.py
7,157 B
SET
[ EDIT ]
|
[ DEL ]
📄 zipfile.py
79,924 B
SET
[ EDIT ]
|
[ DEL ]
DELETE SELECTED
[ CLOSE ]
EDIT: contextlib.py
"""Utilities for with-statement contexts. See PEP 343.""" import abc import sys import _collections_abc from collections import deque from functools import wraps __all__ = ["contextmanager", "closing", "AbstractContextManager", "ContextDecorator", "ExitStack", "redirect_stdout", "redirect_stderr", "suppress"] class AbstractContextManager(abc.ABC): """An abstract base class for context managers.""" def __enter__(self): """Return `self` upon entering the runtime context.""" return self @abc.abstractmethod def __exit__(self, exc_type, exc_value, traceback): """Raise any exception triggered within the runtime context.""" return None @classmethod def __subclasshook__(cls, C): if cls is AbstractContextManager: return _collections_abc._check_methods(C, "__enter__", "__exit__") return NotImplemented class ContextDecorator(object): "A base class or mixin that enables context managers to work as decorators." def _recreate_cm(self): """Return a recreated instance of self. Allows an otherwise one-shot context manager like _GeneratorContextManager to support use as a decorator via implicit recreation. This is a private interface just for _GeneratorContextManager. See issue #11647 for details. """ return self def __call__(self, func): @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): return func(*args, **kwds) return inner class _GeneratorContextManager(ContextDecorator, AbstractContextManager): """Helper for @contextmanager decorator.""" def __init__(self, func, args, kwds): self.gen = func(*args, **kwds) self.func, self.args, self.kwds = func, args, kwds # Issue 19330: ensure context manager instances have good docstrings doc = getattr(func, "__doc__", None) if doc is None: doc = type(self).__doc__ self.__doc__ = doc # Unfortunately, this still doesn't provide good help output when # inspecting the created context manager instances, since pydoc # currently bypasses the instance docstring and shows the docstring # for the class instead. # See http://bugs.python.org/issue19404 for more details. def _recreate_cm(self): # _GCM instances are one-shot context managers, so the # CM must be recreated each time a decorated function is # called return self.__class__(self.func, self.args, self.kwds) def __enter__(self): try: return next(self.gen) except StopIteration: raise RuntimeError("generator didn't yield") from None def __exit__(self, type, value, traceback): if type is None: try: next(self.gen) except StopIteration: return False else: raise RuntimeError("generator didn't stop") else: if value is None: # Need to force instantiation so we can reliably # tell if we get the same exception back value = type() try: self.gen.throw(type, value, traceback) except StopIteration as exc: # Suppress StopIteration *unless* it's the same exception that # was passed to throw(). This prevents a StopIteration # raised inside the "with" statement from being suppressed. return exc is not value except RuntimeError as exc: # Don't re-raise the passed in exception. (issue27122) if exc is value: return False # Likewise, avoid suppressing if a StopIteration exception # was passed to throw() and later wrapped into a RuntimeError # (see PEP 479). if type is StopIteration and exc.__cause__ is value: return False raise except: # only re-raise if it's *not* the exception that was # passed to throw(), because __exit__() must not raise # an exception unless __exit__() itself failed. But throw() # has to raise the exception to signal propagation, so this # fixes the impedance mismatch between the throw() protocol # and the __exit__() protocol. # if sys.exc_info()[1] is value: return False raise raise RuntimeError("generator didn't stop after throw()") def contextmanager(func): """@contextmanager decorator. Typical usage: @contextmanager def some_generator(<arguments>): <setup> try: yield <value> finally: <cleanup> This makes this: with some_generator(<arguments>) as <variable>: <body> equivalent to this: <setup> try: <variable> = <value> <body> finally: <cleanup> """ @wraps(func) def helper(*args, **kwds): return _GeneratorContextManager(func, args, kwds) return helper class closing(AbstractContextManager): """Context to automatically close something at the end of a block. Code like this: with closing(<module>.open(<arguments>)) as f: <block> is equivalent to this: f = <module>.open(<arguments>) try: <block> finally: f.close() """ def __init__(self, thing): self.thing = thing def __enter__(self): return self.thing def __exit__(self, *exc_info): self.thing.close() class _RedirectStream(AbstractContextManager): _stream = None def __init__(self, new_target): self._new_target = new_target # We use a list of old targets to make this CM re-entrant self._old_targets = [] def __enter__(self): self._old_targets.append(getattr(sys, self._stream)) setattr(sys, self._stream, self._new_target) return self._new_target def __exit__(self, exctype, excinst, exctb): setattr(sys, self._stream, self._old_targets.pop()) class redirect_stdout(_RedirectStream): """Context manager for temporarily redirecting stdout to another file. # How to send help() to stderr with redirect_stdout(sys.stderr): help(dir) # How to write help() to a file with open('help.txt', 'w') as f: with redirect_stdout(f): help(pow) """ _stream = "stdout" class redirect_stderr(_RedirectStream): """Context manager for temporarily redirecting stderr to another file.""" _stream = "stderr" class suppress(AbstractContextManager): """Context manager to suppress specified exceptions After the exception is suppressed, execution proceeds with the next statement following the with statement. with suppress(FileNotFoundError): os.remove(somefile) # Execution still resumes here if the file was already removed """ def __init__(self, *exceptions): self._exceptions = exceptions def __enter__(self): pass def __exit__(self, exctype, excinst, exctb): # Unlike isinstance and issubclass, CPython exception handling # currently only looks at the concrete type hierarchy (ignoring # the instance and subclass checking hooks). While Guido considers # that a bug rather than a feature, it's a fairly hard one to fix # due to various internal implementation details. suppress provides # the simpler issubclass based semantics, rather than trying to # exactly reproduce the limitations of the CPython interpreter. # # See http://bugs.python.org/issue12029 for more details return exctype is not None and issubclass(exctype, self._exceptions) # Inspired by discussions on http://bugs.python.org/issue13585 class ExitStack(AbstractContextManager): """Context manager for dynamic management of a stack of exit callbacks For example: with ExitStack() as stack: files = [stack.enter_context(open(fname)) for fname in filenames] # All opened files will automatically be closed at the end of # the with statement, even if attempts to open files later # in the list raise an exception """ def __init__(self): self._exit_callbacks = deque() def pop_all(self): """Preserve the context stack by transferring it to a new instance""" new_stack = type(self)() new_stack._exit_callbacks = self._exit_callbacks self._exit_callbacks = deque() return new_stack def _push_cm_exit(self, cm, cm_exit): """Helper to correctly register callbacks to __exit__ methods""" def _exit_wrapper(*exc_details): return cm_exit(cm, *exc_details) _exit_wrapper.__self__ = cm self.push(_exit_wrapper) def push(self, exit): """Registers a callback with the standard __exit__ method signature Can suppress exceptions the same way __exit__ methods can. Also accepts any object with an __exit__ method (registering a call to the method instead of the object itself) """ # We use an unbound method rather than a bound method to follow # the standard lookup behaviour for special methods _cb_type = type(exit) try: exit_method = _cb_type.__exit__ except AttributeError: # Not a context manager, so assume its a callable self._exit_callbacks.append(exit) else: self._push_cm_exit(exit, exit_method) return exit # Allow use as a decorator def callback(self, callback, *args, **kwds): """Registers an arbitrary callback and arguments. Cannot suppress exceptions. """ def _exit_wrapper(exc_type, exc, tb): callback(*args, **kwds) # We changed the signature, so using @wraps is not appropriate, but # setting __wrapped__ may still help with introspection _exit_wrapper.__wrapped__ = callback self.push(_exit_wrapper) return callback # Allow use as a decorator def enter_context(self, cm): """Enters the supplied context manager If successful, also pushes its __exit__ method as a callback and returns the result of the __enter__ method. """ # We look up the special methods on the type to match the with statement _cm_type = type(cm) _exit = _cm_type.__exit__ result = _cm_type.__enter__(cm) self._push_cm_exit(cm, _exit) return result def close(self): """Immediately unwind the context stack""" self.__exit__(None, None, None) def __exit__(self, *exc_details): received_exc = exc_details[0] is not None # We manipulate the exception state so it behaves as though # we were actually nesting multiple with statements frame_exc = sys.exc_info()[1] def _fix_exception_context(new_exc, old_exc): # Context may not be correct, so find the end of the chain while 1: exc_context = new_exc.__context__ if exc_context is old_exc: # Context is already set correctly (see issue 20317) return if exc_context is None or exc_context is frame_exc: break new_exc = exc_context # Change the end of the chain to point to the exception # we expect it to reference new_exc.__context__ = old_exc # Callbacks are invoked in LIFO order to match the behaviour of # nested context managers suppressed_exc = False pending_raise = False while self._exit_callbacks: cb = self._exit_callbacks.pop() try: if cb(*exc_details): suppressed_exc = True pending_raise = False exc_details = (None, None, None) except: new_exc_details = sys.exc_info() # simulate the stack of exceptions by setting the context _fix_exception_context(new_exc_details[1], exc_details[1]) pending_raise = True exc_details = new_exc_details if pending_raise: try: # bare "raise exc_details[1]" replaces our carefully # set-up context fixed_ctx = exc_details[1].__context__ raise exc_details[1] except BaseException: exc_details[1].__context__ = fixed_ctx raise return received_exc and suppressed_exc