File: responses.py

package info (click to toggle)
python-openapi-core 0.19.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,008 kB
  • sloc: python: 18,868; makefile: 47
file content (28 lines) | stat: -rw-r--r-- 812 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
"""OpenAPI core contrib requests responses module"""

from requests import Response
from werkzeug.datastructures import Headers


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

    @property
    def data(self) -> bytes:
        assert isinstance(self.response.content, bytes)
        return self.response.content

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

    @property
    def content_type(self) -> str:
        return str(self.response.headers.get("Content-Type", ""))

    @property
    def headers(self) -> Headers:
        return Headers(dict(self.response.headers))