/usr/lib/python3/dist-packages/lz4/deprecated.py is in python3-lz4 0.10.1+dfsg1-0.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 | # See:
# http://stackoverflow.com/questions/2536307/decorators-in-the-python-standard-lib-deprecated-specifically
import functools
import inspect
import warnings
class deprecated(object):
def __init__(self, reason):
if inspect.isclass(reason) or inspect.isfunction(reason):
raise TypeError("Reason for deprecation must be supplied")
self.reason = reason
def __call__(self, cls_or_func):
if inspect.isfunction(cls_or_func):
if hasattr(cls_or_func, 'func_code'):
_code = cls_or_func.func_code
else:
_code = cls_or_func.__code__
fmt = "Call to deprecated function or method {name} ({reason})."
filename = _code.co_filename
lineno = _code.co_firstlineno + 1
elif inspect.isclass(cls_or_func):
fmt = "Call to deprecated class {name} ({reason})."
filename = cls_or_func.__module__
lineno = 1
else:
raise TypeError(type(cls_or_func))
msg = fmt.format(name=cls_or_func.__name__, reason=self.reason)
@functools.wraps(cls_or_func)
def new_func(*args, **kwargs):
warnings.simplefilter('always', DeprecationWarning) # turn off filter
warnings.warn_explicit(msg, category=DeprecationWarning, filename=filename, lineno=lineno)
warnings.simplefilter('default', DeprecationWarning) # reset filter
return cls_or_func(*args, **kwargs)
return new_func
|