| 94 | |
| 95 | |
| 96 | class PoolConnectionProxy(connection._ConnectionProxy, |
| 97 | metaclass=PoolConnectionProxyMeta, |
| 98 | wrap=True): |
| 99 | |
| 100 | __slots__ = ('_con', '_holder') |
| 101 | |
| 102 | def __init__( |
| 103 | self, holder: PoolConnectionHolder, con: connection.Connection |
| 104 | ) -> None: |
| 105 | self._con = con |
| 106 | self._holder = holder |
| 107 | con._set_proxy(self) |
| 108 | |
| 109 | def __getattr__(self, attr: str) -> Any: |
| 110 | # Proxy all unresolved attributes to the wrapped Connection object. |
| 111 | return getattr(self._con, attr) |
| 112 | |
| 113 | def _detach(self) -> Optional[connection.Connection]: |
| 114 | if self._con is None: |
| 115 | return |
| 116 | |
| 117 | con, self._con = self._con, None |
| 118 | con._set_proxy(None) |
| 119 | return con |
| 120 | |
| 121 | def __repr__(self) -> str: |
| 122 | if self._con is None: |
| 123 | return '<{classname} [released] {id:#x}>'.format( |
| 124 | classname=self.__class__.__name__, id=id(self)) |
| 125 | else: |
| 126 | return '<{classname} {con!r} {id:#x}>'.format( |
| 127 | classname=self.__class__.__name__, con=self._con, id=id(self)) |
| 128 | |
| 129 | |
| 130 | class PoolConnectionHolder: |