How to use the aiofiles.os.wrap 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 N-Coder / studip-fuse / studip_fuse / launcher / aioimpl / asyncio / aiohttp_client.py View on Github external
import attr
from aiohttp import ClientRequest, hdrs, helpers
from async_exit_stack import AsyncExitStack
from async_generator import async_generator, asynccontextmanager, yield_
from async_lru import alru_cache
from oauthlib.oauth1 import Client as OAuth1Client
from pyrsistent import freeze
from yarl import URL

from studip_fuse.studipfs.api.aiobase import BaseHTTPClient
from studip_fuse.studipfs.api.aiointerface import Download

log = logging.getLogger(__name__)

async_stat = aiofiles.os.stat
async_utime = aiofiles.os.wrap(os.utime)


class AuthenticatedClientRequest(ClientRequest):
    def update_auth(self, auth):
        if auth is None:
            auth = self.auth
        if auth is None:
            return

        if isinstance(auth, helpers.BasicAuth):
            self.headers[hdrs.AUTHORIZATION] = auth.encode()
        elif isinstance(auth, OAuth1Client):
            url, headers, _ = auth.sign(
                str(self.url), str(self.method), None, self.headers
            )
            self.url = URL(url)