local.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. import copy
  2. import math
  3. import operator
  4. import typing as t
  5. from contextvars import ContextVar
  6. from functools import partial
  7. from functools import update_wrapper
  8. from operator import attrgetter
  9. from .wsgi import ClosingIterator
  10. if t.TYPE_CHECKING:
  11. from _typeshed.wsgi import StartResponse
  12. from _typeshed.wsgi import WSGIApplication
  13. from _typeshed.wsgi import WSGIEnvironment
  14. T = t.TypeVar("T")
  15. F = t.TypeVar("F", bound=t.Callable[..., t.Any])
  16. def release_local(local: t.Union["Local", "LocalStack"]) -> None:
  17. """Release the data for the current context in a :class:`Local` or
  18. :class:`LocalStack` without using a :class:`LocalManager`.
  19. This should not be needed for modern use cases, and may be removed
  20. in the future.
  21. .. versionadded:: 0.6.1
  22. """
  23. local.__release_local__()
  24. class Local:
  25. """Create a namespace of context-local data. This wraps a
  26. :class:`ContextVar` containing a :class:`dict` value.
  27. This may incur a performance penalty compared to using individual
  28. context vars, as it has to copy data to avoid mutating the dict
  29. between nested contexts.
  30. :param context_var: The :class:`~contextvars.ContextVar` to use as
  31. storage for this local. If not given, one will be created.
  32. Context vars not created at the global scope may interfere with
  33. garbage collection.
  34. .. versionchanged:: 2.0
  35. Uses ``ContextVar`` instead of a custom storage implementation.
  36. """
  37. __slots__ = ("__storage",)
  38. def __init__(
  39. self, context_var: t.Optional[ContextVar[t.Dict[str, t.Any]]] = None
  40. ) -> None:
  41. if context_var is None:
  42. # A ContextVar not created at global scope interferes with
  43. # Python's garbage collection. However, a local only makes
  44. # sense defined at the global scope as well, in which case
  45. # the GC issue doesn't seem relevant.
  46. context_var = ContextVar(f"werkzeug.Local<{id(self)}>.storage")
  47. object.__setattr__(self, "_Local__storage", context_var)
  48. def __iter__(self) -> t.Iterator[t.Tuple[str, t.Any]]:
  49. return iter(self.__storage.get({}).items())
  50. def __call__(
  51. self, name: str, *, unbound_message: t.Optional[str] = None
  52. ) -> "LocalProxy":
  53. """Create a :class:`LocalProxy` that access an attribute on this
  54. local namespace.
  55. :param name: Proxy this attribute.
  56. :param unbound_message: The error message that the proxy will
  57. show if the attribute isn't set.
  58. """
  59. return LocalProxy(self, name, unbound_message=unbound_message)
  60. def __release_local__(self) -> None:
  61. self.__storage.set({})
  62. def __getattr__(self, name: str) -> t.Any:
  63. values = self.__storage.get({})
  64. if name in values:
  65. return values[name]
  66. raise AttributeError(name)
  67. def __setattr__(self, name: str, value: t.Any) -> None:
  68. values = self.__storage.get({}).copy()
  69. values[name] = value
  70. self.__storage.set(values)
  71. def __delattr__(self, name: str) -> None:
  72. values = self.__storage.get({})
  73. if name in values:
  74. values = values.copy()
  75. del values[name]
  76. self.__storage.set(values)
  77. else:
  78. raise AttributeError(name)
  79. class LocalStack(t.Generic[T]):
  80. """Create a stack of context-local data. This wraps a
  81. :class:`ContextVar` containing a :class:`list` value.
  82. This may incur a performance penalty compared to using individual
  83. context vars, as it has to copy data to avoid mutating the list
  84. between nested contexts.
  85. :param context_var: The :class:`~contextvars.ContextVar` to use as
  86. storage for this local. If not given, one will be created.
  87. Context vars not created at the global scope may interfere with
  88. garbage collection.
  89. .. versionchanged:: 2.0
  90. Uses ``ContextVar`` instead of a custom storage implementation.
  91. .. versionadded:: 0.6.1
  92. """
  93. __slots__ = ("_storage",)
  94. def __init__(self, context_var: t.Optional[ContextVar[t.List[T]]] = None) -> None:
  95. if context_var is None:
  96. # A ContextVar not created at global scope interferes with
  97. # Python's garbage collection. However, a local only makes
  98. # sense defined at the global scope as well, in which case
  99. # the GC issue doesn't seem relevant.
  100. context_var = ContextVar(f"werkzeug.LocalStack<{id(self)}>.storage")
  101. self._storage = context_var
  102. def __release_local__(self) -> None:
  103. self._storage.set([])
  104. def push(self, obj: T) -> t.List[T]:
  105. """Add a new item to the top of the stack."""
  106. stack = self._storage.get([]).copy()
  107. stack.append(obj)
  108. self._storage.set(stack)
  109. return stack
  110. def pop(self) -> t.Optional[T]:
  111. """Remove the top item from the stack and return it. If the
  112. stack is empty, return ``None``.
  113. """
  114. stack = self._storage.get([])
  115. if len(stack) == 0:
  116. return None
  117. rv = stack[-1]
  118. self._storage.set(stack[:-1])
  119. return rv
  120. @property
  121. def top(self) -> t.Optional[T]:
  122. """The topmost item on the stack. If the stack is empty,
  123. `None` is returned.
  124. """
  125. stack = self._storage.get([])
  126. if len(stack) == 0:
  127. return None
  128. return stack[-1]
  129. def __call__(
  130. self, name: t.Optional[str] = None, *, unbound_message: t.Optional[str] = None
  131. ) -> "LocalProxy":
  132. """Create a :class:`LocalProxy` that accesses the top of this
  133. local stack.
  134. :param name: If given, the proxy access this attribute of the
  135. top item, rather than the item itself.
  136. :param unbound_message: The error message that the proxy will
  137. show if the stack is empty.
  138. """
  139. return LocalProxy(self, name, unbound_message=unbound_message)
  140. class LocalManager:
  141. """Manage releasing the data for the current context in one or more
  142. :class:`Local` and :class:`LocalStack` objects.
  143. This should not be needed for modern use cases, and may be removed
  144. in the future.
  145. :param locals: A local or list of locals to manage.
  146. .. versionchanged:: 2.0
  147. ``ident_func`` is deprecated and will be removed in Werkzeug
  148. 2.1.
  149. .. versionchanged:: 0.7
  150. The ``ident_func`` parameter was added.
  151. .. versionchanged:: 0.6.1
  152. The :func:`release_local` function can be used instead of a
  153. manager.
  154. """
  155. __slots__ = ("locals",)
  156. def __init__(
  157. self,
  158. locals: t.Optional[
  159. t.Union[Local, LocalStack, t.Iterable[t.Union[Local, LocalStack]]]
  160. ] = None,
  161. ) -> None:
  162. if locals is None:
  163. self.locals = []
  164. elif isinstance(locals, Local):
  165. self.locals = [locals]
  166. else:
  167. self.locals = list(locals) # type: ignore[arg-type]
  168. def cleanup(self) -> None:
  169. """Release the data in the locals for this context. Call this at
  170. the end of each request or use :meth:`make_middleware`.
  171. """
  172. for local in self.locals:
  173. release_local(local)
  174. def make_middleware(self, app: "WSGIApplication") -> "WSGIApplication":
  175. """Wrap a WSGI application so that local data is released
  176. automatically after the response has been sent for a request.
  177. """
  178. def application(
  179. environ: "WSGIEnvironment", start_response: "StartResponse"
  180. ) -> t.Iterable[bytes]:
  181. return ClosingIterator(app(environ, start_response), self.cleanup)
  182. return application
  183. def middleware(self, func: "WSGIApplication") -> "WSGIApplication":
  184. """Like :meth:`make_middleware` but used as a decorator on the
  185. WSGI application function.
  186. .. code-block:: python
  187. @manager.middleware
  188. def application(environ, start_response):
  189. ...
  190. """
  191. return update_wrapper(self.make_middleware(func), func)
  192. def __repr__(self) -> str:
  193. return f"<{type(self).__name__} storages: {len(self.locals)}>"
  194. class _ProxyLookup:
  195. """Descriptor that handles proxied attribute lookup for
  196. :class:`LocalProxy`.
  197. :param f: The built-in function this attribute is accessed through.
  198. Instead of looking up the special method, the function call
  199. is redone on the object.
  200. :param fallback: Return this function if the proxy is unbound
  201. instead of raising a :exc:`RuntimeError`.
  202. :param is_attr: This proxied name is an attribute, not a function.
  203. Call the fallback immediately to get the value.
  204. :param class_value: Value to return when accessed from the
  205. ``LocalProxy`` class directly. Used for ``__doc__`` so building
  206. docs still works.
  207. """
  208. __slots__ = ("bind_f", "fallback", "is_attr", "class_value", "name")
  209. def __init__(
  210. self,
  211. f: t.Optional[t.Callable] = None,
  212. fallback: t.Optional[t.Callable] = None,
  213. class_value: t.Optional[t.Any] = None,
  214. is_attr: bool = False,
  215. ) -> None:
  216. bind_f: t.Optional[t.Callable[["LocalProxy", t.Any], t.Callable]]
  217. if hasattr(f, "__get__"):
  218. # A Python function, can be turned into a bound method.
  219. def bind_f(instance: "LocalProxy", obj: t.Any) -> t.Callable:
  220. return f.__get__(obj, type(obj)) # type: ignore
  221. elif f is not None:
  222. # A C function, use partial to bind the first argument.
  223. def bind_f(instance: "LocalProxy", obj: t.Any) -> t.Callable:
  224. return partial(f, obj) # type: ignore
  225. else:
  226. # Use getattr, which will produce a bound method.
  227. bind_f = None
  228. self.bind_f = bind_f
  229. self.fallback = fallback
  230. self.class_value = class_value
  231. self.is_attr = is_attr
  232. def __set_name__(self, owner: "LocalProxy", name: str) -> None:
  233. self.name = name
  234. def __get__(self, instance: "LocalProxy", owner: t.Optional[type] = None) -> t.Any:
  235. if instance is None:
  236. if self.class_value is not None:
  237. return self.class_value
  238. return self
  239. try:
  240. obj = instance._get_current_object() # type: ignore[misc]
  241. except RuntimeError:
  242. if self.fallback is None:
  243. raise
  244. fallback = self.fallback.__get__(instance, owner)
  245. if self.is_attr:
  246. # __class__ and __doc__ are attributes, not methods.
  247. # Call the fallback to get the value.
  248. return fallback()
  249. return fallback
  250. if self.bind_f is not None:
  251. return self.bind_f(instance, obj)
  252. return getattr(obj, self.name)
  253. def __repr__(self) -> str:
  254. return f"proxy {self.name}"
  255. def __call__(self, instance: "LocalProxy", *args: t.Any, **kwargs: t.Any) -> t.Any:
  256. """Support calling unbound methods from the class. For example,
  257. this happens with ``copy.copy``, which does
  258. ``type(x).__copy__(x)``. ``type(x)`` can't be proxied, so it
  259. returns the proxy type and descriptor.
  260. """
  261. return self.__get__(instance, type(instance))(*args, **kwargs)
  262. class _ProxyIOp(_ProxyLookup):
  263. """Look up an augmented assignment method on a proxied object. The
  264. method is wrapped to return the proxy instead of the object.
  265. """
  266. __slots__ = ()
  267. def __init__(
  268. self, f: t.Optional[t.Callable] = None, fallback: t.Optional[t.Callable] = None
  269. ) -> None:
  270. super().__init__(f, fallback)
  271. def bind_f(instance: "LocalProxy", obj: t.Any) -> t.Callable:
  272. def i_op(self: t.Any, other: t.Any) -> "LocalProxy":
  273. f(self, other) # type: ignore
  274. return instance
  275. return i_op.__get__(obj, type(obj)) # type: ignore
  276. self.bind_f = bind_f
  277. def _l_to_r_op(op: F) -> F:
  278. """Swap the argument order to turn an l-op into an r-op."""
  279. def r_op(obj: t.Any, other: t.Any) -> t.Any:
  280. return op(other, obj)
  281. return t.cast(F, r_op)
  282. def _identity(o: T) -> T:
  283. return o
  284. class LocalProxy(t.Generic[T]):
  285. """A proxy to the object bound to a context-local object. All
  286. operations on the proxy are forwarded to the bound object. If no
  287. object is bound, a ``RuntimeError`` is raised.
  288. :param local: The context-local object that provides the proxied
  289. object.
  290. :param name: Proxy this attribute from the proxied object.
  291. :param unbound_message: The error message to show if the
  292. context-local object is unbound.
  293. Proxy a :class:`~contextvars.ContextVar` to make it easier to
  294. access. Pass a name to proxy that attribute.
  295. .. code-block:: python
  296. _request_var = ContextVar("request")
  297. request = LocalProxy(_request_var)
  298. session = LocalProxy(_request_var, "session")
  299. Proxy an attribute on a :class:`Local` namespace by calling the
  300. local with the attribute name:
  301. .. code-block:: python
  302. data = Local()
  303. user = data("user")
  304. Proxy the top item on a :class:`LocalStack` by calling the local.
  305. Pass a name to proxy that attribute.
  306. .. code-block::
  307. app_stack = LocalStack()
  308. current_app = app_stack()
  309. g = app_stack("g")
  310. Pass a function to proxy the return value from that function. This
  311. was previously used to access attributes of local objects before
  312. that was supported directly.
  313. .. code-block:: python
  314. session = LocalProxy(lambda: request.session)
  315. ``__repr__`` and ``__class__`` are proxied, so ``repr(x)`` and
  316. ``isinstance(x, cls)`` will look like the proxied object. Use
  317. ``issubclass(type(x), LocalProxy)`` to check if an object is a
  318. proxy.
  319. .. code-block:: python
  320. repr(user) # <User admin>
  321. isinstance(user, User) # True
  322. issubclass(type(user), LocalProxy) # True
  323. .. versionchanged:: 2.2.2
  324. ``__wrapped__`` is set when wrapping an object, not only when
  325. wrapping a function, to prevent doctest from failing.
  326. .. versionchanged:: 2.2
  327. Can proxy a ``ContextVar`` or ``LocalStack`` directly.
  328. .. versionchanged:: 2.2
  329. The ``name`` parameter can be used with any proxied object, not
  330. only ``Local``.
  331. .. versionchanged:: 2.2
  332. Added the ``unbound_message`` parameter.
  333. .. versionchanged:: 2.0
  334. Updated proxied attributes and methods to reflect the current
  335. data model.
  336. .. versionchanged:: 0.6.1
  337. The class can be instantiated with a callable.
  338. """
  339. __slots__ = ("__wrapped", "_get_current_object")
  340. _get_current_object: t.Callable[[], T]
  341. """Return the current object this proxy is bound to. If the proxy is
  342. unbound, this raises a ``RuntimeError``.
  343. This should be used if you need to pass the object to something that
  344. doesn't understand the proxy. It can also be useful for performance
  345. if you are accessing the object multiple times in a function, rather
  346. than going through the proxy multiple times.
  347. """
  348. def __init__(
  349. self,
  350. local: t.Union[ContextVar[T], Local, LocalStack[T], t.Callable[[], T]],
  351. name: t.Optional[str] = None,
  352. *,
  353. unbound_message: t.Optional[str] = None,
  354. ) -> None:
  355. if name is None:
  356. get_name = _identity
  357. else:
  358. get_name = attrgetter(name) # type: ignore[assignment]
  359. if unbound_message is None:
  360. unbound_message = "object is not bound"
  361. if isinstance(local, Local):
  362. if name is None:
  363. raise TypeError("'name' is required when proxying a 'Local' object.")
  364. def _get_current_object() -> T:
  365. try:
  366. return get_name(local) # type: ignore[return-value]
  367. except AttributeError:
  368. raise RuntimeError(unbound_message) from None
  369. elif isinstance(local, LocalStack):
  370. def _get_current_object() -> T:
  371. obj = local.top # type: ignore[union-attr]
  372. if obj is None:
  373. raise RuntimeError(unbound_message)
  374. return get_name(obj)
  375. elif isinstance(local, ContextVar):
  376. def _get_current_object() -> T:
  377. try:
  378. obj = local.get() # type: ignore[union-attr]
  379. except LookupError:
  380. raise RuntimeError(unbound_message) from None
  381. return get_name(obj)
  382. elif callable(local):
  383. def _get_current_object() -> T:
  384. return get_name(local()) # type: ignore
  385. else:
  386. raise TypeError(f"Don't know how to proxy '{type(local)}'.")
  387. object.__setattr__(self, "_LocalProxy__wrapped", local)
  388. object.__setattr__(self, "_get_current_object", _get_current_object)
  389. __doc__ = _ProxyLookup( # type: ignore
  390. class_value=__doc__, fallback=lambda self: type(self).__doc__, is_attr=True
  391. )
  392. __wrapped__ = _ProxyLookup(
  393. fallback=lambda self: self._LocalProxy__wrapped, is_attr=True
  394. )
  395. # __del__ should only delete the proxy
  396. __repr__ = _ProxyLookup( # type: ignore
  397. repr, fallback=lambda self: f"<{type(self).__name__} unbound>"
  398. )
  399. __str__ = _ProxyLookup(str) # type: ignore
  400. __bytes__ = _ProxyLookup(bytes)
  401. __format__ = _ProxyLookup() # type: ignore
  402. __lt__ = _ProxyLookup(operator.lt)
  403. __le__ = _ProxyLookup(operator.le)
  404. __eq__ = _ProxyLookup(operator.eq) # type: ignore
  405. __ne__ = _ProxyLookup(operator.ne) # type: ignore
  406. __gt__ = _ProxyLookup(operator.gt)
  407. __ge__ = _ProxyLookup(operator.ge)
  408. __hash__ = _ProxyLookup(hash) # type: ignore
  409. __bool__ = _ProxyLookup(bool, fallback=lambda self: False)
  410. __getattr__ = _ProxyLookup(getattr)
  411. # __getattribute__ triggered through __getattr__
  412. __setattr__ = _ProxyLookup(setattr) # type: ignore
  413. __delattr__ = _ProxyLookup(delattr) # type: ignore
  414. __dir__ = _ProxyLookup(dir, fallback=lambda self: []) # type: ignore
  415. # __get__ (proxying descriptor not supported)
  416. # __set__ (descriptor)
  417. # __delete__ (descriptor)
  418. # __set_name__ (descriptor)
  419. # __objclass__ (descriptor)
  420. # __slots__ used by proxy itself
  421. # __dict__ (__getattr__)
  422. # __weakref__ (__getattr__)
  423. # __init_subclass__ (proxying metaclass not supported)
  424. # __prepare__ (metaclass)
  425. __class__ = _ProxyLookup(
  426. fallback=lambda self: type(self), is_attr=True
  427. ) # type: ignore
  428. __instancecheck__ = _ProxyLookup(lambda self, other: isinstance(other, self))
  429. __subclasscheck__ = _ProxyLookup(lambda self, other: issubclass(other, self))
  430. # __class_getitem__ triggered through __getitem__
  431. __call__ = _ProxyLookup(lambda self, *args, **kwargs: self(*args, **kwargs))
  432. __len__ = _ProxyLookup(len)
  433. __length_hint__ = _ProxyLookup(operator.length_hint)
  434. __getitem__ = _ProxyLookup(operator.getitem)
  435. __setitem__ = _ProxyLookup(operator.setitem)
  436. __delitem__ = _ProxyLookup(operator.delitem)
  437. # __missing__ triggered through __getitem__
  438. __iter__ = _ProxyLookup(iter)
  439. __next__ = _ProxyLookup(next)
  440. __reversed__ = _ProxyLookup(reversed)
  441. __contains__ = _ProxyLookup(operator.contains)
  442. __add__ = _ProxyLookup(operator.add)
  443. __sub__ = _ProxyLookup(operator.sub)
  444. __mul__ = _ProxyLookup(operator.mul)
  445. __matmul__ = _ProxyLookup(operator.matmul)
  446. __truediv__ = _ProxyLookup(operator.truediv)
  447. __floordiv__ = _ProxyLookup(operator.floordiv)
  448. __mod__ = _ProxyLookup(operator.mod)
  449. __divmod__ = _ProxyLookup(divmod)
  450. __pow__ = _ProxyLookup(pow)
  451. __lshift__ = _ProxyLookup(operator.lshift)
  452. __rshift__ = _ProxyLookup(operator.rshift)
  453. __and__ = _ProxyLookup(operator.and_)
  454. __xor__ = _ProxyLookup(operator.xor)
  455. __or__ = _ProxyLookup(operator.or_)
  456. __radd__ = _ProxyLookup(_l_to_r_op(operator.add))
  457. __rsub__ = _ProxyLookup(_l_to_r_op(operator.sub))
  458. __rmul__ = _ProxyLookup(_l_to_r_op(operator.mul))
  459. __rmatmul__ = _ProxyLookup(_l_to_r_op(operator.matmul))
  460. __rtruediv__ = _ProxyLookup(_l_to_r_op(operator.truediv))
  461. __rfloordiv__ = _ProxyLookup(_l_to_r_op(operator.floordiv))
  462. __rmod__ = _ProxyLookup(_l_to_r_op(operator.mod))
  463. __rdivmod__ = _ProxyLookup(_l_to_r_op(divmod))
  464. __rpow__ = _ProxyLookup(_l_to_r_op(pow))
  465. __rlshift__ = _ProxyLookup(_l_to_r_op(operator.lshift))
  466. __rrshift__ = _ProxyLookup(_l_to_r_op(operator.rshift))
  467. __rand__ = _ProxyLookup(_l_to_r_op(operator.and_))
  468. __rxor__ = _ProxyLookup(_l_to_r_op(operator.xor))
  469. __ror__ = _ProxyLookup(_l_to_r_op(operator.or_))
  470. __iadd__ = _ProxyIOp(operator.iadd)
  471. __isub__ = _ProxyIOp(operator.isub)
  472. __imul__ = _ProxyIOp(operator.imul)
  473. __imatmul__ = _ProxyIOp(operator.imatmul)
  474. __itruediv__ = _ProxyIOp(operator.itruediv)
  475. __ifloordiv__ = _ProxyIOp(operator.ifloordiv)
  476. __imod__ = _ProxyIOp(operator.imod)
  477. __ipow__ = _ProxyIOp(operator.ipow)
  478. __ilshift__ = _ProxyIOp(operator.ilshift)
  479. __irshift__ = _ProxyIOp(operator.irshift)
  480. __iand__ = _ProxyIOp(operator.iand)
  481. __ixor__ = _ProxyIOp(operator.ixor)
  482. __ior__ = _ProxyIOp(operator.ior)
  483. __neg__ = _ProxyLookup(operator.neg)
  484. __pos__ = _ProxyLookup(operator.pos)
  485. __abs__ = _ProxyLookup(abs)
  486. __invert__ = _ProxyLookup(operator.invert)
  487. __complex__ = _ProxyLookup(complex)
  488. __int__ = _ProxyLookup(int)
  489. __float__ = _ProxyLookup(float)
  490. __index__ = _ProxyLookup(operator.index)
  491. __round__ = _ProxyLookup(round)
  492. __trunc__ = _ProxyLookup(math.trunc)
  493. __floor__ = _ProxyLookup(math.floor)
  494. __ceil__ = _ProxyLookup(math.ceil)
  495. __enter__ = _ProxyLookup()
  496. __exit__ = _ProxyLookup()
  497. __await__ = _ProxyLookup()
  498. __aiter__ = _ProxyLookup()
  499. __anext__ = _ProxyLookup()
  500. __aenter__ = _ProxyLookup()
  501. __aexit__ = _ProxyLookup()
  502. __copy__ = _ProxyLookup(copy.copy)
  503. __deepcopy__ = _ProxyLookup(copy.deepcopy)
  504. # __getnewargs_ex__ (pickle through proxy not supported)
  505. # __getnewargs__ (pickle)
  506. # __getstate__ (pickle)
  507. # __setstate__ (pickle)
  508. # __reduce__ (pickle)
  509. # __reduce_ex__ (pickle)