How to use the aiomysql.utils._ContextManager function in aiomysql

To help you get started, we’ve selected a few aiomysql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aio-libs / aiomysql / aiomysql / utils.py View on Github external
def __aexit__(self, exc_type, exc, tb):
            self._obj.close()
            yield from self._obj.wait_closed()
            self._obj = None


class _SAConnectionContextManager(_ContextManager):

    if PY_35:  # pragma: no branch
        @asyncio.coroutine
        def __aiter__(self):
            result = yield from self._coro
            return result


class _TransactionContextManager(_ContextManager):

    if PY_35:  # pragma: no branch

        @asyncio.coroutine
        def __aexit__(self, exc_type, exc, tb):
            if exc_type:
                yield from self._obj.rollback()
            else:
                if self._obj.is_active:
                    yield from self._obj.commit()
            self._obj = None


class _PoolAcquireContextManager(_ContextManager):

    __slots__ = ('_coro', '_conn', '_pool')
github aio-libs / aiomysql / aiomysql / utils.py View on Github external
class _TransactionContextManager(_ContextManager):

    if PY_35:  # pragma: no branch

        @asyncio.coroutine
        def __aexit__(self, exc_type, exc, tb):
            if exc_type:
                yield from self._obj.rollback()
            else:
                if self._obj.is_active:
                    yield from self._obj.commit()
            self._obj = None


class _PoolAcquireContextManager(_ContextManager):

    __slots__ = ('_coro', '_conn', '_pool')

    def __init__(self, coro, pool):
        self._coro = coro
        self._conn = None
        self._pool = pool

    if PY_35:  # pragma: no branch
        @asyncio.coroutine
        def __aenter__(self):
            self._conn = yield from self._coro
            return self._conn

        @asyncio.coroutine
        def __aexit__(self, exc_type, exc, tb):
github aio-libs / aiomysql / aiomysql / utils.py View on Github external
else:
                yield from self._obj.ensure_closed()
            self._obj = None


class _PoolContextManager(_ContextManager):

    if PY_35:  # pragma: no branch
        @asyncio.coroutine
        def __aexit__(self, exc_type, exc, tb):
            self._obj.close()
            yield from self._obj.wait_closed()
            self._obj = None


class _SAConnectionContextManager(_ContextManager):

    if PY_35:  # pragma: no branch
        @asyncio.coroutine
        def __aiter__(self):
            result = yield from self._coro
            return result


class _TransactionContextManager(_ContextManager):

    if PY_35:  # pragma: no branch

        @asyncio.coroutine
        def __aexit__(self, exc_type, exc, tb):
            if exc_type:
                yield from self._obj.rollback()
github aio-libs / aiomysql / aiomysql / utils.py View on Github external
self._conn = yield from self._pool.acquire()
            return self._conn

        @asyncio.coroutine
        def __aexit__(self, exc_type, exc_val, exc_tb):
            try:
                yield from self._pool.release(self._conn)
            finally:
                self._pool = None
                self._conn = None


if not PY_35:
    try:
        from asyncio import coroutines
        coroutines._COROUTINE_TYPES += (_ContextManager,)
    except Exception:
        pass
github aio-libs / aiomysql / aiomysql / utils.py View on Github external
def __await__(self):
            resp = yield from self._coro
            return resp

        @asyncio.coroutine
        def __aenter__(self):
            self._obj = yield from self._coro
            return self._obj

        @asyncio.coroutine
        def __aexit__(self, exc_type, exc, tb):
            yield from self._obj.close()
            self._obj = None


class _ConnectionContextManager(_ContextManager):

    if PY_35:  # pragma: no branch
        @asyncio.coroutine
        def __aexit__(self, exc_type, exc, tb):
            if exc_type is not None:
                self._obj.close()
            else:
                yield from self._obj.ensure_closed()
            self._obj = None


class _PoolContextManager(_ContextManager):

    if PY_35:  # pragma: no branch
        @asyncio.coroutine
        def __aexit__(self, exc_type, exc, tb):
github aio-libs / aiomysql / aiomysql / connection.py View on Github external
any(not issubclass(cursor, Cursor) for cursor in cursors):
                raise TypeError('Custom cursor must be subclass of Cursor')
        except TypeError:
            raise TypeError('Custom cursor must be subclass of Cursor')
        if cursors and len(cursors) == 1:
            cur = cursors[0](self, self._echo)
        elif cursors:
            cursor_name = ''.join(map(lambda x: x.__name__, cursors)) \
                .replace('Cursor', '') + 'Cursor'
            cursor_class = type(cursor_name, cursors, {})
            cur = cursor_class(self, self._echo)
        else:
            cur = self.cursorclass(self, self._echo)
        fut = self._loop.create_future()
        fut.set_result(cur)
        return _ContextManager(fut)
github aio-libs / aiomysql / aiomysql / utils.py View on Github external
self._obj = None


class _ConnectionContextManager(_ContextManager):

    if PY_35:  # pragma: no branch
        @asyncio.coroutine
        def __aexit__(self, exc_type, exc, tb):
            if exc_type is not None:
                self._obj.close()
            else:
                yield from self._obj.ensure_closed()
            self._obj = None


class _PoolContextManager(_ContextManager):

    if PY_35:  # pragma: no branch
        @asyncio.coroutine
        def __aexit__(self, exc_type, exc, tb):
            self._obj.close()
            yield from self._obj.wait_closed()
            self._obj = None


class _SAConnectionContextManager(_ContextManager):

    if PY_35:  # pragma: no branch
        @asyncio.coroutine
        def __aiter__(self):
            result = yield from self._coro
            return result