Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
await self._obj.wait_closed()
self._obj = None
class _TransactionPointContextManager(_ContextManager):
async def __aexit__(self, exc_type, exc_val, exc_tb):
if exc_type is not None:
await self._obj.rollback_savepoint()
else:
await self._obj.release_savepoint()
self._obj = None
class _TransactionBeginContextManager(_ContextManager):
async def __aexit__(self, exc_type, exc_val, exc_tb):
if exc_type is not None:
await self._obj.rollback()
else:
await self._obj.commit()
self._obj = None
class _TransactionContextManager(_ContextManager):
async def __aexit__(self, exc_type, exc, tb):
if exc_type:
await self._obj.rollback()
else:
self._obj = None
class _TransactionContextManager(_ContextManager):
async def __aexit__(self, exc_type, exc, tb):
if exc_type:
await self._obj.rollback()
else:
if self._obj.is_active:
await self._obj.commit()
self._obj = None
class _PoolAcquireContextManager(_ContextManager):
__slots__ = ('_coro', '_obj', '_pool')
def __init__(self, coro, pool):
super().__init__(coro)
self._pool = pool
async def __aexit__(self, exc_type, exc, tb):
await self._pool.release(self._obj)
self._pool = None
self._obj = None
class _PoolConnectionContextManager:
"""Context manager.
This enables the following idiom for acquiring and releasing a
self._obj = None
class _TransactionBeginContextManager(_ContextManager):
async def __aexit__(self, exc_type, exc_val, exc_tb):
if exc_type is not None:
await self._obj.rollback()
else:
await self._obj.commit()
self._obj = None
class _TransactionContextManager(_ContextManager):
async def __aexit__(self, exc_type, exc, tb):
if exc_type:
await self._obj.rollback()
else:
if self._obj.is_active:
await self._obj.commit()
self._obj = None
class _PoolAcquireContextManager(_ContextManager):
__slots__ = ('_coro', '_obj', '_pool')
def __init__(self, coro, pool):
super().__init__(coro)
self._pool = pool
return self.send(None)
def __await__(self):
resp = self._coro.__await__()
return resp
async def __aenter__(self):
self._obj = await self._coro
return self._obj
async def __aexit__(self, exc_type, exc, tb):
self._obj.close()
self._obj = None
class _SAConnectionContextManager(_ContextManager):
def __aiter__(self):
return self
async def __anext__(self):
if self._obj is None:
self._obj = await self._coro
try:
return (await self._obj.__anext__())
except StopAsyncIteration:
self._obj.close()
self._obj = None
raise
class _PoolContextManager(_ContextManager):
try:
return (await self._obj.__anext__())
except StopAsyncIteration:
self._obj.close()
self._obj = None
raise
class _PoolContextManager(_ContextManager):
async def __aexit__(self, exc_type, exc, tb):
self._obj.close()
await self._obj.wait_closed()
self._obj = None
class _TransactionPointContextManager(_ContextManager):
async def __aexit__(self, exc_type, exc_val, exc_tb):
if exc_type is not None:
await self._obj.rollback_savepoint()
else:
await self._obj.release_savepoint()
self._obj = None
class _TransactionBeginContextManager(_ContextManager):
async def __aexit__(self, exc_type, exc_val, exc_tb):
if exc_type is not None:
await self._obj.rollback()
else:
def __aiter__(self):
return self
async def __anext__(self):
if self._obj is None:
self._obj = await self._coro
try:
return (await self._obj.__anext__())
except StopAsyncIteration:
self._obj.close()
self._obj = None
raise
class _PoolContextManager(_ContextManager):
async def __aexit__(self, exc_type, exc, tb):
self._obj.close()
await self._obj.wait_closed()
self._obj = None
class _TransactionPointContextManager(_ContextManager):
async def __aexit__(self, exc_type, exc_val, exc_tb):
if exc_type is not None:
await self._obj.rollback_savepoint()
else:
await self._obj.release_savepoint()
self._obj = None
*cursor_factory* argument can be used to create non-standard
cursors. The argument must be subclass of
`psycopg2.extensions.cursor`.
*name*, *scrollable* and *withhold* parameters are not supported by
psycopg in asynchronous mode.
NOTE: as of [TODO] any previously created created cursor from this
connection will be closed
"""
self._last_usage = self._loop.time()
core = self._cursor(name=name, cursor_factory=cursor_factory,
scrollable=scrollable, withhold=withhold,
timeout=timeout)
return _ContextManager(core)
def connect(dsn=None, *, timeout=TIMEOUT, loop=None, enable_json=True,
enable_hstore=True, enable_uuid=True, echo=False, **kwargs):
"""A factory for connecting to PostgreSQL.
The coroutine accepts all parameters that psycopg2.connect() does
plus optional keyword-only `loop` and `timeout` parameters.
Returns instantiated Connection object.
"""
coro = _connect(dsn=dsn, timeout=timeout, loop=loop,
enable_json=enable_json, enable_hstore=enable_hstore,
enable_uuid=enable_uuid, echo=echo, **kwargs)
return _ContextManager(coro)
def cursor(self, *args, **kwargs):
# unfortunately we also need to patch this method as otherwise "self"
# ends up being the aiopg connection object
coro = self._cursor(*args, **kwargs)
return _ContextManager(coro)