arkindex-client 1.1.1__py3-none-any.whl → 1.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- arkindex/client/client.py +179 -68
- arkindex/document.py +21 -105
- arkindex/schema/openapi.py +44 -292
- {arkindex_client-1.1.1.dist-info → arkindex_client-1.1.2.dist-info}/METADATA +2 -2
- {arkindex_client-1.1.1.dist-info → arkindex_client-1.1.2.dist-info}/RECORD +8 -11
- arkindex/client/base.py +0 -98
- arkindex/client/transports.py +0 -132
- arkindex/schema/jsonschema.py +0 -66
- {arkindex_client-1.1.1.dist-info → arkindex_client-1.1.2.dist-info}/LICENSE +0 -0
- {arkindex_client-1.1.1.dist-info → arkindex_client-1.1.2.dist-info}/WHEEL +0 -0
- {arkindex_client-1.1.1.dist-info → arkindex_client-1.1.2.dist-info}/top_level.txt +0 -0
arkindex/client/transports.py
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
import http
|
|
3
|
-
from importlib.metadata import version
|
|
4
|
-
|
|
5
|
-
import requests
|
|
6
|
-
|
|
7
|
-
from arkindex import exceptions
|
|
8
|
-
from arkindex.client import decoders
|
|
9
|
-
|
|
10
|
-
REQUEST_TIMEOUT = (30, 60)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class BlockAllCookies(http.cookiejar.CookiePolicy):
|
|
14
|
-
"""
|
|
15
|
-
A cookie policy that rejects all cookies.
|
|
16
|
-
Used to override the default `requests` behavior.
|
|
17
|
-
"""
|
|
18
|
-
|
|
19
|
-
return_ok = set_ok = domain_return_ok = path_return_ok = (
|
|
20
|
-
lambda self, *args, **kwargs: False
|
|
21
|
-
)
|
|
22
|
-
netscape = True
|
|
23
|
-
rfc2965 = hide_cookie2 = False
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class BaseTransport:
|
|
27
|
-
schemes = None
|
|
28
|
-
|
|
29
|
-
def send(self, method, url, query_params=None, content=None, encoding=None):
|
|
30
|
-
raise NotImplementedError()
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
class HTTPTransport(BaseTransport):
|
|
34
|
-
schemes = ["http", "https"]
|
|
35
|
-
default_decoders = [
|
|
36
|
-
decoders.JSONDecoder(),
|
|
37
|
-
decoders.TextDecoder(),
|
|
38
|
-
decoders.DownloadDecoder(),
|
|
39
|
-
]
|
|
40
|
-
|
|
41
|
-
def __init__(
|
|
42
|
-
self,
|
|
43
|
-
auth=None,
|
|
44
|
-
decoders=None,
|
|
45
|
-
headers=None,
|
|
46
|
-
session=None,
|
|
47
|
-
allow_cookies=True,
|
|
48
|
-
verify=True,
|
|
49
|
-
):
|
|
50
|
-
if session is None:
|
|
51
|
-
session = requests.Session()
|
|
52
|
-
if auth is not None:
|
|
53
|
-
session.auth = auth
|
|
54
|
-
if not allow_cookies:
|
|
55
|
-
session.cookies.set_policy(BlockAllCookies())
|
|
56
|
-
|
|
57
|
-
self.session = session
|
|
58
|
-
self.verify = verify
|
|
59
|
-
self.decoders = list(decoders) if decoders else list(self.default_decoders)
|
|
60
|
-
|
|
61
|
-
client_version = version("arkindex-client")
|
|
62
|
-
self.headers = {
|
|
63
|
-
"accept": ", ".join([decoder.media_type for decoder in self.decoders]),
|
|
64
|
-
"user-agent": f"arkindex-client/{client_version}",
|
|
65
|
-
}
|
|
66
|
-
if headers:
|
|
67
|
-
self.headers.update({key.lower(): value for key, value in headers.items()})
|
|
68
|
-
|
|
69
|
-
def send(self, method, url, query_params=None, content=None, encoding=None):
|
|
70
|
-
options = self.get_request_options(query_params, content, encoding)
|
|
71
|
-
response = self.session.request(method, url, **options)
|
|
72
|
-
result = self.decode_response_content(response)
|
|
73
|
-
|
|
74
|
-
if 400 <= response.status_code <= 599:
|
|
75
|
-
title = "%d %s" % (response.status_code, response.reason)
|
|
76
|
-
raise exceptions.ErrorResponse(
|
|
77
|
-
title=title, status_code=response.status_code, content=result
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
return result
|
|
81
|
-
|
|
82
|
-
def get_decoder(self, content_type=None):
|
|
83
|
-
"""
|
|
84
|
-
Given the value of a 'Content-Type' header, return the appropriate
|
|
85
|
-
decoder for handling the response content.
|
|
86
|
-
"""
|
|
87
|
-
if content_type is None:
|
|
88
|
-
return self.decoders[0]
|
|
89
|
-
|
|
90
|
-
content_type = content_type.split(";")[0].strip().lower()
|
|
91
|
-
main_type = content_type.split("/")[0] + "/*"
|
|
92
|
-
wildcard_type = "*/*"
|
|
93
|
-
|
|
94
|
-
for codec in self.decoders:
|
|
95
|
-
if codec.media_type in (content_type, main_type, wildcard_type):
|
|
96
|
-
return codec
|
|
97
|
-
|
|
98
|
-
text = (
|
|
99
|
-
"Unsupported encoding '%s' in response Content-Type header." % content_type
|
|
100
|
-
)
|
|
101
|
-
message = exceptions.ErrorMessage(text=text, code="cannot-decode-response")
|
|
102
|
-
raise exceptions.ClientError(messages=[message])
|
|
103
|
-
|
|
104
|
-
def get_request_options(self, query_params=None, content=None, encoding=None):
|
|
105
|
-
"""
|
|
106
|
-
Return the 'options' for sending the outgoing request.
|
|
107
|
-
"""
|
|
108
|
-
options = {
|
|
109
|
-
"headers": dict(self.headers),
|
|
110
|
-
"params": query_params,
|
|
111
|
-
"timeout": REQUEST_TIMEOUT,
|
|
112
|
-
"verify": self.verify,
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if content is not None:
|
|
116
|
-
assert (
|
|
117
|
-
encoding == "application/json"
|
|
118
|
-
), "Only JSON request bodies are supported"
|
|
119
|
-
options["json"] = content
|
|
120
|
-
|
|
121
|
-
return options
|
|
122
|
-
|
|
123
|
-
def decode_response_content(self, response):
|
|
124
|
-
"""
|
|
125
|
-
Given an HTTP response, return the decoded data.
|
|
126
|
-
"""
|
|
127
|
-
if not response.content:
|
|
128
|
-
return None
|
|
129
|
-
|
|
130
|
-
content_type = response.headers.get("content-type")
|
|
131
|
-
decoder = self.get_decoder(content_type)
|
|
132
|
-
return decoder.decode(response)
|
arkindex/schema/jsonschema.py
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
import typesystem
|
|
3
|
-
|
|
4
|
-
definitions = typesystem.SchemaDefinitions()
|
|
5
|
-
|
|
6
|
-
JSON_SCHEMA = (
|
|
7
|
-
typesystem.Object(
|
|
8
|
-
properties={
|
|
9
|
-
"$ref": typesystem.String(),
|
|
10
|
-
"type": typesystem.String() | typesystem.Array(items=typesystem.String()),
|
|
11
|
-
"enum": typesystem.Array(unique_items=True, min_items=1),
|
|
12
|
-
"definitions": typesystem.Object(
|
|
13
|
-
additional_properties=typesystem.Reference(
|
|
14
|
-
"JSONSchema", definitions=definitions
|
|
15
|
-
)
|
|
16
|
-
),
|
|
17
|
-
# String
|
|
18
|
-
"minLength": typesystem.Integer(minimum=0),
|
|
19
|
-
"maxLength": typesystem.Integer(minimum=0),
|
|
20
|
-
"pattern": typesystem.String(format="regex"),
|
|
21
|
-
"format": typesystem.String(),
|
|
22
|
-
# Numeric
|
|
23
|
-
"minimum": typesystem.Number(),
|
|
24
|
-
"maximum": typesystem.Number(),
|
|
25
|
-
"exclusiveMinimum": typesystem.Number(),
|
|
26
|
-
"exclusiveMaximum": typesystem.Number(),
|
|
27
|
-
"multipleOf": typesystem.Number(exclusive_minimum=0),
|
|
28
|
-
# Object
|
|
29
|
-
"properties": typesystem.Object(
|
|
30
|
-
additional_properties=typesystem.Reference(
|
|
31
|
-
"JSONSchema", definitions=definitions
|
|
32
|
-
)
|
|
33
|
-
),
|
|
34
|
-
"minProperties": typesystem.Integer(minimum=0),
|
|
35
|
-
"maxProperties": typesystem.Integer(minimum=0),
|
|
36
|
-
"patternProperties": typesystem.Object(
|
|
37
|
-
additional_properties=typesystem.Reference(
|
|
38
|
-
"JSONSchema", definitions=definitions
|
|
39
|
-
)
|
|
40
|
-
),
|
|
41
|
-
"additionalProperties": (
|
|
42
|
-
typesystem.Reference("JSONSchema", definitions=definitions)
|
|
43
|
-
| typesystem.Boolean()
|
|
44
|
-
),
|
|
45
|
-
"required": typesystem.Array(items=typesystem.String(), unique_items=True),
|
|
46
|
-
# Array
|
|
47
|
-
"items": (
|
|
48
|
-
typesystem.Reference("JSONSchema", definitions=definitions)
|
|
49
|
-
| typesystem.Array(
|
|
50
|
-
items=typesystem.Reference("JSONSchema", definitions=definitions),
|
|
51
|
-
min_items=1,
|
|
52
|
-
)
|
|
53
|
-
),
|
|
54
|
-
"additionalItems": (
|
|
55
|
-
typesystem.Reference("JSONSchema", definitions=definitions)
|
|
56
|
-
| typesystem.Boolean()
|
|
57
|
-
),
|
|
58
|
-
"minItems": typesystem.Integer(minimum=0),
|
|
59
|
-
"maxItems": typesystem.Integer(minimum=0),
|
|
60
|
-
"uniqueItems": typesystem.Boolean(),
|
|
61
|
-
}
|
|
62
|
-
)
|
|
63
|
-
| typesystem.Boolean()
|
|
64
|
-
)
|
|
65
|
-
|
|
66
|
-
definitions["JSONSchema"] = JSON_SCHEMA
|
|
File without changes
|
|
File without changes
|
|
File without changes
|