How to use the anyio.aopen function in anyio

To help you get started, we’ve selected a few anyio 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 theelous3 / asks / tests / test_multipart.py View on Github external
async def test_multipart_body_with_real_pre_opened_test_file(dummy_file_path):
    async with await aopen(dummy_file_path, "rb") as f:
        assert (
            await build_multipart_body(
                values=OrderedDict({"file": f,}),
                encoding="utf8",
                boundary_data="8banana133744910kmmr13a56!102!5649",
            )
            == b'--8banana133744910kmmr13a56!102!5649\r\nContent-Disposition: form-data; name="file"; filename="test.txt"\r\nContent-Type: text/plain\r\n\r\ndummyfile\n\r\n--8banana133744910kmmr13a56!102!5649--\r\n'
        )
github theelous3 / asks / tests / test_anyio.py View on Github external
async def test_multipart_send_single_already_open_async(server):
    async with await aopen(TEST_FILE1, "rb") as f:
        r = await asks.post(server.http_test_url, multipart={"file_1": f})
    j = r.json()

    assert any(file_data["name"] == "file_1" for file_data in j["files"])

    file_data = next(
        file_data for file_data in j["files"] if file_data["name"] == "file_1"
    )
    assert file_data["file"] == "Compooper"
github python-trio / hip / test / with_dummyserver / async_only / test_poolmanager.py View on Github external
async def test_upload_anyio_async_files(self, backend, anyio_backend):
        """Uploading a file opened via 'anyio.aopen()' should be possible"""
        with open(__file__, mode="rb") as f:
            data = f.read()
            content_length = len(data)

        headers = {
            "Content-Length": str(content_length),
        }
        url = "%s/echo" % self.base_url

        with PoolManager(backend=backend) as http:
            async with await anyio.aopen(__file__, mode="rb") as f:
                resp = await http.urlopen("PUT", url, headers=headers, body=f)
                assert resp.status == 200
                assert resp.data == data
github theelous3 / asks / asks / multipart.py View on Github external
async def to_bytes(self):
        binary_source = self.binary_source

        if isinstance(binary_source, Path):
            async with await aopen(binary_source, "rb") as f:
                return await f.read()

        if isinstance(binary_source, bytes):
            return binary_source

        # else we should have a BinaryIO or an async equivalent,
        # which we can't really type-check at runtime
        result = binary_source.read()

        if isinstance(result, bytes):
            return result

        # We must then assume it is a coroutine.
        return await result
github theelous3 / asks / asks / request_object.py View on Github external
async def _file_manager(self, path):
        async with await aopen(path, "rb") as f:
            return b"".join(await f.readlines()) + b"\r\n"