Add loan-advisor-agent
Browse files- loan-advisor-agent/.venv/Lib/site-packages/wrapt/__init__.py +30 -0
- loan-advisor-agent/.venv/Lib/site-packages/wrapt/__wrapt__.py +14 -0
- loan-advisor-agent/.venv/Lib/site-packages/wrapt/_wrappers.cp312-win_amd64.pyd +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/wrapt/arguments.py +38 -0
- loan-advisor-agent/.venv/Lib/site-packages/wrapt/decorators.py +541 -0
- loan-advisor-agent/.venv/Lib/site-packages/wrapt/importer.py +295 -0
- loan-advisor-agent/.venv/Lib/site-packages/wrapt/patches.py +141 -0
- loan-advisor-agent/.venv/Lib/site-packages/wrapt/weakrefs.py +98 -0
- loan-advisor-agent/.venv/Lib/site-packages/wrapt/wrappers.py +821 -0
loan-advisor-agent/.venv/Lib/site-packages/wrapt/__init__.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__version_info__ = ('1', '17', '3')
|
| 2 |
+
__version__ = '.'.join(__version_info__)
|
| 3 |
+
|
| 4 |
+
from .__wrapt__ import (ObjectProxy, CallableObjectProxy, FunctionWrapper,
|
| 5 |
+
BoundFunctionWrapper, PartialCallableObjectProxy)
|
| 6 |
+
|
| 7 |
+
from .patches import (resolve_path, apply_patch, wrap_object, wrap_object_attribute,
|
| 8 |
+
function_wrapper, wrap_function_wrapper, patch_function_wrapper,
|
| 9 |
+
transient_function_wrapper)
|
| 10 |
+
|
| 11 |
+
from .weakrefs import WeakFunctionProxy
|
| 12 |
+
|
| 13 |
+
from .decorators import (adapter_factory, AdapterFactory, decorator,
|
| 14 |
+
synchronized)
|
| 15 |
+
|
| 16 |
+
from .importer import (register_post_import_hook, when_imported,
|
| 17 |
+
notify_module_loaded, discover_post_import_hooks)
|
| 18 |
+
|
| 19 |
+
# Import of inspect.getcallargs() included for backward compatibility. An
|
| 20 |
+
# implementation of this was previously bundled and made available here for
|
| 21 |
+
# Python <2.7. Avoid using this in future.
|
| 22 |
+
|
| 23 |
+
from inspect import getcallargs
|
| 24 |
+
|
| 25 |
+
# Variant of inspect.formatargspec() included here for forward compatibility.
|
| 26 |
+
# This is being done because Python 3.11 dropped inspect.formatargspec() but
|
| 27 |
+
# code for handling signature changing decorators relied on it. Exposing the
|
| 28 |
+
# bundled implementation here in case any user of wrapt was also needing it.
|
| 29 |
+
|
| 30 |
+
from .arguments import formatargspec
|
loan-advisor-agent/.venv/Lib/site-packages/wrapt/__wrapt__.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
from .wrappers import (ObjectProxy, CallableObjectProxy,
|
| 4 |
+
PartialCallableObjectProxy, FunctionWrapper,
|
| 5 |
+
BoundFunctionWrapper, _FunctionWrapperBase)
|
| 6 |
+
|
| 7 |
+
try:
|
| 8 |
+
if not os.environ.get('WRAPT_DISABLE_EXTENSIONS'):
|
| 9 |
+
from ._wrappers import (ObjectProxy, CallableObjectProxy,
|
| 10 |
+
PartialCallableObjectProxy, FunctionWrapper,
|
| 11 |
+
BoundFunctionWrapper, _FunctionWrapperBase)
|
| 12 |
+
|
| 13 |
+
except ImportError:
|
| 14 |
+
pass
|
loan-advisor-agent/.venv/Lib/site-packages/wrapt/_wrappers.cp312-win_amd64.pyd
ADDED
|
Binary file (38.9 kB). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/wrapt/arguments.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# The inspect.formatargspec() function was dropped in Python 3.11 but we need
|
| 2 |
+
# need it for when constructing signature changing decorators based on result of
|
| 3 |
+
# inspect.getargspec() or inspect.getfullargspec(). The code here implements
|
| 4 |
+
# inspect.formatargspec() base on Parameter and Signature from inspect module,
|
| 5 |
+
# which were added in Python 3.6. Thanks to Cyril Jouve for the implementation.
|
| 6 |
+
|
| 7 |
+
try:
|
| 8 |
+
from inspect import Parameter, Signature
|
| 9 |
+
except ImportError:
|
| 10 |
+
from inspect import formatargspec
|
| 11 |
+
else:
|
| 12 |
+
def formatargspec(args, varargs=None, varkw=None, defaults=None,
|
| 13 |
+
kwonlyargs=(), kwonlydefaults={}, annotations={}):
|
| 14 |
+
if kwonlydefaults is None:
|
| 15 |
+
kwonlydefaults = {}
|
| 16 |
+
ndefaults = len(defaults) if defaults else 0
|
| 17 |
+
parameters = [
|
| 18 |
+
Parameter(
|
| 19 |
+
arg,
|
| 20 |
+
Parameter.POSITIONAL_OR_KEYWORD,
|
| 21 |
+
default=defaults[i] if i >= 0 else Parameter.empty,
|
| 22 |
+
annotation=annotations.get(arg, Parameter.empty),
|
| 23 |
+
) for i, arg in enumerate(args, ndefaults - len(args))
|
| 24 |
+
]
|
| 25 |
+
if varargs:
|
| 26 |
+
parameters.append(Parameter(varargs, Parameter.VAR_POSITIONAL))
|
| 27 |
+
parameters.extend(
|
| 28 |
+
Parameter(
|
| 29 |
+
kwonlyarg,
|
| 30 |
+
Parameter.KEYWORD_ONLY,
|
| 31 |
+
default=kwonlydefaults.get(kwonlyarg, Parameter.empty),
|
| 32 |
+
annotation=annotations.get(kwonlyarg, Parameter.empty),
|
| 33 |
+
) for kwonlyarg in kwonlyargs
|
| 34 |
+
)
|
| 35 |
+
if varkw:
|
| 36 |
+
parameters.append(Parameter(varkw, Parameter.VAR_KEYWORD))
|
| 37 |
+
return_annotation = annotations.get('return', Signature.empty)
|
| 38 |
+
return str(Signature(parameters, return_annotation=return_annotation))
|
loan-advisor-agent/.venv/Lib/site-packages/wrapt/decorators.py
ADDED
|
@@ -0,0 +1,541 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""This module implements decorators for implementing other decorators
|
| 2 |
+
as well as some commonly used decorators.
|
| 3 |
+
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import sys
|
| 7 |
+
|
| 8 |
+
PY2 = sys.version_info[0] == 2
|
| 9 |
+
|
| 10 |
+
if PY2:
|
| 11 |
+
string_types = basestring,
|
| 12 |
+
|
| 13 |
+
def exec_(_code_, _globs_=None, _locs_=None):
|
| 14 |
+
"""Execute code in a namespace."""
|
| 15 |
+
if _globs_ is None:
|
| 16 |
+
frame = sys._getframe(1)
|
| 17 |
+
_globs_ = frame.f_globals
|
| 18 |
+
if _locs_ is None:
|
| 19 |
+
_locs_ = frame.f_locals
|
| 20 |
+
del frame
|
| 21 |
+
elif _locs_ is None:
|
| 22 |
+
_locs_ = _globs_
|
| 23 |
+
exec("""exec _code_ in _globs_, _locs_""")
|
| 24 |
+
|
| 25 |
+
else:
|
| 26 |
+
string_types = str,
|
| 27 |
+
|
| 28 |
+
import builtins
|
| 29 |
+
|
| 30 |
+
exec_ = getattr(builtins, "exec")
|
| 31 |
+
del builtins
|
| 32 |
+
|
| 33 |
+
from functools import partial
|
| 34 |
+
from inspect import isclass
|
| 35 |
+
from threading import Lock, RLock
|
| 36 |
+
|
| 37 |
+
from .arguments import formatargspec
|
| 38 |
+
|
| 39 |
+
try:
|
| 40 |
+
from inspect import signature
|
| 41 |
+
except ImportError:
|
| 42 |
+
pass
|
| 43 |
+
|
| 44 |
+
from .__wrapt__ import (FunctionWrapper, BoundFunctionWrapper, ObjectProxy,
|
| 45 |
+
CallableObjectProxy)
|
| 46 |
+
|
| 47 |
+
# Adapter wrapper for the wrapped function which will overlay certain
|
| 48 |
+
# properties from the adapter function onto the wrapped function so that
|
| 49 |
+
# functions such as inspect.getargspec(), inspect.getfullargspec(),
|
| 50 |
+
# inspect.signature() and inspect.getsource() return the correct results
|
| 51 |
+
# one would expect.
|
| 52 |
+
|
| 53 |
+
class _AdapterFunctionCode(CallableObjectProxy):
|
| 54 |
+
|
| 55 |
+
def __init__(self, wrapped_code, adapter_code):
|
| 56 |
+
super(_AdapterFunctionCode, self).__init__(wrapped_code)
|
| 57 |
+
self._self_adapter_code = adapter_code
|
| 58 |
+
|
| 59 |
+
@property
|
| 60 |
+
def co_argcount(self):
|
| 61 |
+
return self._self_adapter_code.co_argcount
|
| 62 |
+
|
| 63 |
+
@property
|
| 64 |
+
def co_code(self):
|
| 65 |
+
return self._self_adapter_code.co_code
|
| 66 |
+
|
| 67 |
+
@property
|
| 68 |
+
def co_flags(self):
|
| 69 |
+
return self._self_adapter_code.co_flags
|
| 70 |
+
|
| 71 |
+
@property
|
| 72 |
+
def co_kwonlyargcount(self):
|
| 73 |
+
return self._self_adapter_code.co_kwonlyargcount
|
| 74 |
+
|
| 75 |
+
@property
|
| 76 |
+
def co_varnames(self):
|
| 77 |
+
return self._self_adapter_code.co_varnames
|
| 78 |
+
|
| 79 |
+
class _AdapterFunctionSurrogate(CallableObjectProxy):
|
| 80 |
+
|
| 81 |
+
def __init__(self, wrapped, adapter):
|
| 82 |
+
super(_AdapterFunctionSurrogate, self).__init__(wrapped)
|
| 83 |
+
self._self_adapter = adapter
|
| 84 |
+
|
| 85 |
+
@property
|
| 86 |
+
def __code__(self):
|
| 87 |
+
return _AdapterFunctionCode(self.__wrapped__.__code__,
|
| 88 |
+
self._self_adapter.__code__)
|
| 89 |
+
|
| 90 |
+
@property
|
| 91 |
+
def __defaults__(self):
|
| 92 |
+
return self._self_adapter.__defaults__
|
| 93 |
+
|
| 94 |
+
@property
|
| 95 |
+
def __kwdefaults__(self):
|
| 96 |
+
return self._self_adapter.__kwdefaults__
|
| 97 |
+
|
| 98 |
+
@property
|
| 99 |
+
def __signature__(self):
|
| 100 |
+
if 'signature' not in globals():
|
| 101 |
+
return self._self_adapter.__signature__
|
| 102 |
+
else:
|
| 103 |
+
return signature(self._self_adapter)
|
| 104 |
+
|
| 105 |
+
if PY2:
|
| 106 |
+
func_code = __code__
|
| 107 |
+
func_defaults = __defaults__
|
| 108 |
+
|
| 109 |
+
class _BoundAdapterWrapper(BoundFunctionWrapper):
|
| 110 |
+
|
| 111 |
+
@property
|
| 112 |
+
def __func__(self):
|
| 113 |
+
return _AdapterFunctionSurrogate(self.__wrapped__.__func__,
|
| 114 |
+
self._self_parent._self_adapter)
|
| 115 |
+
|
| 116 |
+
@property
|
| 117 |
+
def __signature__(self):
|
| 118 |
+
if 'signature' not in globals():
|
| 119 |
+
return self.__wrapped__.__signature__
|
| 120 |
+
else:
|
| 121 |
+
return signature(self._self_parent._self_adapter)
|
| 122 |
+
|
| 123 |
+
if PY2:
|
| 124 |
+
im_func = __func__
|
| 125 |
+
|
| 126 |
+
class AdapterWrapper(FunctionWrapper):
|
| 127 |
+
|
| 128 |
+
__bound_function_wrapper__ = _BoundAdapterWrapper
|
| 129 |
+
|
| 130 |
+
def __init__(self, *args, **kwargs):
|
| 131 |
+
adapter = kwargs.pop('adapter')
|
| 132 |
+
super(AdapterWrapper, self).__init__(*args, **kwargs)
|
| 133 |
+
self._self_surrogate = _AdapterFunctionSurrogate(
|
| 134 |
+
self.__wrapped__, adapter)
|
| 135 |
+
self._self_adapter = adapter
|
| 136 |
+
|
| 137 |
+
@property
|
| 138 |
+
def __code__(self):
|
| 139 |
+
return self._self_surrogate.__code__
|
| 140 |
+
|
| 141 |
+
@property
|
| 142 |
+
def __defaults__(self):
|
| 143 |
+
return self._self_surrogate.__defaults__
|
| 144 |
+
|
| 145 |
+
@property
|
| 146 |
+
def __kwdefaults__(self):
|
| 147 |
+
return self._self_surrogate.__kwdefaults__
|
| 148 |
+
|
| 149 |
+
if PY2:
|
| 150 |
+
func_code = __code__
|
| 151 |
+
func_defaults = __defaults__
|
| 152 |
+
|
| 153 |
+
@property
|
| 154 |
+
def __signature__(self):
|
| 155 |
+
return self._self_surrogate.__signature__
|
| 156 |
+
|
| 157 |
+
class AdapterFactory(object):
|
| 158 |
+
def __call__(self, wrapped):
|
| 159 |
+
raise NotImplementedError()
|
| 160 |
+
|
| 161 |
+
class DelegatedAdapterFactory(AdapterFactory):
|
| 162 |
+
def __init__(self, factory):
|
| 163 |
+
super(DelegatedAdapterFactory, self).__init__()
|
| 164 |
+
self.factory = factory
|
| 165 |
+
def __call__(self, wrapped):
|
| 166 |
+
return self.factory(wrapped)
|
| 167 |
+
|
| 168 |
+
adapter_factory = DelegatedAdapterFactory
|
| 169 |
+
|
| 170 |
+
# Decorator for creating other decorators. This decorator and the
|
| 171 |
+
# wrappers which they use are designed to properly preserve any name
|
| 172 |
+
# attributes, function signatures etc, in addition to the wrappers
|
| 173 |
+
# themselves acting like a transparent proxy for the original wrapped
|
| 174 |
+
# function so the wrapper is effectively indistinguishable from the
|
| 175 |
+
# original wrapped function.
|
| 176 |
+
|
| 177 |
+
def decorator(wrapper=None, enabled=None, adapter=None, proxy=FunctionWrapper):
|
| 178 |
+
# The decorator should be supplied with a single positional argument
|
| 179 |
+
# which is the wrapper function to be used to implement the
|
| 180 |
+
# decorator. This may be preceded by a step whereby the keyword
|
| 181 |
+
# arguments are supplied to customise the behaviour of the
|
| 182 |
+
# decorator. The 'adapter' argument is used to optionally denote a
|
| 183 |
+
# separate function which is notionally used by an adapter
|
| 184 |
+
# decorator. In that case parts of the function '__code__' and
|
| 185 |
+
# '__defaults__' attributes are used from the adapter function
|
| 186 |
+
# rather than those of the wrapped function. This allows for the
|
| 187 |
+
# argument specification from inspect.getfullargspec() and similar
|
| 188 |
+
# functions to be overridden with a prototype for a different
|
| 189 |
+
# function than what was wrapped. The 'enabled' argument provides a
|
| 190 |
+
# way to enable/disable the use of the decorator. If the type of
|
| 191 |
+
# 'enabled' is a boolean, then it is evaluated immediately and the
|
| 192 |
+
# wrapper not even applied if it is False. If not a boolean, it will
|
| 193 |
+
# be evaluated when the wrapper is called for an unbound wrapper,
|
| 194 |
+
# and when binding occurs for a bound wrapper. When being evaluated,
|
| 195 |
+
# if 'enabled' is callable it will be called to obtain the value to
|
| 196 |
+
# be checked. If False, the wrapper will not be called and instead
|
| 197 |
+
# the original wrapped function will be called directly instead.
|
| 198 |
+
# The 'proxy' argument provides a way of passing a custom version of
|
| 199 |
+
# the FunctionWrapper class used in decorating the function.
|
| 200 |
+
|
| 201 |
+
if wrapper is not None:
|
| 202 |
+
# Helper function for creating wrapper of the appropriate
|
| 203 |
+
# time when we need it down below.
|
| 204 |
+
|
| 205 |
+
def _build(wrapped, wrapper, enabled=None, adapter=None):
|
| 206 |
+
if adapter:
|
| 207 |
+
if isinstance(adapter, AdapterFactory):
|
| 208 |
+
adapter = adapter(wrapped)
|
| 209 |
+
|
| 210 |
+
if not callable(adapter):
|
| 211 |
+
ns = {}
|
| 212 |
+
|
| 213 |
+
# Check if the signature argument specification has
|
| 214 |
+
# annotations. If it does then we need to remember
|
| 215 |
+
# it but also drop it when attempting to manufacture
|
| 216 |
+
# a standin adapter function. This is necessary else
|
| 217 |
+
# it will try and look up any types referenced in
|
| 218 |
+
# the annotations in the empty namespace we use,
|
| 219 |
+
# which will fail.
|
| 220 |
+
|
| 221 |
+
annotations = {}
|
| 222 |
+
|
| 223 |
+
if not isinstance(adapter, string_types):
|
| 224 |
+
if len(adapter) == 7:
|
| 225 |
+
annotations = adapter[-1]
|
| 226 |
+
adapter = adapter[:-1]
|
| 227 |
+
adapter = formatargspec(*adapter)
|
| 228 |
+
|
| 229 |
+
exec_('def adapter{}: pass'.format(adapter), ns, ns)
|
| 230 |
+
adapter = ns['adapter']
|
| 231 |
+
|
| 232 |
+
# Override the annotations for the manufactured
|
| 233 |
+
# adapter function so they match the original
|
| 234 |
+
# adapter signature argument specification.
|
| 235 |
+
|
| 236 |
+
if annotations:
|
| 237 |
+
adapter.__annotations__ = annotations
|
| 238 |
+
|
| 239 |
+
return AdapterWrapper(wrapped=wrapped, wrapper=wrapper,
|
| 240 |
+
enabled=enabled, adapter=adapter)
|
| 241 |
+
|
| 242 |
+
return proxy(wrapped=wrapped, wrapper=wrapper, enabled=enabled)
|
| 243 |
+
|
| 244 |
+
# The wrapper has been provided so return the final decorator.
|
| 245 |
+
# The decorator is itself one of our function wrappers so we
|
| 246 |
+
# can determine when it is applied to functions, instance methods
|
| 247 |
+
# or class methods. This allows us to bind the instance or class
|
| 248 |
+
# method so the appropriate self or cls attribute is supplied
|
| 249 |
+
# when it is finally called.
|
| 250 |
+
|
| 251 |
+
def _wrapper(wrapped, instance, args, kwargs):
|
| 252 |
+
# We first check for the case where the decorator was applied
|
| 253 |
+
# to a class type.
|
| 254 |
+
#
|
| 255 |
+
# @decorator
|
| 256 |
+
# class mydecoratorclass(object):
|
| 257 |
+
# def __init__(self, arg=None):
|
| 258 |
+
# self.arg = arg
|
| 259 |
+
# def __call__(self, wrapped, instance, args, kwargs):
|
| 260 |
+
# return wrapped(*args, **kwargs)
|
| 261 |
+
#
|
| 262 |
+
# @mydecoratorclass(arg=1)
|
| 263 |
+
# def function():
|
| 264 |
+
# pass
|
| 265 |
+
#
|
| 266 |
+
# In this case an instance of the class is to be used as the
|
| 267 |
+
# decorator wrapper function. If args was empty at this point,
|
| 268 |
+
# then it means that there were optional keyword arguments
|
| 269 |
+
# supplied to be used when creating an instance of the class
|
| 270 |
+
# to be used as the wrapper function.
|
| 271 |
+
|
| 272 |
+
if instance is None and isclass(wrapped) and not args:
|
| 273 |
+
# We still need to be passed the target function to be
|
| 274 |
+
# wrapped as yet, so we need to return a further function
|
| 275 |
+
# to be able to capture it.
|
| 276 |
+
|
| 277 |
+
def _capture(target_wrapped):
|
| 278 |
+
# Now have the target function to be wrapped and need
|
| 279 |
+
# to create an instance of the class which is to act
|
| 280 |
+
# as the decorator wrapper function. Before we do that,
|
| 281 |
+
# we need to first check that use of the decorator
|
| 282 |
+
# hadn't been disabled by a simple boolean. If it was,
|
| 283 |
+
# the target function to be wrapped is returned instead.
|
| 284 |
+
|
| 285 |
+
_enabled = enabled
|
| 286 |
+
if type(_enabled) is bool:
|
| 287 |
+
if not _enabled:
|
| 288 |
+
return target_wrapped
|
| 289 |
+
_enabled = None
|
| 290 |
+
|
| 291 |
+
# Now create an instance of the class which is to act
|
| 292 |
+
# as the decorator wrapper function. Any arguments had
|
| 293 |
+
# to be supplied as keyword only arguments so that is
|
| 294 |
+
# all we pass when creating it.
|
| 295 |
+
|
| 296 |
+
target_wrapper = wrapped(**kwargs)
|
| 297 |
+
|
| 298 |
+
# Finally build the wrapper itself and return it.
|
| 299 |
+
|
| 300 |
+
return _build(target_wrapped, target_wrapper,
|
| 301 |
+
_enabled, adapter)
|
| 302 |
+
|
| 303 |
+
return _capture
|
| 304 |
+
|
| 305 |
+
# We should always have the target function to be wrapped at
|
| 306 |
+
# this point as the first (and only) value in args.
|
| 307 |
+
|
| 308 |
+
target_wrapped = args[0]
|
| 309 |
+
|
| 310 |
+
# Need to now check that use of the decorator hadn't been
|
| 311 |
+
# disabled by a simple boolean. If it was, then target
|
| 312 |
+
# function to be wrapped is returned instead.
|
| 313 |
+
|
| 314 |
+
_enabled = enabled
|
| 315 |
+
if type(_enabled) is bool:
|
| 316 |
+
if not _enabled:
|
| 317 |
+
return target_wrapped
|
| 318 |
+
_enabled = None
|
| 319 |
+
|
| 320 |
+
# We now need to build the wrapper, but there are a couple of
|
| 321 |
+
# different cases we need to consider.
|
| 322 |
+
|
| 323 |
+
if instance is None:
|
| 324 |
+
if isclass(wrapped):
|
| 325 |
+
# In this case the decorator was applied to a class
|
| 326 |
+
# type but optional keyword arguments were not supplied
|
| 327 |
+
# for initialising an instance of the class to be used
|
| 328 |
+
# as the decorator wrapper function.
|
| 329 |
+
#
|
| 330 |
+
# @decorator
|
| 331 |
+
# class mydecoratorclass(object):
|
| 332 |
+
# def __init__(self, arg=None):
|
| 333 |
+
# self.arg = arg
|
| 334 |
+
# def __call__(self, wrapped, instance,
|
| 335 |
+
# args, kwargs):
|
| 336 |
+
# return wrapped(*args, **kwargs)
|
| 337 |
+
#
|
| 338 |
+
# @mydecoratorclass
|
| 339 |
+
# def function():
|
| 340 |
+
# pass
|
| 341 |
+
#
|
| 342 |
+
# We still need to create an instance of the class to
|
| 343 |
+
# be used as the decorator wrapper function, but no
|
| 344 |
+
# arguments are pass.
|
| 345 |
+
|
| 346 |
+
target_wrapper = wrapped()
|
| 347 |
+
|
| 348 |
+
else:
|
| 349 |
+
# In this case the decorator was applied to a normal
|
| 350 |
+
# function, or possibly a static method of a class.
|
| 351 |
+
#
|
| 352 |
+
# @decorator
|
| 353 |
+
# def mydecoratorfuntion(wrapped, instance,
|
| 354 |
+
# args, kwargs):
|
| 355 |
+
# return wrapped(*args, **kwargs)
|
| 356 |
+
#
|
| 357 |
+
# @mydecoratorfunction
|
| 358 |
+
# def function():
|
| 359 |
+
# pass
|
| 360 |
+
#
|
| 361 |
+
# That normal function becomes the decorator wrapper
|
| 362 |
+
# function.
|
| 363 |
+
|
| 364 |
+
target_wrapper = wrapper
|
| 365 |
+
|
| 366 |
+
else:
|
| 367 |
+
if isclass(instance):
|
| 368 |
+
# In this case the decorator was applied to a class
|
| 369 |
+
# method.
|
| 370 |
+
#
|
| 371 |
+
# class myclass(object):
|
| 372 |
+
# @decorator
|
| 373 |
+
# @classmethod
|
| 374 |
+
# def decoratorclassmethod(cls, wrapped,
|
| 375 |
+
# instance, args, kwargs):
|
| 376 |
+
# return wrapped(*args, **kwargs)
|
| 377 |
+
#
|
| 378 |
+
# instance = myclass()
|
| 379 |
+
#
|
| 380 |
+
# @instance.decoratorclassmethod
|
| 381 |
+
# def function():
|
| 382 |
+
# pass
|
| 383 |
+
#
|
| 384 |
+
# This one is a bit strange because binding was actually
|
| 385 |
+
# performed on the wrapper created by our decorator
|
| 386 |
+
# factory. We need to apply that binding to the decorator
|
| 387 |
+
# wrapper function that the decorator factory
|
| 388 |
+
# was applied to.
|
| 389 |
+
|
| 390 |
+
target_wrapper = wrapper.__get__(None, instance)
|
| 391 |
+
|
| 392 |
+
else:
|
| 393 |
+
# In this case the decorator was applied to an instance
|
| 394 |
+
# method.
|
| 395 |
+
#
|
| 396 |
+
# class myclass(object):
|
| 397 |
+
# @decorator
|
| 398 |
+
# def decoratorclassmethod(self, wrapped,
|
| 399 |
+
# instance, args, kwargs):
|
| 400 |
+
# return wrapped(*args, **kwargs)
|
| 401 |
+
#
|
| 402 |
+
# instance = myclass()
|
| 403 |
+
#
|
| 404 |
+
# @instance.decoratorclassmethod
|
| 405 |
+
# def function():
|
| 406 |
+
# pass
|
| 407 |
+
#
|
| 408 |
+
# This one is a bit strange because binding was actually
|
| 409 |
+
# performed on the wrapper created by our decorator
|
| 410 |
+
# factory. We need to apply that binding to the decorator
|
| 411 |
+
# wrapper function that the decorator factory
|
| 412 |
+
# was applied to.
|
| 413 |
+
|
| 414 |
+
target_wrapper = wrapper.__get__(instance, type(instance))
|
| 415 |
+
|
| 416 |
+
# Finally build the wrapper itself and return it.
|
| 417 |
+
|
| 418 |
+
return _build(target_wrapped, target_wrapper, _enabled, adapter)
|
| 419 |
+
|
| 420 |
+
# We first return our magic function wrapper here so we can
|
| 421 |
+
# determine in what context the decorator factory was used. In
|
| 422 |
+
# other words, it is itself a universal decorator. The decorator
|
| 423 |
+
# function is used as the adapter so that linters see a signature
|
| 424 |
+
# corresponding to the decorator and not the wrapper it is being
|
| 425 |
+
# applied to.
|
| 426 |
+
|
| 427 |
+
return _build(wrapper, _wrapper, adapter=decorator)
|
| 428 |
+
|
| 429 |
+
else:
|
| 430 |
+
# The wrapper still has not been provided, so we are just
|
| 431 |
+
# collecting the optional keyword arguments. Return the
|
| 432 |
+
# decorator again wrapped in a partial using the collected
|
| 433 |
+
# arguments.
|
| 434 |
+
|
| 435 |
+
return partial(decorator, enabled=enabled, adapter=adapter,
|
| 436 |
+
proxy=proxy)
|
| 437 |
+
|
| 438 |
+
# Decorator for implementing thread synchronization. It can be used as a
|
| 439 |
+
# decorator, in which case the synchronization context is determined by
|
| 440 |
+
# what type of function is wrapped, or it can also be used as a context
|
| 441 |
+
# manager, where the user needs to supply the correct synchronization
|
| 442 |
+
# context. It is also possible to supply an object which appears to be a
|
| 443 |
+
# synchronization primitive of some sort, by virtue of having release()
|
| 444 |
+
# and acquire() methods. In that case that will be used directly as the
|
| 445 |
+
# synchronization primitive without creating a separate lock against the
|
| 446 |
+
# derived or supplied context.
|
| 447 |
+
|
| 448 |
+
def synchronized(wrapped):
|
| 449 |
+
# Determine if being passed an object which is a synchronization
|
| 450 |
+
# primitive. We can't check by type for Lock, RLock, Semaphore etc,
|
| 451 |
+
# as the means of creating them isn't the type. Therefore use the
|
| 452 |
+
# existence of acquire() and release() methods. This is more
|
| 453 |
+
# extensible anyway as it allows custom synchronization mechanisms.
|
| 454 |
+
|
| 455 |
+
if hasattr(wrapped, 'acquire') and hasattr(wrapped, 'release'):
|
| 456 |
+
# We remember what the original lock is and then return a new
|
| 457 |
+
# decorator which accesses and locks it. When returning the new
|
| 458 |
+
# decorator we wrap it with an object proxy so we can override
|
| 459 |
+
# the context manager methods in case it is being used to wrap
|
| 460 |
+
# synchronized statements with a 'with' statement.
|
| 461 |
+
|
| 462 |
+
lock = wrapped
|
| 463 |
+
|
| 464 |
+
@decorator
|
| 465 |
+
def _synchronized(wrapped, instance, args, kwargs):
|
| 466 |
+
# Execute the wrapped function while the original supplied
|
| 467 |
+
# lock is held.
|
| 468 |
+
|
| 469 |
+
with lock:
|
| 470 |
+
return wrapped(*args, **kwargs)
|
| 471 |
+
|
| 472 |
+
class _PartialDecorator(CallableObjectProxy):
|
| 473 |
+
|
| 474 |
+
def __enter__(self):
|
| 475 |
+
lock.acquire()
|
| 476 |
+
return lock
|
| 477 |
+
|
| 478 |
+
def __exit__(self, *args):
|
| 479 |
+
lock.release()
|
| 480 |
+
|
| 481 |
+
return _PartialDecorator(wrapped=_synchronized)
|
| 482 |
+
|
| 483 |
+
# Following only apply when the lock is being created automatically
|
| 484 |
+
# based on the context of what was supplied. In this case we supply
|
| 485 |
+
# a final decorator, but need to use FunctionWrapper directly as we
|
| 486 |
+
# want to derive from it to add context manager methods in case it is
|
| 487 |
+
# being used to wrap synchronized statements with a 'with' statement.
|
| 488 |
+
|
| 489 |
+
def _synchronized_lock(context):
|
| 490 |
+
# Attempt to retrieve the lock for the specific context.
|
| 491 |
+
|
| 492 |
+
lock = vars(context).get('_synchronized_lock', None)
|
| 493 |
+
|
| 494 |
+
if lock is None:
|
| 495 |
+
# There is no existing lock defined for the context we
|
| 496 |
+
# are dealing with so we need to create one. This needs
|
| 497 |
+
# to be done in a way to guarantee there is only one
|
| 498 |
+
# created, even if multiple threads try and create it at
|
| 499 |
+
# the same time. We can't always use the setdefault()
|
| 500 |
+
# method on the __dict__ for the context. This is the
|
| 501 |
+
# case where the context is a class, as __dict__ is
|
| 502 |
+
# actually a dictproxy. What we therefore do is use a
|
| 503 |
+
# meta lock on this wrapper itself, to control the
|
| 504 |
+
# creation and assignment of the lock attribute against
|
| 505 |
+
# the context.
|
| 506 |
+
|
| 507 |
+
with synchronized._synchronized_meta_lock:
|
| 508 |
+
# We need to check again for whether the lock we want
|
| 509 |
+
# exists in case two threads were trying to create it
|
| 510 |
+
# at the same time and were competing to create the
|
| 511 |
+
# meta lock.
|
| 512 |
+
|
| 513 |
+
lock = vars(context).get('_synchronized_lock', None)
|
| 514 |
+
|
| 515 |
+
if lock is None:
|
| 516 |
+
lock = RLock()
|
| 517 |
+
setattr(context, '_synchronized_lock', lock)
|
| 518 |
+
|
| 519 |
+
return lock
|
| 520 |
+
|
| 521 |
+
def _synchronized_wrapper(wrapped, instance, args, kwargs):
|
| 522 |
+
# Execute the wrapped function while the lock for the
|
| 523 |
+
# desired context is held. If instance is None then the
|
| 524 |
+
# wrapped function is used as the context.
|
| 525 |
+
|
| 526 |
+
with _synchronized_lock(instance if instance is not None else wrapped):
|
| 527 |
+
return wrapped(*args, **kwargs)
|
| 528 |
+
|
| 529 |
+
class _FinalDecorator(FunctionWrapper):
|
| 530 |
+
|
| 531 |
+
def __enter__(self):
|
| 532 |
+
self._self_lock = _synchronized_lock(self.__wrapped__)
|
| 533 |
+
self._self_lock.acquire()
|
| 534 |
+
return self._self_lock
|
| 535 |
+
|
| 536 |
+
def __exit__(self, *args):
|
| 537 |
+
self._self_lock.release()
|
| 538 |
+
|
| 539 |
+
return _FinalDecorator(wrapped=wrapped, wrapper=_synchronized_wrapper)
|
| 540 |
+
|
| 541 |
+
synchronized._synchronized_meta_lock = Lock()
|
loan-advisor-agent/.venv/Lib/site-packages/wrapt/importer.py
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""This module implements a post import hook mechanism styled after what is
|
| 2 |
+
described in PEP-369. Note that it doesn't cope with modules being reloaded.
|
| 3 |
+
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import sys
|
| 7 |
+
import threading
|
| 8 |
+
|
| 9 |
+
PY2 = sys.version_info[0] == 2
|
| 10 |
+
|
| 11 |
+
if PY2:
|
| 12 |
+
string_types = basestring,
|
| 13 |
+
find_spec = None
|
| 14 |
+
else:
|
| 15 |
+
string_types = str,
|
| 16 |
+
from importlib.util import find_spec
|
| 17 |
+
|
| 18 |
+
from .__wrapt__ import ObjectProxy
|
| 19 |
+
|
| 20 |
+
# The dictionary registering any post import hooks to be triggered once
|
| 21 |
+
# the target module has been imported. Once a module has been imported
|
| 22 |
+
# and the hooks fired, the list of hooks recorded against the target
|
| 23 |
+
# module will be truncated but the list left in the dictionary. This
|
| 24 |
+
# acts as a flag to indicate that the module had already been imported.
|
| 25 |
+
|
| 26 |
+
_post_import_hooks = {}
|
| 27 |
+
_post_import_hooks_init = False
|
| 28 |
+
_post_import_hooks_lock = threading.RLock()
|
| 29 |
+
|
| 30 |
+
# Register a new post import hook for the target module name. This
|
| 31 |
+
# differs from the PEP-369 implementation in that it also allows the
|
| 32 |
+
# hook function to be specified as a string consisting of the name of
|
| 33 |
+
# the callback in the form 'module:function'. This will result in a
|
| 34 |
+
# proxy callback being registered which will defer loading of the
|
| 35 |
+
# specified module containing the callback function until required.
|
| 36 |
+
|
| 37 |
+
def _create_import_hook_from_string(name):
|
| 38 |
+
def import_hook(module):
|
| 39 |
+
module_name, function = name.split(':')
|
| 40 |
+
attrs = function.split('.')
|
| 41 |
+
__import__(module_name)
|
| 42 |
+
callback = sys.modules[module_name]
|
| 43 |
+
for attr in attrs:
|
| 44 |
+
callback = getattr(callback, attr)
|
| 45 |
+
return callback(module)
|
| 46 |
+
return import_hook
|
| 47 |
+
|
| 48 |
+
def register_post_import_hook(hook, name):
|
| 49 |
+
# Create a deferred import hook if hook is a string name rather than
|
| 50 |
+
# a callable function.
|
| 51 |
+
|
| 52 |
+
if isinstance(hook, string_types):
|
| 53 |
+
hook = _create_import_hook_from_string(hook)
|
| 54 |
+
|
| 55 |
+
with _post_import_hooks_lock:
|
| 56 |
+
# Automatically install the import hook finder if it has not already
|
| 57 |
+
# been installed.
|
| 58 |
+
|
| 59 |
+
global _post_import_hooks_init
|
| 60 |
+
|
| 61 |
+
if not _post_import_hooks_init:
|
| 62 |
+
_post_import_hooks_init = True
|
| 63 |
+
sys.meta_path.insert(0, ImportHookFinder())
|
| 64 |
+
|
| 65 |
+
# Check if the module is already imported. If not, register the hook
|
| 66 |
+
# to be called after import.
|
| 67 |
+
|
| 68 |
+
module = sys.modules.get(name, None)
|
| 69 |
+
|
| 70 |
+
if module is None:
|
| 71 |
+
_post_import_hooks.setdefault(name, []).append(hook)
|
| 72 |
+
|
| 73 |
+
# If the module is already imported, we fire the hook right away. Note that
|
| 74 |
+
# the hook is called outside of the lock to avoid deadlocks if code run as a
|
| 75 |
+
# consequence of calling the module import hook in turn triggers a separate
|
| 76 |
+
# thread which tries to register an import hook.
|
| 77 |
+
|
| 78 |
+
if module is not None:
|
| 79 |
+
hook(module)
|
| 80 |
+
|
| 81 |
+
# Register post import hooks defined as package entry points.
|
| 82 |
+
|
| 83 |
+
def _create_import_hook_from_entrypoint(entrypoint):
|
| 84 |
+
def import_hook(module):
|
| 85 |
+
__import__(entrypoint.module_name)
|
| 86 |
+
callback = sys.modules[entrypoint.module_name]
|
| 87 |
+
for attr in entrypoint.attrs:
|
| 88 |
+
callback = getattr(callback, attr)
|
| 89 |
+
return callback(module)
|
| 90 |
+
return import_hook
|
| 91 |
+
|
| 92 |
+
def discover_post_import_hooks(group):
|
| 93 |
+
try:
|
| 94 |
+
import pkg_resources
|
| 95 |
+
except ImportError:
|
| 96 |
+
return
|
| 97 |
+
|
| 98 |
+
for entrypoint in pkg_resources.iter_entry_points(group=group):
|
| 99 |
+
callback = _create_import_hook_from_entrypoint(entrypoint)
|
| 100 |
+
register_post_import_hook(callback, entrypoint.name)
|
| 101 |
+
|
| 102 |
+
# Indicate that a module has been loaded. Any post import hooks which
|
| 103 |
+
# were registered against the target module will be invoked. If an
|
| 104 |
+
# exception is raised in any of the post import hooks, that will cause
|
| 105 |
+
# the import of the target module to fail.
|
| 106 |
+
|
| 107 |
+
def notify_module_loaded(module):
|
| 108 |
+
name = getattr(module, '__name__', None)
|
| 109 |
+
|
| 110 |
+
with _post_import_hooks_lock:
|
| 111 |
+
hooks = _post_import_hooks.pop(name, ())
|
| 112 |
+
|
| 113 |
+
# Note that the hook is called outside of the lock to avoid deadlocks if
|
| 114 |
+
# code run as a consequence of calling the module import hook in turn
|
| 115 |
+
# triggers a separate thread which tries to register an import hook.
|
| 116 |
+
|
| 117 |
+
for hook in hooks:
|
| 118 |
+
hook(module)
|
| 119 |
+
|
| 120 |
+
# A custom module import finder. This intercepts attempts to import
|
| 121 |
+
# modules and watches out for attempts to import target modules of
|
| 122 |
+
# interest. When a module of interest is imported, then any post import
|
| 123 |
+
# hooks which are registered will be invoked.
|
| 124 |
+
|
| 125 |
+
class _ImportHookLoader:
|
| 126 |
+
|
| 127 |
+
def load_module(self, fullname):
|
| 128 |
+
module = sys.modules[fullname]
|
| 129 |
+
notify_module_loaded(module)
|
| 130 |
+
|
| 131 |
+
return module
|
| 132 |
+
|
| 133 |
+
class _ImportHookChainedLoader(ObjectProxy):
|
| 134 |
+
|
| 135 |
+
def __init__(self, loader):
|
| 136 |
+
super(_ImportHookChainedLoader, self).__init__(loader)
|
| 137 |
+
|
| 138 |
+
if hasattr(loader, "load_module"):
|
| 139 |
+
self.__self_setattr__('load_module', self._self_load_module)
|
| 140 |
+
if hasattr(loader, "create_module"):
|
| 141 |
+
self.__self_setattr__('create_module', self._self_create_module)
|
| 142 |
+
if hasattr(loader, "exec_module"):
|
| 143 |
+
self.__self_setattr__('exec_module', self._self_exec_module)
|
| 144 |
+
|
| 145 |
+
def _self_set_loader(self, module):
|
| 146 |
+
# Set module's loader to self.__wrapped__ unless it's already set to
|
| 147 |
+
# something else. Import machinery will set it to spec.loader if it is
|
| 148 |
+
# None, so handle None as well. The module may not support attribute
|
| 149 |
+
# assignment, in which case we simply skip it. Note that we also deal
|
| 150 |
+
# with __loader__ not existing at all. This is to future proof things
|
| 151 |
+
# due to proposal to remove the attribue as described in the GitHub
|
| 152 |
+
# issue at https://github.com/python/cpython/issues/77458. Also prior
|
| 153 |
+
# to Python 3.3, the __loader__ attribute was only set if a custom
|
| 154 |
+
# module loader was used. It isn't clear whether the attribute still
|
| 155 |
+
# existed in that case or was set to None.
|
| 156 |
+
|
| 157 |
+
class UNDEFINED: pass
|
| 158 |
+
|
| 159 |
+
if getattr(module, "__loader__", UNDEFINED) in (None, self):
|
| 160 |
+
try:
|
| 161 |
+
module.__loader__ = self.__wrapped__
|
| 162 |
+
except AttributeError:
|
| 163 |
+
pass
|
| 164 |
+
|
| 165 |
+
if (getattr(module, "__spec__", None) is not None
|
| 166 |
+
and getattr(module.__spec__, "loader", None) is self):
|
| 167 |
+
module.__spec__.loader = self.__wrapped__
|
| 168 |
+
|
| 169 |
+
def _self_load_module(self, fullname):
|
| 170 |
+
module = self.__wrapped__.load_module(fullname)
|
| 171 |
+
self._self_set_loader(module)
|
| 172 |
+
notify_module_loaded(module)
|
| 173 |
+
|
| 174 |
+
return module
|
| 175 |
+
|
| 176 |
+
# Python 3.4 introduced create_module() and exec_module() instead of
|
| 177 |
+
# load_module() alone. Splitting the two steps.
|
| 178 |
+
|
| 179 |
+
def _self_create_module(self, spec):
|
| 180 |
+
return self.__wrapped__.create_module(spec)
|
| 181 |
+
|
| 182 |
+
def _self_exec_module(self, module):
|
| 183 |
+
self._self_set_loader(module)
|
| 184 |
+
self.__wrapped__.exec_module(module)
|
| 185 |
+
notify_module_loaded(module)
|
| 186 |
+
|
| 187 |
+
class ImportHookFinder:
|
| 188 |
+
|
| 189 |
+
def __init__(self):
|
| 190 |
+
self.in_progress = {}
|
| 191 |
+
|
| 192 |
+
def find_module(self, fullname, path=None):
|
| 193 |
+
# If the module being imported is not one we have registered
|
| 194 |
+
# post import hooks for, we can return immediately. We will
|
| 195 |
+
# take no further part in the importing of this module.
|
| 196 |
+
|
| 197 |
+
with _post_import_hooks_lock:
|
| 198 |
+
if fullname not in _post_import_hooks:
|
| 199 |
+
return None
|
| 200 |
+
|
| 201 |
+
# When we are interested in a specific module, we will call back
|
| 202 |
+
# into the import system a second time to defer to the import
|
| 203 |
+
# finder that is supposed to handle the importing of the module.
|
| 204 |
+
# We set an in progress flag for the target module so that on
|
| 205 |
+
# the second time through we don't trigger another call back
|
| 206 |
+
# into the import system and cause a infinite loop.
|
| 207 |
+
|
| 208 |
+
if fullname in self.in_progress:
|
| 209 |
+
return None
|
| 210 |
+
|
| 211 |
+
self.in_progress[fullname] = True
|
| 212 |
+
|
| 213 |
+
# Now call back into the import system again.
|
| 214 |
+
|
| 215 |
+
try:
|
| 216 |
+
if not find_spec:
|
| 217 |
+
# For Python 2 we don't have much choice but to
|
| 218 |
+
# call back in to __import__(). This will
|
| 219 |
+
# actually cause the module to be imported. If no
|
| 220 |
+
# module could be found then ImportError will be
|
| 221 |
+
# raised. Otherwise we return a loader which
|
| 222 |
+
# returns the already loaded module and invokes
|
| 223 |
+
# the post import hooks.
|
| 224 |
+
|
| 225 |
+
__import__(fullname)
|
| 226 |
+
|
| 227 |
+
return _ImportHookLoader()
|
| 228 |
+
|
| 229 |
+
else:
|
| 230 |
+
# For Python 3 we need to use find_spec().loader
|
| 231 |
+
# from the importlib.util module. It doesn't actually
|
| 232 |
+
# import the target module and only finds the
|
| 233 |
+
# loader. If a loader is found, we need to return
|
| 234 |
+
# our own loader which will then in turn call the
|
| 235 |
+
# real loader to import the module and invoke the
|
| 236 |
+
# post import hooks.
|
| 237 |
+
|
| 238 |
+
loader = getattr(find_spec(fullname), "loader", None)
|
| 239 |
+
|
| 240 |
+
if loader and not isinstance(loader, _ImportHookChainedLoader):
|
| 241 |
+
return _ImportHookChainedLoader(loader)
|
| 242 |
+
|
| 243 |
+
finally:
|
| 244 |
+
del self.in_progress[fullname]
|
| 245 |
+
|
| 246 |
+
def find_spec(self, fullname, path=None, target=None):
|
| 247 |
+
# Since Python 3.4, you are meant to implement find_spec() method
|
| 248 |
+
# instead of find_module() and since Python 3.10 you get deprecation
|
| 249 |
+
# warnings if you don't define find_spec().
|
| 250 |
+
|
| 251 |
+
# If the module being imported is not one we have registered
|
| 252 |
+
# post import hooks for, we can return immediately. We will
|
| 253 |
+
# take no further part in the importing of this module.
|
| 254 |
+
|
| 255 |
+
with _post_import_hooks_lock:
|
| 256 |
+
if fullname not in _post_import_hooks:
|
| 257 |
+
return None
|
| 258 |
+
|
| 259 |
+
# When we are interested in a specific module, we will call back
|
| 260 |
+
# into the import system a second time to defer to the import
|
| 261 |
+
# finder that is supposed to handle the importing of the module.
|
| 262 |
+
# We set an in progress flag for the target module so that on
|
| 263 |
+
# the second time through we don't trigger another call back
|
| 264 |
+
# into the import system and cause a infinite loop.
|
| 265 |
+
|
| 266 |
+
if fullname in self.in_progress:
|
| 267 |
+
return None
|
| 268 |
+
|
| 269 |
+
self.in_progress[fullname] = True
|
| 270 |
+
|
| 271 |
+
# Now call back into the import system again.
|
| 272 |
+
|
| 273 |
+
try:
|
| 274 |
+
# This should only be Python 3 so find_spec() should always
|
| 275 |
+
# exist so don't need to check.
|
| 276 |
+
|
| 277 |
+
spec = find_spec(fullname)
|
| 278 |
+
loader = getattr(spec, "loader", None)
|
| 279 |
+
|
| 280 |
+
if loader and not isinstance(loader, _ImportHookChainedLoader):
|
| 281 |
+
spec.loader = _ImportHookChainedLoader(loader)
|
| 282 |
+
|
| 283 |
+
return spec
|
| 284 |
+
|
| 285 |
+
finally:
|
| 286 |
+
del self.in_progress[fullname]
|
| 287 |
+
|
| 288 |
+
# Decorator for marking that a function should be called as a post
|
| 289 |
+
# import hook when the target module is imported.
|
| 290 |
+
|
| 291 |
+
def when_imported(name):
|
| 292 |
+
def register(hook):
|
| 293 |
+
register_post_import_hook(hook, name)
|
| 294 |
+
return hook
|
| 295 |
+
return register
|
loan-advisor-agent/.venv/Lib/site-packages/wrapt/patches.py
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import inspect
|
| 2 |
+
import sys
|
| 3 |
+
|
| 4 |
+
PY2 = sys.version_info[0] == 2
|
| 5 |
+
|
| 6 |
+
if PY2:
|
| 7 |
+
string_types = basestring,
|
| 8 |
+
else:
|
| 9 |
+
string_types = str,
|
| 10 |
+
|
| 11 |
+
from .__wrapt__ import FunctionWrapper
|
| 12 |
+
|
| 13 |
+
# Helper functions for applying wrappers to existing functions.
|
| 14 |
+
|
| 15 |
+
def resolve_path(module, name):
|
| 16 |
+
if isinstance(module, string_types):
|
| 17 |
+
__import__(module)
|
| 18 |
+
module = sys.modules[module]
|
| 19 |
+
|
| 20 |
+
parent = module
|
| 21 |
+
|
| 22 |
+
path = name.split('.')
|
| 23 |
+
attribute = path[0]
|
| 24 |
+
|
| 25 |
+
# We can't just always use getattr() because in doing
|
| 26 |
+
# that on a class it will cause binding to occur which
|
| 27 |
+
# will complicate things later and cause some things not
|
| 28 |
+
# to work. For the case of a class we therefore access
|
| 29 |
+
# the __dict__ directly. To cope though with the wrong
|
| 30 |
+
# class being given to us, or a method being moved into
|
| 31 |
+
# a base class, we need to walk the class hierarchy to
|
| 32 |
+
# work out exactly which __dict__ the method was defined
|
| 33 |
+
# in, as accessing it from __dict__ will fail if it was
|
| 34 |
+
# not actually on the class given. Fallback to using
|
| 35 |
+
# getattr() if we can't find it. If it truly doesn't
|
| 36 |
+
# exist, then that will fail.
|
| 37 |
+
|
| 38 |
+
def lookup_attribute(parent, attribute):
|
| 39 |
+
if inspect.isclass(parent):
|
| 40 |
+
for cls in inspect.getmro(parent):
|
| 41 |
+
if attribute in vars(cls):
|
| 42 |
+
return vars(cls)[attribute]
|
| 43 |
+
else:
|
| 44 |
+
return getattr(parent, attribute)
|
| 45 |
+
else:
|
| 46 |
+
return getattr(parent, attribute)
|
| 47 |
+
|
| 48 |
+
original = lookup_attribute(parent, attribute)
|
| 49 |
+
|
| 50 |
+
for attribute in path[1:]:
|
| 51 |
+
parent = original
|
| 52 |
+
original = lookup_attribute(parent, attribute)
|
| 53 |
+
|
| 54 |
+
return (parent, attribute, original)
|
| 55 |
+
|
| 56 |
+
def apply_patch(parent, attribute, replacement):
|
| 57 |
+
setattr(parent, attribute, replacement)
|
| 58 |
+
|
| 59 |
+
def wrap_object(module, name, factory, args=(), kwargs={}):
|
| 60 |
+
(parent, attribute, original) = resolve_path(module, name)
|
| 61 |
+
wrapper = factory(original, *args, **kwargs)
|
| 62 |
+
apply_patch(parent, attribute, wrapper)
|
| 63 |
+
return wrapper
|
| 64 |
+
|
| 65 |
+
# Function for applying a proxy object to an attribute of a class
|
| 66 |
+
# instance. The wrapper works by defining an attribute of the same name
|
| 67 |
+
# on the class which is a descriptor and which intercepts access to the
|
| 68 |
+
# instance attribute. Note that this cannot be used on attributes which
|
| 69 |
+
# are themselves defined by a property object.
|
| 70 |
+
|
| 71 |
+
class AttributeWrapper(object):
|
| 72 |
+
|
| 73 |
+
def __init__(self, attribute, factory, args, kwargs):
|
| 74 |
+
self.attribute = attribute
|
| 75 |
+
self.factory = factory
|
| 76 |
+
self.args = args
|
| 77 |
+
self.kwargs = kwargs
|
| 78 |
+
|
| 79 |
+
def __get__(self, instance, owner):
|
| 80 |
+
value = instance.__dict__[self.attribute]
|
| 81 |
+
return self.factory(value, *self.args, **self.kwargs)
|
| 82 |
+
|
| 83 |
+
def __set__(self, instance, value):
|
| 84 |
+
instance.__dict__[self.attribute] = value
|
| 85 |
+
|
| 86 |
+
def __delete__(self, instance):
|
| 87 |
+
del instance.__dict__[self.attribute]
|
| 88 |
+
|
| 89 |
+
def wrap_object_attribute(module, name, factory, args=(), kwargs={}):
|
| 90 |
+
path, attribute = name.rsplit('.', 1)
|
| 91 |
+
parent = resolve_path(module, path)[2]
|
| 92 |
+
wrapper = AttributeWrapper(attribute, factory, args, kwargs)
|
| 93 |
+
apply_patch(parent, attribute, wrapper)
|
| 94 |
+
return wrapper
|
| 95 |
+
|
| 96 |
+
# Functions for creating a simple decorator using a FunctionWrapper,
|
| 97 |
+
# plus short cut functions for applying wrappers to functions. These are
|
| 98 |
+
# for use when doing monkey patching. For a more featured way of
|
| 99 |
+
# creating decorators see the decorator decorator instead.
|
| 100 |
+
|
| 101 |
+
def function_wrapper(wrapper):
|
| 102 |
+
def _wrapper(wrapped, instance, args, kwargs):
|
| 103 |
+
target_wrapped = args[0]
|
| 104 |
+
if instance is None:
|
| 105 |
+
target_wrapper = wrapper
|
| 106 |
+
elif inspect.isclass(instance):
|
| 107 |
+
target_wrapper = wrapper.__get__(None, instance)
|
| 108 |
+
else:
|
| 109 |
+
target_wrapper = wrapper.__get__(instance, type(instance))
|
| 110 |
+
return FunctionWrapper(target_wrapped, target_wrapper)
|
| 111 |
+
return FunctionWrapper(wrapper, _wrapper)
|
| 112 |
+
|
| 113 |
+
def wrap_function_wrapper(module, name, wrapper):
|
| 114 |
+
return wrap_object(module, name, FunctionWrapper, (wrapper,))
|
| 115 |
+
|
| 116 |
+
def patch_function_wrapper(module, name, enabled=None):
|
| 117 |
+
def _wrapper(wrapper):
|
| 118 |
+
return wrap_object(module, name, FunctionWrapper, (wrapper, enabled))
|
| 119 |
+
return _wrapper
|
| 120 |
+
|
| 121 |
+
def transient_function_wrapper(module, name):
|
| 122 |
+
def _decorator(wrapper):
|
| 123 |
+
def _wrapper(wrapped, instance, args, kwargs):
|
| 124 |
+
target_wrapped = args[0]
|
| 125 |
+
if instance is None:
|
| 126 |
+
target_wrapper = wrapper
|
| 127 |
+
elif inspect.isclass(instance):
|
| 128 |
+
target_wrapper = wrapper.__get__(None, instance)
|
| 129 |
+
else:
|
| 130 |
+
target_wrapper = wrapper.__get__(instance, type(instance))
|
| 131 |
+
def _execute(wrapped, instance, args, kwargs):
|
| 132 |
+
(parent, attribute, original) = resolve_path(module, name)
|
| 133 |
+
replacement = FunctionWrapper(original, target_wrapper)
|
| 134 |
+
setattr(parent, attribute, replacement)
|
| 135 |
+
try:
|
| 136 |
+
return wrapped(*args, **kwargs)
|
| 137 |
+
finally:
|
| 138 |
+
setattr(parent, attribute, original)
|
| 139 |
+
return FunctionWrapper(target_wrapped, _execute)
|
| 140 |
+
return FunctionWrapper(wrapper, _wrapper)
|
| 141 |
+
return _decorator
|
loan-advisor-agent/.venv/Lib/site-packages/wrapt/weakrefs.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import functools
|
| 2 |
+
import weakref
|
| 3 |
+
|
| 4 |
+
from .__wrapt__ import ObjectProxy, _FunctionWrapperBase
|
| 5 |
+
|
| 6 |
+
# A weak function proxy. This will work on instance methods, class
|
| 7 |
+
# methods, static methods and regular functions. Special treatment is
|
| 8 |
+
# needed for the method types because the bound method is effectively a
|
| 9 |
+
# transient object and applying a weak reference to one will immediately
|
| 10 |
+
# result in it being destroyed and the weakref callback called. The weak
|
| 11 |
+
# reference is therefore applied to the instance the method is bound to
|
| 12 |
+
# and the original function. The function is then rebound at the point
|
| 13 |
+
# of a call via the weak function proxy.
|
| 14 |
+
|
| 15 |
+
def _weak_function_proxy_callback(ref, proxy, callback):
|
| 16 |
+
if proxy._self_expired:
|
| 17 |
+
return
|
| 18 |
+
|
| 19 |
+
proxy._self_expired = True
|
| 20 |
+
|
| 21 |
+
# This could raise an exception. We let it propagate back and let
|
| 22 |
+
# the weakref.proxy() deal with it, at which point it generally
|
| 23 |
+
# prints out a short error message direct to stderr and keeps going.
|
| 24 |
+
|
| 25 |
+
if callback is not None:
|
| 26 |
+
callback(proxy)
|
| 27 |
+
|
| 28 |
+
class WeakFunctionProxy(ObjectProxy):
|
| 29 |
+
|
| 30 |
+
__slots__ = ('_self_expired', '_self_instance')
|
| 31 |
+
|
| 32 |
+
def __init__(self, wrapped, callback=None):
|
| 33 |
+
# We need to determine if the wrapped function is actually a
|
| 34 |
+
# bound method. In the case of a bound method, we need to keep a
|
| 35 |
+
# reference to the original unbound function and the instance.
|
| 36 |
+
# This is necessary because if we hold a reference to the bound
|
| 37 |
+
# function, it will be the only reference and given it is a
|
| 38 |
+
# temporary object, it will almost immediately expire and
|
| 39 |
+
# the weakref callback triggered. So what is done is that we
|
| 40 |
+
# hold a reference to the instance and unbound function and
|
| 41 |
+
# when called bind the function to the instance once again and
|
| 42 |
+
# then call it. Note that we avoid using a nested function for
|
| 43 |
+
# the callback here so as not to cause any odd reference cycles.
|
| 44 |
+
|
| 45 |
+
_callback = callback and functools.partial(
|
| 46 |
+
_weak_function_proxy_callback, proxy=self,
|
| 47 |
+
callback=callback)
|
| 48 |
+
|
| 49 |
+
self._self_expired = False
|
| 50 |
+
|
| 51 |
+
if isinstance(wrapped, _FunctionWrapperBase):
|
| 52 |
+
self._self_instance = weakref.ref(wrapped._self_instance,
|
| 53 |
+
_callback)
|
| 54 |
+
|
| 55 |
+
if wrapped._self_parent is not None:
|
| 56 |
+
super(WeakFunctionProxy, self).__init__(
|
| 57 |
+
weakref.proxy(wrapped._self_parent, _callback))
|
| 58 |
+
|
| 59 |
+
else:
|
| 60 |
+
super(WeakFunctionProxy, self).__init__(
|
| 61 |
+
weakref.proxy(wrapped, _callback))
|
| 62 |
+
|
| 63 |
+
return
|
| 64 |
+
|
| 65 |
+
try:
|
| 66 |
+
self._self_instance = weakref.ref(wrapped.__self__, _callback)
|
| 67 |
+
|
| 68 |
+
super(WeakFunctionProxy, self).__init__(
|
| 69 |
+
weakref.proxy(wrapped.__func__, _callback))
|
| 70 |
+
|
| 71 |
+
except AttributeError:
|
| 72 |
+
self._self_instance = None
|
| 73 |
+
|
| 74 |
+
super(WeakFunctionProxy, self).__init__(
|
| 75 |
+
weakref.proxy(wrapped, _callback))
|
| 76 |
+
|
| 77 |
+
def __call__(*args, **kwargs):
|
| 78 |
+
def _unpack_self(self, *args):
|
| 79 |
+
return self, args
|
| 80 |
+
|
| 81 |
+
self, args = _unpack_self(*args)
|
| 82 |
+
|
| 83 |
+
# We perform a boolean check here on the instance and wrapped
|
| 84 |
+
# function as that will trigger the reference error prior to
|
| 85 |
+
# calling if the reference had expired.
|
| 86 |
+
|
| 87 |
+
instance = self._self_instance and self._self_instance()
|
| 88 |
+
function = self.__wrapped__ and self.__wrapped__
|
| 89 |
+
|
| 90 |
+
# If the wrapped function was originally a bound function, for
|
| 91 |
+
# which we retained a reference to the instance and the unbound
|
| 92 |
+
# function we need to rebind the function and then call it. If
|
| 93 |
+
# not just called the wrapped function.
|
| 94 |
+
|
| 95 |
+
if instance is None:
|
| 96 |
+
return self.__wrapped__(*args, **kwargs)
|
| 97 |
+
|
| 98 |
+
return function.__get__(instance, type(instance))(*args, **kwargs)
|
loan-advisor-agent/.venv/Lib/site-packages/wrapt/wrappers.py
ADDED
|
@@ -0,0 +1,821 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
| 1 |
+
import sys
|
| 2 |
+
import operator
|
| 3 |
+
import inspect
|
| 4 |
+
|
| 5 |
+
PY2 = sys.version_info[0] == 2
|
| 6 |
+
|
| 7 |
+
if PY2:
|
| 8 |
+
string_types = basestring,
|
| 9 |
+
else:
|
| 10 |
+
string_types = str,
|
| 11 |
+
|
| 12 |
+
def with_metaclass(meta, *bases):
|
| 13 |
+
"""Create a base class with a metaclass."""
|
| 14 |
+
return meta("NewBase", bases, {})
|
| 15 |
+
|
| 16 |
+
class _ObjectProxyMethods(object):
|
| 17 |
+
|
| 18 |
+
# We use properties to override the values of __module__ and
|
| 19 |
+
# __doc__. If we add these in ObjectProxy, the derived class
|
| 20 |
+
# __dict__ will still be setup to have string variants of these
|
| 21 |
+
# attributes and the rules of descriptors means that they appear to
|
| 22 |
+
# take precedence over the properties in the base class. To avoid
|
| 23 |
+
# that, we copy the properties into the derived class type itself
|
| 24 |
+
# via a meta class. In that way the properties will always take
|
| 25 |
+
# precedence.
|
| 26 |
+
|
| 27 |
+
@property
|
| 28 |
+
def __module__(self):
|
| 29 |
+
return self.__wrapped__.__module__
|
| 30 |
+
|
| 31 |
+
@__module__.setter
|
| 32 |
+
def __module__(self, value):
|
| 33 |
+
self.__wrapped__.__module__ = value
|
| 34 |
+
|
| 35 |
+
@property
|
| 36 |
+
def __doc__(self):
|
| 37 |
+
return self.__wrapped__.__doc__
|
| 38 |
+
|
| 39 |
+
@__doc__.setter
|
| 40 |
+
def __doc__(self, value):
|
| 41 |
+
self.__wrapped__.__doc__ = value
|
| 42 |
+
|
| 43 |
+
# We similar use a property for __dict__. We need __dict__ to be
|
| 44 |
+
# explicit to ensure that vars() works as expected.
|
| 45 |
+
|
| 46 |
+
@property
|
| 47 |
+
def __dict__(self):
|
| 48 |
+
return self.__wrapped__.__dict__
|
| 49 |
+
|
| 50 |
+
# Need to also propagate the special __weakref__ attribute for case
|
| 51 |
+
# where decorating classes which will define this. If do not define
|
| 52 |
+
# it and use a function like inspect.getmembers() on a decorator
|
| 53 |
+
# class it will fail. This can't be in the derived classes.
|
| 54 |
+
|
| 55 |
+
@property
|
| 56 |
+
def __weakref__(self):
|
| 57 |
+
return self.__wrapped__.__weakref__
|
| 58 |
+
|
| 59 |
+
class _ObjectProxyMetaType(type):
|
| 60 |
+
def __new__(cls, name, bases, dictionary):
|
| 61 |
+
# Copy our special properties into the class so that they
|
| 62 |
+
# always take precedence over attributes of the same name added
|
| 63 |
+
# during construction of a derived class. This is to save
|
| 64 |
+
# duplicating the implementation for them in all derived classes.
|
| 65 |
+
|
| 66 |
+
dictionary.update(vars(_ObjectProxyMethods))
|
| 67 |
+
|
| 68 |
+
return type.__new__(cls, name, bases, dictionary)
|
| 69 |
+
|
| 70 |
+
class ObjectProxy(with_metaclass(_ObjectProxyMetaType)):
|
| 71 |
+
|
| 72 |
+
__slots__ = '__wrapped__'
|
| 73 |
+
|
| 74 |
+
def __init__(self, wrapped):
|
| 75 |
+
object.__setattr__(self, '__wrapped__', wrapped)
|
| 76 |
+
|
| 77 |
+
# Python 3.2+ has the __qualname__ attribute, but it does not
|
| 78 |
+
# allow it to be overridden using a property and it must instead
|
| 79 |
+
# be an actual string object instead.
|
| 80 |
+
|
| 81 |
+
try:
|
| 82 |
+
object.__setattr__(self, '__qualname__', wrapped.__qualname__)
|
| 83 |
+
except AttributeError:
|
| 84 |
+
pass
|
| 85 |
+
|
| 86 |
+
# Python 3.10 onwards also does not allow itself to be overridden
|
| 87 |
+
# using a property and it must instead be set explicitly.
|
| 88 |
+
|
| 89 |
+
try:
|
| 90 |
+
object.__setattr__(self, '__annotations__', wrapped.__annotations__)
|
| 91 |
+
except AttributeError:
|
| 92 |
+
pass
|
| 93 |
+
|
| 94 |
+
def __self_setattr__(self, name, value):
|
| 95 |
+
object.__setattr__(self, name, value)
|
| 96 |
+
|
| 97 |
+
@property
|
| 98 |
+
def __name__(self):
|
| 99 |
+
return self.__wrapped__.__name__
|
| 100 |
+
|
| 101 |
+
@__name__.setter
|
| 102 |
+
def __name__(self, value):
|
| 103 |
+
self.__wrapped__.__name__ = value
|
| 104 |
+
|
| 105 |
+
@property
|
| 106 |
+
def __class__(self):
|
| 107 |
+
return self.__wrapped__.__class__
|
| 108 |
+
|
| 109 |
+
@__class__.setter
|
| 110 |
+
def __class__(self, value):
|
| 111 |
+
self.__wrapped__.__class__ = value
|
| 112 |
+
|
| 113 |
+
def __dir__(self):
|
| 114 |
+
return dir(self.__wrapped__)
|
| 115 |
+
|
| 116 |
+
def __str__(self):
|
| 117 |
+
return str(self.__wrapped__)
|
| 118 |
+
|
| 119 |
+
if not PY2:
|
| 120 |
+
def __bytes__(self):
|
| 121 |
+
return bytes(self.__wrapped__)
|
| 122 |
+
|
| 123 |
+
def __repr__(self):
|
| 124 |
+
return '<{} at 0x{:x} for {} at 0x{:x}>'.format(
|
| 125 |
+
type(self).__name__, id(self),
|
| 126 |
+
type(self.__wrapped__).__name__,
|
| 127 |
+
id(self.__wrapped__))
|
| 128 |
+
|
| 129 |
+
def __format__(self, format_spec):
|
| 130 |
+
return format(self.__wrapped__, format_spec)
|
| 131 |
+
|
| 132 |
+
def __reversed__(self):
|
| 133 |
+
return reversed(self.__wrapped__)
|
| 134 |
+
|
| 135 |
+
if not PY2:
|
| 136 |
+
def __round__(self, ndigits=None):
|
| 137 |
+
return round(self.__wrapped__, ndigits)
|
| 138 |
+
|
| 139 |
+
if sys.hexversion >= 0x03070000:
|
| 140 |
+
def __mro_entries__(self, bases):
|
| 141 |
+
return (self.__wrapped__,)
|
| 142 |
+
|
| 143 |
+
def __lt__(self, other):
|
| 144 |
+
return self.__wrapped__ < other
|
| 145 |
+
|
| 146 |
+
def __le__(self, other):
|
| 147 |
+
return self.__wrapped__ <= other
|
| 148 |
+
|
| 149 |
+
def __eq__(self, other):
|
| 150 |
+
return self.__wrapped__ == other
|
| 151 |
+
|
| 152 |
+
def __ne__(self, other):
|
| 153 |
+
return self.__wrapped__ != other
|
| 154 |
+
|
| 155 |
+
def __gt__(self, other):
|
| 156 |
+
return self.__wrapped__ > other
|
| 157 |
+
|
| 158 |
+
def __ge__(self, other):
|
| 159 |
+
return self.__wrapped__ >= other
|
| 160 |
+
|
| 161 |
+
def __hash__(self):
|
| 162 |
+
return hash(self.__wrapped__)
|
| 163 |
+
|
| 164 |
+
def __nonzero__(self):
|
| 165 |
+
return bool(self.__wrapped__)
|
| 166 |
+
|
| 167 |
+
def __bool__(self):
|
| 168 |
+
return bool(self.__wrapped__)
|
| 169 |
+
|
| 170 |
+
def __setattr__(self, name, value):
|
| 171 |
+
if name.startswith('_self_'):
|
| 172 |
+
object.__setattr__(self, name, value)
|
| 173 |
+
|
| 174 |
+
elif name == '__wrapped__':
|
| 175 |
+
object.__setattr__(self, name, value)
|
| 176 |
+
try:
|
| 177 |
+
object.__delattr__(self, '__qualname__')
|
| 178 |
+
except AttributeError:
|
| 179 |
+
pass
|
| 180 |
+
try:
|
| 181 |
+
object.__setattr__(self, '__qualname__', value.__qualname__)
|
| 182 |
+
except AttributeError:
|
| 183 |
+
pass
|
| 184 |
+
try:
|
| 185 |
+
object.__delattr__(self, '__annotations__')
|
| 186 |
+
except AttributeError:
|
| 187 |
+
pass
|
| 188 |
+
try:
|
| 189 |
+
object.__setattr__(self, '__annotations__', value.__annotations__)
|
| 190 |
+
except AttributeError:
|
| 191 |
+
pass
|
| 192 |
+
|
| 193 |
+
elif name == '__qualname__':
|
| 194 |
+
setattr(self.__wrapped__, name, value)
|
| 195 |
+
object.__setattr__(self, name, value)
|
| 196 |
+
|
| 197 |
+
elif name == '__annotations__':
|
| 198 |
+
setattr(self.__wrapped__, name, value)
|
| 199 |
+
object.__setattr__(self, name, value)
|
| 200 |
+
|
| 201 |
+
elif hasattr(type(self), name):
|
| 202 |
+
object.__setattr__(self, name, value)
|
| 203 |
+
|
| 204 |
+
else:
|
| 205 |
+
setattr(self.__wrapped__, name, value)
|
| 206 |
+
|
| 207 |
+
def __getattr__(self, name):
|
| 208 |
+
# If we are being to lookup '__wrapped__' then the
|
| 209 |
+
# '__init__()' method cannot have been called.
|
| 210 |
+
|
| 211 |
+
if name == '__wrapped__':
|
| 212 |
+
raise ValueError('wrapper has not been initialised')
|
| 213 |
+
|
| 214 |
+
return getattr(self.__wrapped__, name)
|
| 215 |
+
|
| 216 |
+
def __delattr__(self, name):
|
| 217 |
+
if name.startswith('_self_'):
|
| 218 |
+
object.__delattr__(self, name)
|
| 219 |
+
|
| 220 |
+
elif name == '__wrapped__':
|
| 221 |
+
raise TypeError('__wrapped__ must be an object')
|
| 222 |
+
|
| 223 |
+
elif name == '__qualname__':
|
| 224 |
+
object.__delattr__(self, name)
|
| 225 |
+
delattr(self.__wrapped__, name)
|
| 226 |
+
|
| 227 |
+
elif hasattr(type(self), name):
|
| 228 |
+
object.__delattr__(self, name)
|
| 229 |
+
|
| 230 |
+
else:
|
| 231 |
+
delattr(self.__wrapped__, name)
|
| 232 |
+
|
| 233 |
+
def __add__(self, other):
|
| 234 |
+
return self.__wrapped__ + other
|
| 235 |
+
|
| 236 |
+
def __sub__(self, other):
|
| 237 |
+
return self.__wrapped__ - other
|
| 238 |
+
|
| 239 |
+
def __mul__(self, other):
|
| 240 |
+
return self.__wrapped__ * other
|
| 241 |
+
|
| 242 |
+
def __div__(self, other):
|
| 243 |
+
return operator.div(self.__wrapped__, other)
|
| 244 |
+
|
| 245 |
+
def __truediv__(self, other):
|
| 246 |
+
return operator.truediv(self.__wrapped__, other)
|
| 247 |
+
|
| 248 |
+
def __floordiv__(self, other):
|
| 249 |
+
return self.__wrapped__ // other
|
| 250 |
+
|
| 251 |
+
def __mod__(self, other):
|
| 252 |
+
return self.__wrapped__ % other
|
| 253 |
+
|
| 254 |
+
def __divmod__(self, other):
|
| 255 |
+
return divmod(self.__wrapped__, other)
|
| 256 |
+
|
| 257 |
+
def __pow__(self, other, *args):
|
| 258 |
+
return pow(self.__wrapped__, other, *args)
|
| 259 |
+
|
| 260 |
+
def __lshift__(self, other):
|
| 261 |
+
return self.__wrapped__ << other
|
| 262 |
+
|
| 263 |
+
def __rshift__(self, other):
|
| 264 |
+
return self.__wrapped__ >> other
|
| 265 |
+
|
| 266 |
+
def __and__(self, other):
|
| 267 |
+
return self.__wrapped__ & other
|
| 268 |
+
|
| 269 |
+
def __xor__(self, other):
|
| 270 |
+
return self.__wrapped__ ^ other
|
| 271 |
+
|
| 272 |
+
def __or__(self, other):
|
| 273 |
+
return self.__wrapped__ | other
|
| 274 |
+
|
| 275 |
+
def __radd__(self, other):
|
| 276 |
+
return other + self.__wrapped__
|
| 277 |
+
|
| 278 |
+
def __rsub__(self, other):
|
| 279 |
+
return other - self.__wrapped__
|
| 280 |
+
|
| 281 |
+
def __rmul__(self, other):
|
| 282 |
+
return other * self.__wrapped__
|
| 283 |
+
|
| 284 |
+
def __rdiv__(self, other):
|
| 285 |
+
return operator.div(other, self.__wrapped__)
|
| 286 |
+
|
| 287 |
+
def __rtruediv__(self, other):
|
| 288 |
+
return operator.truediv(other, self.__wrapped__)
|
| 289 |
+
|
| 290 |
+
def __rfloordiv__(self, other):
|
| 291 |
+
return other // self.__wrapped__
|
| 292 |
+
|
| 293 |
+
def __rmod__(self, other):
|
| 294 |
+
return other % self.__wrapped__
|
| 295 |
+
|
| 296 |
+
def __rdivmod__(self, other):
|
| 297 |
+
return divmod(other, self.__wrapped__)
|
| 298 |
+
|
| 299 |
+
def __rpow__(self, other, *args):
|
| 300 |
+
return pow(other, self.__wrapped__, *args)
|
| 301 |
+
|
| 302 |
+
def __rlshift__(self, other):
|
| 303 |
+
return other << self.__wrapped__
|
| 304 |
+
|
| 305 |
+
def __rrshift__(self, other):
|
| 306 |
+
return other >> self.__wrapped__
|
| 307 |
+
|
| 308 |
+
def __rand__(self, other):
|
| 309 |
+
return other & self.__wrapped__
|
| 310 |
+
|
| 311 |
+
def __rxor__(self, other):
|
| 312 |
+
return other ^ self.__wrapped__
|
| 313 |
+
|
| 314 |
+
def __ror__(self, other):
|
| 315 |
+
return other | self.__wrapped__
|
| 316 |
+
|
| 317 |
+
def __iadd__(self, other):
|
| 318 |
+
self.__wrapped__ += other
|
| 319 |
+
return self
|
| 320 |
+
|
| 321 |
+
def __isub__(self, other):
|
| 322 |
+
self.__wrapped__ -= other
|
| 323 |
+
return self
|
| 324 |
+
|
| 325 |
+
def __imul__(self, other):
|
| 326 |
+
self.__wrapped__ *= other
|
| 327 |
+
return self
|
| 328 |
+
|
| 329 |
+
def __idiv__(self, other):
|
| 330 |
+
self.__wrapped__ = operator.idiv(self.__wrapped__, other)
|
| 331 |
+
return self
|
| 332 |
+
|
| 333 |
+
def __itruediv__(self, other):
|
| 334 |
+
self.__wrapped__ = operator.itruediv(self.__wrapped__, other)
|
| 335 |
+
return self
|
| 336 |
+
|
| 337 |
+
def __ifloordiv__(self, other):
|
| 338 |
+
self.__wrapped__ //= other
|
| 339 |
+
return self
|
| 340 |
+
|
| 341 |
+
def __imod__(self, other):
|
| 342 |
+
self.__wrapped__ %= other
|
| 343 |
+
return self
|
| 344 |
+
|
| 345 |
+
def __ipow__(self, other):
|
| 346 |
+
self.__wrapped__ **= other
|
| 347 |
+
return self
|
| 348 |
+
|
| 349 |
+
def __ilshift__(self, other):
|
| 350 |
+
self.__wrapped__ <<= other
|
| 351 |
+
return self
|
| 352 |
+
|
| 353 |
+
def __irshift__(self, other):
|
| 354 |
+
self.__wrapped__ >>= other
|
| 355 |
+
return self
|
| 356 |
+
|
| 357 |
+
def __iand__(self, other):
|
| 358 |
+
self.__wrapped__ &= other
|
| 359 |
+
return self
|
| 360 |
+
|
| 361 |
+
def __ixor__(self, other):
|
| 362 |
+
self.__wrapped__ ^= other
|
| 363 |
+
return self
|
| 364 |
+
|
| 365 |
+
def __ior__(self, other):
|
| 366 |
+
self.__wrapped__ |= other
|
| 367 |
+
return self
|
| 368 |
+
|
| 369 |
+
def __neg__(self):
|
| 370 |
+
return -self.__wrapped__
|
| 371 |
+
|
| 372 |
+
def __pos__(self):
|
| 373 |
+
return +self.__wrapped__
|
| 374 |
+
|
| 375 |
+
def __abs__(self):
|
| 376 |
+
return abs(self.__wrapped__)
|
| 377 |
+
|
| 378 |
+
def __invert__(self):
|
| 379 |
+
return ~self.__wrapped__
|
| 380 |
+
|
| 381 |
+
def __int__(self):
|
| 382 |
+
return int(self.__wrapped__)
|
| 383 |
+
|
| 384 |
+
def __long__(self):
|
| 385 |
+
return long(self.__wrapped__)
|
| 386 |
+
|
| 387 |
+
def __float__(self):
|
| 388 |
+
return float(self.__wrapped__)
|
| 389 |
+
|
| 390 |
+
def __complex__(self):
|
| 391 |
+
return complex(self.__wrapped__)
|
| 392 |
+
|
| 393 |
+
def __oct__(self):
|
| 394 |
+
return oct(self.__wrapped__)
|
| 395 |
+
|
| 396 |
+
def __hex__(self):
|
| 397 |
+
return hex(self.__wrapped__)
|
| 398 |
+
|
| 399 |
+
def __index__(self):
|
| 400 |
+
return operator.index(self.__wrapped__)
|
| 401 |
+
|
| 402 |
+
def __len__(self):
|
| 403 |
+
return len(self.__wrapped__)
|
| 404 |
+
|
| 405 |
+
def __contains__(self, value):
|
| 406 |
+
return value in self.__wrapped__
|
| 407 |
+
|
| 408 |
+
def __getitem__(self, key):
|
| 409 |
+
return self.__wrapped__[key]
|
| 410 |
+
|
| 411 |
+
def __setitem__(self, key, value):
|
| 412 |
+
self.__wrapped__[key] = value
|
| 413 |
+
|
| 414 |
+
def __delitem__(self, key):
|
| 415 |
+
del self.__wrapped__[key]
|
| 416 |
+
|
| 417 |
+
def __getslice__(self, i, j):
|
| 418 |
+
return self.__wrapped__[i:j]
|
| 419 |
+
|
| 420 |
+
def __setslice__(self, i, j, value):
|
| 421 |
+
self.__wrapped__[i:j] = value
|
| 422 |
+
|
| 423 |
+
def __delslice__(self, i, j):
|
| 424 |
+
del self.__wrapped__[i:j]
|
| 425 |
+
|
| 426 |
+
def __enter__(self):
|
| 427 |
+
return self.__wrapped__.__enter__()
|
| 428 |
+
|
| 429 |
+
def __exit__(self, *args, **kwargs):
|
| 430 |
+
return self.__wrapped__.__exit__(*args, **kwargs)
|
| 431 |
+
|
| 432 |
+
def __iter__(self):
|
| 433 |
+
return iter(self.__wrapped__)
|
| 434 |
+
|
| 435 |
+
def __copy__(self):
|
| 436 |
+
raise NotImplementedError('object proxy must define __copy__()')
|
| 437 |
+
|
| 438 |
+
def __deepcopy__(self, memo):
|
| 439 |
+
raise NotImplementedError('object proxy must define __deepcopy__()')
|
| 440 |
+
|
| 441 |
+
def __reduce__(self):
|
| 442 |
+
raise NotImplementedError(
|
| 443 |
+
'object proxy must define __reduce__()')
|
| 444 |
+
|
| 445 |
+
def __reduce_ex__(self, protocol):
|
| 446 |
+
raise NotImplementedError(
|
| 447 |
+
'object proxy must define __reduce_ex__()')
|
| 448 |
+
|
| 449 |
+
class CallableObjectProxy(ObjectProxy):
|
| 450 |
+
|
| 451 |
+
def __call__(*args, **kwargs):
|
| 452 |
+
def _unpack_self(self, *args):
|
| 453 |
+
return self, args
|
| 454 |
+
|
| 455 |
+
self, args = _unpack_self(*args)
|
| 456 |
+
|
| 457 |
+
return self.__wrapped__(*args, **kwargs)
|
| 458 |
+
|
| 459 |
+
class PartialCallableObjectProxy(ObjectProxy):
|
| 460 |
+
|
| 461 |
+
def __init__(*args, **kwargs):
|
| 462 |
+
def _unpack_self(self, *args):
|
| 463 |
+
return self, args
|
| 464 |
+
|
| 465 |
+
self, args = _unpack_self(*args)
|
| 466 |
+
|
| 467 |
+
if len(args) < 1:
|
| 468 |
+
raise TypeError('partial type takes at least one argument')
|
| 469 |
+
|
| 470 |
+
wrapped, args = args[0], args[1:]
|
| 471 |
+
|
| 472 |
+
if not callable(wrapped):
|
| 473 |
+
raise TypeError('the first argument must be callable')
|
| 474 |
+
|
| 475 |
+
super(PartialCallableObjectProxy, self).__init__(wrapped)
|
| 476 |
+
|
| 477 |
+
self._self_args = args
|
| 478 |
+
self._self_kwargs = kwargs
|
| 479 |
+
|
| 480 |
+
def __call__(*args, **kwargs):
|
| 481 |
+
def _unpack_self(self, *args):
|
| 482 |
+
return self, args
|
| 483 |
+
|
| 484 |
+
self, args = _unpack_self(*args)
|
| 485 |
+
|
| 486 |
+
_args = self._self_args + args
|
| 487 |
+
|
| 488 |
+
_kwargs = dict(self._self_kwargs)
|
| 489 |
+
_kwargs.update(kwargs)
|
| 490 |
+
|
| 491 |
+
return self.__wrapped__(*_args, **_kwargs)
|
| 492 |
+
|
| 493 |
+
class _FunctionWrapperBase(ObjectProxy):
|
| 494 |
+
|
| 495 |
+
__slots__ = ('_self_instance', '_self_wrapper', '_self_enabled',
|
| 496 |
+
'_self_binding', '_self_parent', '_self_owner')
|
| 497 |
+
|
| 498 |
+
def __init__(self, wrapped, instance, wrapper, enabled=None,
|
| 499 |
+
binding='callable', parent=None, owner=None):
|
| 500 |
+
|
| 501 |
+
super(_FunctionWrapperBase, self).__init__(wrapped)
|
| 502 |
+
|
| 503 |
+
object.__setattr__(self, '_self_instance', instance)
|
| 504 |
+
object.__setattr__(self, '_self_wrapper', wrapper)
|
| 505 |
+
object.__setattr__(self, '_self_enabled', enabled)
|
| 506 |
+
object.__setattr__(self, '_self_binding', binding)
|
| 507 |
+
object.__setattr__(self, '_self_parent', parent)
|
| 508 |
+
object.__setattr__(self, '_self_owner', owner)
|
| 509 |
+
|
| 510 |
+
def __get__(self, instance, owner):
|
| 511 |
+
# This method is actually doing double duty for both unbound and bound
|
| 512 |
+
# derived wrapper classes. It should possibly be broken up and the
|
| 513 |
+
# distinct functionality moved into the derived classes. Can't do that
|
| 514 |
+
# straight away due to some legacy code which is relying on it being
|
| 515 |
+
# here in this base class.
|
| 516 |
+
#
|
| 517 |
+
# The distinguishing attribute which determines whether we are being
|
| 518 |
+
# called in an unbound or bound wrapper is the parent attribute. If
|
| 519 |
+
# binding has never occurred, then the parent will be None.
|
| 520 |
+
#
|
| 521 |
+
# First therefore, is if we are called in an unbound wrapper. In this
|
| 522 |
+
# case we perform the binding.
|
| 523 |
+
#
|
| 524 |
+
# We have two special cases to worry about here. These are where we are
|
| 525 |
+
# decorating a class or builtin function as neither provide a __get__()
|
| 526 |
+
# method to call. In this case we simply return self.
|
| 527 |
+
#
|
| 528 |
+
# Note that we otherwise still do binding even if instance is None and
|
| 529 |
+
# accessing an unbound instance method from a class. This is because we
|
| 530 |
+
# need to be able to later detect that specific case as we will need to
|
| 531 |
+
# extract the instance from the first argument of those passed in.
|
| 532 |
+
|
| 533 |
+
if self._self_parent is None:
|
| 534 |
+
# Technically can probably just check for existence of __get__ on
|
| 535 |
+
# the wrapped object, but this is more explicit.
|
| 536 |
+
|
| 537 |
+
if self._self_binding == 'builtin':
|
| 538 |
+
return self
|
| 539 |
+
|
| 540 |
+
if self._self_binding == "class":
|
| 541 |
+
return self
|
| 542 |
+
|
| 543 |
+
binder = getattr(self.__wrapped__, '__get__', None)
|
| 544 |
+
|
| 545 |
+
if binder is None:
|
| 546 |
+
return self
|
| 547 |
+
|
| 548 |
+
descriptor = binder(instance, owner)
|
| 549 |
+
|
| 550 |
+
return self.__bound_function_wrapper__(descriptor, instance,
|
| 551 |
+
self._self_wrapper, self._self_enabled,
|
| 552 |
+
self._self_binding, self, owner)
|
| 553 |
+
|
| 554 |
+
# Now we have the case of binding occurring a second time on what was
|
| 555 |
+
# already a bound function. In this case we would usually return
|
| 556 |
+
# ourselves again. This mirrors what Python does.
|
| 557 |
+
#
|
| 558 |
+
# The special case this time is where we were originally bound with an
|
| 559 |
+
# instance of None and we were likely an instance method. In that case
|
| 560 |
+
# we rebind against the original wrapped function from the parent again.
|
| 561 |
+
|
| 562 |
+
if self._self_instance is None and self._self_binding in ('function', 'instancemethod', 'callable'):
|
| 563 |
+
descriptor = self._self_parent.__wrapped__.__get__(
|
| 564 |
+
instance, owner)
|
| 565 |
+
|
| 566 |
+
return self._self_parent.__bound_function_wrapper__(
|
| 567 |
+
descriptor, instance, self._self_wrapper,
|
| 568 |
+
self._self_enabled, self._self_binding,
|
| 569 |
+
self._self_parent, owner)
|
| 570 |
+
|
| 571 |
+
return self
|
| 572 |
+
|
| 573 |
+
def __call__(*args, **kwargs):
|
| 574 |
+
def _unpack_self(self, *args):
|
| 575 |
+
return self, args
|
| 576 |
+
|
| 577 |
+
self, args = _unpack_self(*args)
|
| 578 |
+
|
| 579 |
+
# If enabled has been specified, then evaluate it at this point
|
| 580 |
+
# and if the wrapper is not to be executed, then simply return
|
| 581 |
+
# the bound function rather than a bound wrapper for the bound
|
| 582 |
+
# function. When evaluating enabled, if it is callable we call
|
| 583 |
+
# it, otherwise we evaluate it as a boolean.
|
| 584 |
+
|
| 585 |
+
if self._self_enabled is not None:
|
| 586 |
+
if callable(self._self_enabled):
|
| 587 |
+
if not self._self_enabled():
|
| 588 |
+
return self.__wrapped__(*args, **kwargs)
|
| 589 |
+
elif not self._self_enabled:
|
| 590 |
+
return self.__wrapped__(*args, **kwargs)
|
| 591 |
+
|
| 592 |
+
# This can occur where initial function wrapper was applied to
|
| 593 |
+
# a function that was already bound to an instance. In that case
|
| 594 |
+
# we want to extract the instance from the function and use it.
|
| 595 |
+
|
| 596 |
+
if self._self_binding in ('function', 'instancemethod', 'classmethod', 'callable'):
|
| 597 |
+
if self._self_instance is None:
|
| 598 |
+
instance = getattr(self.__wrapped__, '__self__', None)
|
| 599 |
+
if instance is not None:
|
| 600 |
+
return self._self_wrapper(self.__wrapped__, instance,
|
| 601 |
+
args, kwargs)
|
| 602 |
+
|
| 603 |
+
# This is generally invoked when the wrapped function is being
|
| 604 |
+
# called as a normal function and is not bound to a class as an
|
| 605 |
+
# instance method. This is also invoked in the case where the
|
| 606 |
+
# wrapped function was a method, but this wrapper was in turn
|
| 607 |
+
# wrapped using the staticmethod decorator.
|
| 608 |
+
|
| 609 |
+
return self._self_wrapper(self.__wrapped__, self._self_instance,
|
| 610 |
+
args, kwargs)
|
| 611 |
+
|
| 612 |
+
def __set_name__(self, owner, name):
|
| 613 |
+
# This is a special method use to supply information to
|
| 614 |
+
# descriptors about what the name of variable in a class
|
| 615 |
+
# definition is. Not wanting to add this to ObjectProxy as not
|
| 616 |
+
# sure of broader implications of doing that. Thus restrict to
|
| 617 |
+
# FunctionWrapper used by decorators.
|
| 618 |
+
|
| 619 |
+
if hasattr(self.__wrapped__, "__set_name__"):
|
| 620 |
+
self.__wrapped__.__set_name__(owner, name)
|
| 621 |
+
|
| 622 |
+
def __instancecheck__(self, instance):
|
| 623 |
+
# This is a special method used by isinstance() to make checks
|
| 624 |
+
# instance of the `__wrapped__`.
|
| 625 |
+
return isinstance(instance, self.__wrapped__)
|
| 626 |
+
|
| 627 |
+
def __subclasscheck__(self, subclass):
|
| 628 |
+
# This is a special method used by issubclass() to make checks
|
| 629 |
+
# about inheritance of classes. We need to upwrap any object
|
| 630 |
+
# proxy. Not wanting to add this to ObjectProxy as not sure of
|
| 631 |
+
# broader implications of doing that. Thus restrict to
|
| 632 |
+
# FunctionWrapper used by decorators.
|
| 633 |
+
|
| 634 |
+
if hasattr(subclass, "__wrapped__"):
|
| 635 |
+
return issubclass(subclass.__wrapped__, self.__wrapped__)
|
| 636 |
+
else:
|
| 637 |
+
return issubclass(subclass, self.__wrapped__)
|
| 638 |
+
|
| 639 |
+
class BoundFunctionWrapper(_FunctionWrapperBase):
|
| 640 |
+
|
| 641 |
+
def __call__(*args, **kwargs):
|
| 642 |
+
def _unpack_self(self, *args):
|
| 643 |
+
return self, args
|
| 644 |
+
|
| 645 |
+
self, args = _unpack_self(*args)
|
| 646 |
+
|
| 647 |
+
# If enabled has been specified, then evaluate it at this point and if
|
| 648 |
+
# the wrapper is not to be executed, then simply return the bound
|
| 649 |
+
# function rather than a bound wrapper for the bound function. When
|
| 650 |
+
# evaluating enabled, if it is callable we call it, otherwise we
|
| 651 |
+
# evaluate it as a boolean.
|
| 652 |
+
|
| 653 |
+
if self._self_enabled is not None:
|
| 654 |
+
if callable(self._self_enabled):
|
| 655 |
+
if not self._self_enabled():
|
| 656 |
+
return self.__wrapped__(*args, **kwargs)
|
| 657 |
+
elif not self._self_enabled:
|
| 658 |
+
return self.__wrapped__(*args, **kwargs)
|
| 659 |
+
|
| 660 |
+
# We need to do things different depending on whether we are likely
|
| 661 |
+
# wrapping an instance method vs a static method or class method.
|
| 662 |
+
|
| 663 |
+
if self._self_binding == 'function':
|
| 664 |
+
if self._self_instance is None and args:
|
| 665 |
+
instance, newargs = args[0], args[1:]
|
| 666 |
+
if isinstance(instance, self._self_owner):
|
| 667 |
+
wrapped = PartialCallableObjectProxy(self.__wrapped__, instance)
|
| 668 |
+
return self._self_wrapper(wrapped, instance, newargs, kwargs)
|
| 669 |
+
|
| 670 |
+
return self._self_wrapper(self.__wrapped__, self._self_instance,
|
| 671 |
+
args, kwargs)
|
| 672 |
+
|
| 673 |
+
elif self._self_binding == 'callable':
|
| 674 |
+
if self._self_instance is None:
|
| 675 |
+
# This situation can occur where someone is calling the
|
| 676 |
+
# instancemethod via the class type and passing the instance as
|
| 677 |
+
# the first argument. We need to shift the args before making
|
| 678 |
+
# the call to the wrapper and effectively bind the instance to
|
| 679 |
+
# the wrapped function using a partial so the wrapper doesn't
|
| 680 |
+
# see anything as being different.
|
| 681 |
+
|
| 682 |
+
if not args:
|
| 683 |
+
raise TypeError('missing 1 required positional argument')
|
| 684 |
+
|
| 685 |
+
instance, args = args[0], args[1:]
|
| 686 |
+
wrapped = PartialCallableObjectProxy(self.__wrapped__, instance)
|
| 687 |
+
return self._self_wrapper(wrapped, instance, args, kwargs)
|
| 688 |
+
|
| 689 |
+
return self._self_wrapper(self.__wrapped__, self._self_instance,
|
| 690 |
+
args, kwargs)
|
| 691 |
+
|
| 692 |
+
else:
|
| 693 |
+
# As in this case we would be dealing with a classmethod or
|
| 694 |
+
# staticmethod, then _self_instance will only tell us whether
|
| 695 |
+
# when calling the classmethod or staticmethod they did it via an
|
| 696 |
+
# instance of the class it is bound to and not the case where
|
| 697 |
+
# done by the class type itself. We thus ignore _self_instance
|
| 698 |
+
# and use the __self__ attribute of the bound function instead.
|
| 699 |
+
# For a classmethod, this means instance will be the class type
|
| 700 |
+
# and for a staticmethod it will be None. This is probably the
|
| 701 |
+
# more useful thing we can pass through even though we loose
|
| 702 |
+
# knowledge of whether they were called on the instance vs the
|
| 703 |
+
# class type, as it reflects what they have available in the
|
| 704 |
+
# decoratored function.
|
| 705 |
+
|
| 706 |
+
instance = getattr(self.__wrapped__, '__self__', None)
|
| 707 |
+
|
| 708 |
+
return self._self_wrapper(self.__wrapped__, instance, args,
|
| 709 |
+
kwargs)
|
| 710 |
+
|
| 711 |
+
class FunctionWrapper(_FunctionWrapperBase):
|
| 712 |
+
|
| 713 |
+
__bound_function_wrapper__ = BoundFunctionWrapper
|
| 714 |
+
|
| 715 |
+
def __init__(self, wrapped, wrapper, enabled=None):
|
| 716 |
+
# What it is we are wrapping here could be anything. We need to
|
| 717 |
+
# try and detect specific cases though. In particular, we need
|
| 718 |
+
# to detect when we are given something that is a method of a
|
| 719 |
+
# class. Further, we need to know when it is likely an instance
|
| 720 |
+
# method, as opposed to a class or static method. This can
|
| 721 |
+
# become problematic though as there isn't strictly a fool proof
|
| 722 |
+
# method of knowing.
|
| 723 |
+
#
|
| 724 |
+
# The situations we could encounter when wrapping a method are:
|
| 725 |
+
#
|
| 726 |
+
# 1. The wrapper is being applied as part of a decorator which
|
| 727 |
+
# is a part of the class definition. In this case what we are
|
| 728 |
+
# given is the raw unbound function, classmethod or staticmethod
|
| 729 |
+
# wrapper objects.
|
| 730 |
+
#
|
| 731 |
+
# The problem here is that we will not know we are being applied
|
| 732 |
+
# in the context of the class being set up. This becomes
|
| 733 |
+
# important later for the case of an instance method, because in
|
| 734 |
+
# that case we just see it as a raw function and can't
|
| 735 |
+
# distinguish it from wrapping a normal function outside of
|
| 736 |
+
# a class context.
|
| 737 |
+
#
|
| 738 |
+
# 2. The wrapper is being applied when performing monkey
|
| 739 |
+
# patching of the class type afterwards and the method to be
|
| 740 |
+
# wrapped was retrieved direct from the __dict__ of the class
|
| 741 |
+
# type. This is effectively the same as (1) above.
|
| 742 |
+
#
|
| 743 |
+
# 3. The wrapper is being applied when performing monkey
|
| 744 |
+
# patching of the class type afterwards and the method to be
|
| 745 |
+
# wrapped was retrieved from the class type. In this case
|
| 746 |
+
# binding will have been performed where the instance against
|
| 747 |
+
# which the method is bound will be None at that point.
|
| 748 |
+
#
|
| 749 |
+
# This case is a problem because we can no longer tell if the
|
| 750 |
+
# method was a static method, plus if using Python3, we cannot
|
| 751 |
+
# tell if it was an instance method as the concept of an
|
| 752 |
+
# unnbound method no longer exists.
|
| 753 |
+
#
|
| 754 |
+
# 4. The wrapper is being applied when performing monkey
|
| 755 |
+
# patching of an instance of a class. In this case binding will
|
| 756 |
+
# have been perfomed where the instance was not None.
|
| 757 |
+
#
|
| 758 |
+
# This case is a problem because we can no longer tell if the
|
| 759 |
+
# method was a static method.
|
| 760 |
+
#
|
| 761 |
+
# Overall, the best we can do is look at the original type of the
|
| 762 |
+
# object which was wrapped prior to any binding being done and
|
| 763 |
+
# see if it is an instance of classmethod or staticmethod. In
|
| 764 |
+
# the case where other decorators are between us and them, if
|
| 765 |
+
# they do not propagate the __class__ attribute so that the
|
| 766 |
+
# isinstance() checks works, then likely this will do the wrong
|
| 767 |
+
# thing where classmethod and staticmethod are used.
|
| 768 |
+
#
|
| 769 |
+
# Since it is likely to be very rare that anyone even puts
|
| 770 |
+
# decorators around classmethod and staticmethod, likelihood of
|
| 771 |
+
# that being an issue is very small, so we accept it and suggest
|
| 772 |
+
# that those other decorators be fixed. It is also only an issue
|
| 773 |
+
# if a decorator wants to actually do things with the arguments.
|
| 774 |
+
#
|
| 775 |
+
# As to not being able to identify static methods properly, we
|
| 776 |
+
# just hope that that isn't something people are going to want
|
| 777 |
+
# to wrap, or if they do suggest they do it the correct way by
|
| 778 |
+
# ensuring that it is decorated in the class definition itself,
|
| 779 |
+
# or patch it in the __dict__ of the class type.
|
| 780 |
+
#
|
| 781 |
+
# So to get the best outcome we can, whenever we aren't sure what
|
| 782 |
+
# it is, we label it as a 'callable'. If it was already bound and
|
| 783 |
+
# that is rebound later, we assume that it will be an instance
|
| 784 |
+
# method and try and cope with the possibility that the 'self'
|
| 785 |
+
# argument it being passed as an explicit argument and shuffle
|
| 786 |
+
# the arguments around to extract 'self' for use as the instance.
|
| 787 |
+
|
| 788 |
+
binding = None
|
| 789 |
+
|
| 790 |
+
if isinstance(wrapped, _FunctionWrapperBase):
|
| 791 |
+
binding = wrapped._self_binding
|
| 792 |
+
|
| 793 |
+
if not binding:
|
| 794 |
+
if inspect.isbuiltin(wrapped):
|
| 795 |
+
binding = 'builtin'
|
| 796 |
+
|
| 797 |
+
elif inspect.isfunction(wrapped):
|
| 798 |
+
binding = 'function'
|
| 799 |
+
|
| 800 |
+
elif inspect.isclass(wrapped):
|
| 801 |
+
binding = 'class'
|
| 802 |
+
|
| 803 |
+
elif isinstance(wrapped, classmethod):
|
| 804 |
+
binding = 'classmethod'
|
| 805 |
+
|
| 806 |
+
elif isinstance(wrapped, staticmethod):
|
| 807 |
+
binding = 'staticmethod'
|
| 808 |
+
|
| 809 |
+
elif hasattr(wrapped, '__self__'):
|
| 810 |
+
if inspect.isclass(wrapped.__self__):
|
| 811 |
+
binding = 'classmethod'
|
| 812 |
+
elif inspect.ismethod(wrapped):
|
| 813 |
+
binding = 'instancemethod'
|
| 814 |
+
else:
|
| 815 |
+
binding = 'callable'
|
| 816 |
+
|
| 817 |
+
else:
|
| 818 |
+
binding = 'callable'
|
| 819 |
+
|
| 820 |
+
super(FunctionWrapper, self).__init__(wrapped, None, wrapper,
|
| 821 |
+
enabled, binding)
|