-
-
Notifications
You must be signed in to change notification settings - Fork 133
/
Copy pathprotocols.py
126 lines (98 loc) · 2.96 KB
/
protocols.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
"""OpenAPI core protocols module"""
from typing import Any
from typing import Mapping
from typing import Optional
from typing import Protocol
from typing import runtime_checkable
from openapi_core.datatypes import RequestParameters
@runtime_checkable
class BaseRequest(Protocol):
parameters: RequestParameters
@property
def method(self) -> str: ...
@property
def body(self) -> Optional[bytes]: ...
@property
def content_type(self) -> str: ...
@runtime_checkable
class Request(BaseRequest, Protocol):
"""Request attributes protocol.
Attributes:
host_url
Url with scheme and host
For example:
https://localhost:8000
path
Request path
full_url_pattern
The matched url with scheme, host and path pattern.
For example:
https://localhost:8000/api/v1/pets
https://localhost:8000/api/v1/pets/{pet_id}
method
The request method, as lowercase string.
parameters
A RequestParameters object. Needs to supports path attribute setter
to write resolved path parameters.
body
The request body, as string.
content_type
The content type with parameters (eg, charset, boundary etc.)
and always lowercase.
"""
@property
def host_url(self) -> str: ...
@property
def path(self) -> str: ...
@runtime_checkable
class WebhookRequest(BaseRequest, Protocol):
"""Webhook request attributes protocol.
Attributes:
name
Webhook name
method
The request method, as lowercase string.
parameters
A RequestParameters object. Needs to supports path attribute setter
to write resolved path parameters.
body
The request body, as string.
content_type
The content type with parameters (eg, charset, boundary etc.)
and always lowercase.
"""
@property
def name(self) -> str: ...
@runtime_checkable
class SupportsPathPattern(Protocol):
"""Supports path_pattern attribute protocol.
You also need to provide path variables in RequestParameters.
Attributes:
path_pattern
The matched path pattern.
For example:
/api/v1/pets/{pet_id}
"""
@property
def path_pattern(self) -> str: ...
@runtime_checkable
class Response(Protocol):
"""Response protocol.
Attributes:
data
The response body, as string.
status_code
The status code as integer.
headers
Response headers as Headers.
content_type
The content type with parameters and always lowercase.
"""
@property
def data(self) -> Optional[bytes]: ...
@property
def status_code(self) -> int: ...
@property
def content_type(self) -> str: ...
@property
def headers(self) -> Mapping[str, Any]: ...