diff options
author | S. Solomon Darnell | 2025-03-28 21:52:21 -0500 |
---|---|---|
committer | S. Solomon Darnell | 2025-03-28 21:52:21 -0500 |
commit | 4a52a71956a8d46fcb7294ac71734504bb09bcc2 (patch) | |
tree | ee3dc5af3b6313e921cd920906356f5d4febc4ed /.venv/lib/python3.12/site-packages/asyncpg/connresource.py | |
parent | cc961e04ba734dd72309fb548a2f97d67d578813 (diff) | |
download | gn-ai-master.tar.gz |
Diffstat (limited to '.venv/lib/python3.12/site-packages/asyncpg/connresource.py')
-rw-r--r-- | .venv/lib/python3.12/site-packages/asyncpg/connresource.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/asyncpg/connresource.py b/.venv/lib/python3.12/site-packages/asyncpg/connresource.py new file mode 100644 index 00000000..3b0c1d3c --- /dev/null +++ b/.venv/lib/python3.12/site-packages/asyncpg/connresource.py @@ -0,0 +1,44 @@ + +# Copyright (C) 2016-present the asyncpg authors and contributors +# <see AUTHORS file> +# +# This module is part of asyncpg and is released under +# the Apache 2.0 License: http://www.apache.org/licenses/LICENSE-2.0 + + +import functools + +from . import exceptions + + +def guarded(meth): + """A decorator to add a sanity check to ConnectionResource methods.""" + + @functools.wraps(meth) + def _check(self, *args, **kwargs): + self._check_conn_validity(meth.__name__) + return meth(self, *args, **kwargs) + + return _check + + +class ConnectionResource: + __slots__ = ('_connection', '_con_release_ctr') + + def __init__(self, connection): + self._connection = connection + self._con_release_ctr = connection._pool_release_ctr + + def _check_conn_validity(self, meth_name): + con_release_ctr = self._connection._pool_release_ctr + if con_release_ctr != self._con_release_ctr: + raise exceptions.InterfaceError( + 'cannot call {}.{}(): ' + 'the underlying connection has been released back ' + 'to the pool'.format(self.__class__.__name__, meth_name)) + + if self._connection.is_closed(): + raise exceptions.InterfaceError( + 'cannot call {}.{}(): ' + 'the underlying connection is closed'.format( + self.__class__.__name__, meth_name)) |