MCPcopy Create free account
hub / github.com/celery/celery / Proxy

Class Proxy

celery/local.py:52–279  ·  view source on GitHub ↗

Proxy to another object.

Source from the content-addressed store, hash-verified

50
51
52class Proxy:
53 """Proxy to another object."""
54
55 # Code stolen from werkzeug.local.Proxy.
56 __slots__ = ('__local', '__args', '__kwargs', '__dict__')
57
58 def __init__(self, local,
59 args=None, kwargs=None, name=None, __doc__=None):
60 object.__setattr__(self, '_Proxy__local', local)
61 object.__setattr__(self, '_Proxy__args', args or ())
62 object.__setattr__(self, '_Proxy__kwargs', kwargs or {})
63 if name is not None:
64 object.__setattr__(self, '__custom_name__', name)
65 if __doc__ is not None:
66 object.__setattr__(self, '__doc__', __doc__)
67
68 @_default_cls_attr('name', str, __name__)
69 def __name__(self):
70 try:
71 return self.__custom_name__
72 except AttributeError:
73 return self._get_current_object().__name__
74
75 @_default_cls_attr('qualname', str, __name__)
76 def __qualname__(self):
77 try:
78 return self.__custom_name__
79 except AttributeError:
80 return self._get_current_object().__qualname__
81
82 @_default_cls_attr('module', str, __module__)
83 def __module__(self):
84 return self._get_current_object().__module__
85
86 @_default_cls_attr('doc', str, __doc__)
87 def __doc__(self):
88 return self._get_current_object().__doc__
89
90 def _get_class(self):
91 return self._get_current_object().__class__
92
93 @property
94 def __class__(self):
95 return self._get_class()
96
97 def _get_current_object(self):
98 """Get current object.
99
100 This is useful if you want the real
101 object behind the proxy at a time for performance reasons or because
102 you want to pass the object into a different context.
103 """
104 loc = object.__getattribute__(self, '_Proxy__local')
105 if not hasattr(loc, '__release_local__'):
106 return loc(*self.__args, **self.__kwargs)
107 try: # pragma: no cover
108 # not sure what this is about
109 return getattr(loc, self.__name__)

Callers 15

test_docMethod · 0.90
test_nameMethod · 0.90
test_boolMethod · 0.90
test_slotsMethod · 0.90
test_dirMethod · 0.90
test_getsetdel_attrMethod · 0.90
test_dictproxyMethod · 0.90
test_listproxyMethod · 0.90
test_complex_castMethod · 0.90
test_indexMethod · 0.90
test_coerceMethod · 0.90

Calls

no outgoing calls

Tested by 15

test_docMethod · 0.72
test_nameMethod · 0.72
test_boolMethod · 0.72
test_slotsMethod · 0.72
test_dirMethod · 0.72
test_getsetdel_attrMethod · 0.72
test_dictproxyMethod · 0.72
test_listproxyMethod · 0.72
test_complex_castMethod · 0.72
test_indexMethod · 0.72
test_coerceMethod · 0.72