How to use the aiofiles._compat.PY_35 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
"""Various base classes."""
import asyncio

from ._compat import PY_35


class AsyncBase:
    def __init__(self, file, loop, executor):
        self._file = file
        self._loop = loop
        self._executor = executor

    if PY_35:
        @asyncio.coroutine
        def __aiter__(self):
            """We are our own iterator."""
            return self

        @asyncio.coroutine
        def __anext__(self):
            """Simulate normal file iteration."""
            line = yield from self.readline()
            if line:
                return line
            else:
                raise StopAsyncIteration

if PY_35:
    from collections.abc import Coroutine