How to use the aiofiles.base._ContextManager function in aiofiles

To help you get started, we’ve selected a few aiofiles 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 Tinche / aiofiles / aiofiles / base.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):
            self._obj.close()
            self._obj = None


class AiofilesContextManager(_ContextManager):
    """An adjusted async context manager for aiofiles."""
    if PY_35:
        @asyncio.coroutine
        def __aexit__(self, exc_type, exc_val, exc_tb):
            yield from self._obj.close()
            self._obj = None