File: awsrequest.py

package info (click to toggle)
python-aiobotocore 2.25.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,524 kB
  • sloc: python: 15,437; makefile: 84
file content (41 lines) | stat: -rw-r--r-- 1,118 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import botocore.utils
from botocore.awsrequest import AWSResponse


class AioAWSResponse(AWSResponse):
    # Unlike AWSResponse, these return awaitables

    async def _content_prop(self):
        """Content of the response as bytes."""

        if self._content is None:
            # NOTE: this will cache the data in self.raw
            self._content = await self.raw.read() or b''

        return self._content

    @property
    def content(self):
        return self._content_prop()

    async def _text_prop(self):
        encoding = botocore.utils.get_encoding_from_headers(self.headers)
        if encoding:
            return (await self.content).decode(encoding)
        else:
            return (await self.content).decode('utf-8')

    @property
    def text(self):
        return self._text_prop()


class HttpxAWSResponse(AioAWSResponse):
    async def _content_prop(self):
        """Content of the response as bytes."""

        if self._content is None:
            # NOTE: this will cache the data in self.raw
            self._content = await self.raw.aread() or b''

        return self._content