File: responses.py

package info (click to toggle)
python-openapi-core 0.22.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,104 kB
  • sloc: python: 19,979; makefile: 44
file content (34 lines) | stat: -rw-r--r-- 971 bytes parent folder | download | duplicates (2)
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
"""OpenAPI core contrib aiohttp responses module"""

import multidict
from aiohttp import web


class AIOHTTPOpenAPIWebResponse:
    def __init__(self, response: web.Response):
        if not isinstance(response, web.Response):
            raise TypeError(
                f"'response' argument is not type of {web.Response.__qualname__!r}"
            )
        self.response = response

    @property
    def data(self) -> bytes:
        if self.response.body is None:
            return b""
        if isinstance(self.response.body, bytes):
            return self.response.body
        assert isinstance(self.response.body, str)
        return self.response.body.encode("utf-8")

    @property
    def status_code(self) -> int:
        return self.response.status

    @property
    def content_type(self) -> str:
        return self.response.content_type or ""

    @property
    def headers(self) -> multidict.CIMultiDict[str]:
        return self.response.headers