/usr/lib/python3/dist-packages/simpy/_compat.py is in python3-simpy3 3.0.10-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | """
Compatibility helpers for older Python versions.
"""
import sys
PY2 = sys.version_info[0] == 2
if PY2: # NOQA
# Python 2.x does not report exception chains. To emulate the behaviour of
# Python 3 traceback.format_exception and traceback.print_exception are
# overwritten with the custom functions. The original functions
# are stored in _format_exception and _print_exception.
import traceback
from collections import deque
_print_exception = traceback.print_exception
_format_exception = traceback.format_exception
def print_exception(etype, value, tb, limit=None, file=None):
if file is None:
file = sys.stderr
# Build the exception chain.
chain = deque()
cause = value
while True:
cause = cause.__dict__.get('__cause__', None)
if cause is None:
break
chain.appendleft(cause)
# Print the exception chain.
for cause in chain:
_print_exception(type(cause), cause,
cause.__dict__.get('__traceback__', None),
limit, file)
traceback._print(file, '\nThe above exception was the direct '
'cause of the following exception:\n')
_print_exception(etype, value, tb, limit, file)
traceback.print_exception = print_exception
def format_exception(etype, value, tb, limit=None):
# Build the exception chain.
chain = deque()
cause = value
while True:
cause = cause.__dict__.get('__cause__', None)
if cause is None:
break
chain.appendleft(cause)
# Format the exception chain.
lines = []
for cause in chain:
lines.extend(_format_exception(
type(cause), cause, cause.__dict__.get('__traceback__', None),
limit))
lines.append('\nThe above exception was the direct '
'cause of the following exception:\n\n')
lines.extend(_format_exception(etype, value, tb, limit))
return lines
traceback.format_exception = format_exception
sys.excepthook = print_exception
|