File: processors.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 (34 lines) | stat: -rw-r--r-- 1,253 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
from typing import Any
from typing import Optional

from jsonschema_path import SchemaPath

from openapi_core.protocols import Request
from openapi_core.unmarshalling.request.datatypes import RequestUnmarshalResult
from openapi_core.unmarshalling.request.protocols import RequestUnmarshaller
from openapi_core.unmarshalling.request.types import RequestUnmarshallerType


class RequestUnmarshallingProcessor:
    def __init__(
        self,
        spec: SchemaPath,
        request_unmarshaller_cls: RequestUnmarshallerType,
        **unmarshaller_kwargs: Any
    ) -> None:
        self.spec = spec
        self.request_unmarshaller_cls = request_unmarshaller_cls
        self.unmarshaller_kwargs = unmarshaller_kwargs

        self._request_unmarshaller_cached: Optional[RequestUnmarshaller] = None

    @property
    def request_unmarshaller(self) -> RequestUnmarshaller:
        if self._request_unmarshaller_cached is None:
            self._request_unmarshaller_cached = self.request_unmarshaller_cls(
                self.spec, **self.unmarshaller_kwargs
            )
        return self._request_unmarshaller_cached

    def process(self, request: Request) -> RequestUnmarshalResult:
        return self.request_unmarshaller.unmarshal(request)