apytizer 0.0.1a0__py3-none-any.whl → 0.0.1b1__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.
- apytizer/__init__.py +2 -12
- apytizer/adapters/__init__.py +2 -3
- apytizer/adapters/transport_adapter.py +91 -0
- apytizer/apis/__init__.py +6 -0
- apytizer/apis/abstract_api.py +36 -0
- apytizer/apis/web_api.py +461 -0
- apytizer/connections/__init__.py +6 -0
- apytizer/connections/abstract_connection.py +28 -0
- apytizer/connections/http_connection.py +431 -0
- apytizer/decorators/__init__.py +5 -5
- apytizer/decorators/caching.py +60 -9
- apytizer/decorators/chunking.py +105 -0
- apytizer/decorators/connection.py +55 -20
- apytizer/decorators/json_response.py +93 -0
- apytizer/decorators/pagination.py +50 -32
- apytizer/endpoints/__init__.py +6 -0
- apytizer/endpoints/abstract_endpoint.py +38 -0
- apytizer/endpoints/web_endpoint.py +519 -0
- apytizer/engines/__init__.py +6 -0
- apytizer/engines/abstract_engine.py +45 -0
- apytizer/engines/http_engine.py +129 -0
- apytizer/errors.py +34 -0
- apytizer/factories/__init__.py +5 -0
- apytizer/factories/abstract_factory.py +17 -0
- apytizer/http_methods.py +34 -0
- apytizer/managers/__init__.py +12 -0
- apytizer/managers/abstract_manager.py +80 -0
- apytizer/managers/base_manager.py +116 -0
- apytizer/mappers/__init__.py +6 -0
- apytizer/mappers/abstract_mapper.py +48 -0
- apytizer/mappers/base_mapper.py +78 -0
- apytizer/media_types.py +118 -0
- apytizer/models/__init__.py +6 -0
- apytizer/models/abstract_model.py +119 -0
- apytizer/models/base_model.py +85 -0
- apytizer/protocols.py +38 -0
- apytizer/repositories/__init__.py +6 -0
- apytizer/repositories/abstract_repository.py +81 -0
- apytizer/repositories/managed_repository.py +92 -0
- apytizer/routes/__init__.py +6 -0
- apytizer/routes/abstract_route.py +32 -0
- apytizer/routes/base_route.py +138 -0
- apytizer/sessions/__init__.py +33 -0
- apytizer/sessions/abstract_session.py +63 -0
- apytizer/sessions/requests_session.py +125 -0
- apytizer/states/__init__.py +6 -0
- apytizer/states/abstract_state.py +71 -0
- apytizer/states/local_state.py +99 -0
- apytizer/utils/__init__.py +9 -4
- apytizer/utils/caching.py +39 -0
- apytizer/utils/dictionaries.py +375 -0
- apytizer/utils/errors.py +104 -0
- apytizer/utils/iterables.py +91 -0
- apytizer/utils/objects.py +145 -0
- apytizer/utils/strings.py +69 -0
- apytizer/utils/typing.py +29 -0
- apytizer-0.0.1b1.dist-info/METADATA +41 -0
- apytizer-0.0.1b1.dist-info/RECORD +60 -0
- {apytizer-0.0.1a0.dist-info → apytizer-0.0.1b1.dist-info}/WHEEL +1 -2
- apytizer/abstracts/__init__.py +0 -8
- apytizer/abstracts/api.py +0 -147
- apytizer/abstracts/endpoint.py +0 -177
- apytizer/abstracts/model.py +0 -50
- apytizer/abstracts/session.py +0 -39
- apytizer/adapters/transport.py +0 -40
- apytizer/base/__init__.py +0 -8
- apytizer/base/api.py +0 -510
- apytizer/base/endpoint.py +0 -443
- apytizer/base/model.py +0 -119
- apytizer/decorators/json.py +0 -35
- apytizer/utils/generate_key.py +0 -18
- apytizer/utils/merge.py +0 -19
- apytizer-0.0.1a0.dist-info/METADATA +0 -27
- apytizer-0.0.1a0.dist-info/RECORD +0 -25
- apytizer-0.0.1a0.dist-info/top_level.txt +0 -1
- {apytizer-0.0.1a0.dist-info → apytizer-0.0.1b1.dist-info/licenses}/LICENSE +0 -0
apytizer/base/endpoint.py
DELETED
|
@@ -1,443 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""Basic endpoint class.
|
|
3
|
-
|
|
4
|
-
This module defines a basic endpoint class implementation.
|
|
5
|
-
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
# Standard Library Imports
|
|
9
|
-
from __future__ import annotations
|
|
10
|
-
import logging
|
|
11
|
-
from typing import Dict, List, MutableMapping, Union
|
|
12
|
-
|
|
13
|
-
# Third-Party Imports
|
|
14
|
-
import requests
|
|
15
|
-
|
|
16
|
-
# Local Imports
|
|
17
|
-
from ..abstracts.api import AbstractAPI
|
|
18
|
-
from ..abstracts.endpoint import AbstractEndpoint
|
|
19
|
-
from ..decorators.caching import cache_response
|
|
20
|
-
from ..utils import merge
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
# Initialize logger.
|
|
24
|
-
log = logging.getLogger(__name__)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
class BasicEndpoint(AbstractEndpoint):
|
|
28
|
-
"""
|
|
29
|
-
Class for interacting with an API endpoint.
|
|
30
|
-
|
|
31
|
-
Args:
|
|
32
|
-
path: Relative URL path for endpoint.
|
|
33
|
-
headers (optional): Headers to set globally for endpoint.
|
|
34
|
-
params (optional): Parameters to set globally for endpoint.
|
|
35
|
-
methods (optional): List of HTTP methods accepted by endpoint.
|
|
36
|
-
cache (optional): Mutable mapping for caching responses.
|
|
37
|
-
|
|
38
|
-
Attributes:
|
|
39
|
-
uri: Endpoint URL.
|
|
40
|
-
|
|
41
|
-
"""
|
|
42
|
-
|
|
43
|
-
def __init__(
|
|
44
|
-
self,
|
|
45
|
-
api: AbstractAPI,
|
|
46
|
-
path: str,
|
|
47
|
-
*,
|
|
48
|
-
headers: Dict = None,
|
|
49
|
-
params: Dict = None,
|
|
50
|
-
methods: List[str] = None,
|
|
51
|
-
cache: MutableMapping = None,
|
|
52
|
-
):
|
|
53
|
-
self.api = api
|
|
54
|
-
self.path = path if path[0] != "/" else path[1:]
|
|
55
|
-
self.headers = headers
|
|
56
|
-
self.params = params
|
|
57
|
-
self.methods = methods
|
|
58
|
-
self.cache = cache
|
|
59
|
-
|
|
60
|
-
def __call__(
|
|
61
|
-
self,
|
|
62
|
-
ref: Union[int, str],
|
|
63
|
-
*,
|
|
64
|
-
headers: Dict = None,
|
|
65
|
-
params: Dict = None,
|
|
66
|
-
methods: List[str] = None,
|
|
67
|
-
cache: MutableMapping = None
|
|
68
|
-
) -> BasicEndpoint:
|
|
69
|
-
"""
|
|
70
|
-
Returns a new endpoint with the appended reference.
|
|
71
|
-
|
|
72
|
-
This method is a shortcut for accessing HTTP methods on a
|
|
73
|
-
child endpoint or a nested resource.
|
|
74
|
-
|
|
75
|
-
Args:
|
|
76
|
-
ref: Reference for a collection or nested resource.
|
|
77
|
-
headers (optional) : Headers to set globally for endpoint.
|
|
78
|
-
params (optional) : Parameters to set globally for endpoint.
|
|
79
|
-
methods (optional): List of HTTP methods accepted by endpoint.
|
|
80
|
-
cache (optional): Mutable mapping for caching responses.
|
|
81
|
-
|
|
82
|
-
Returns:
|
|
83
|
-
BasicEndpoint instance.
|
|
84
|
-
|
|
85
|
-
"""
|
|
86
|
-
if isinstance(ref, (int, str)):
|
|
87
|
-
endpoint = BasicEndpoint(
|
|
88
|
-
self.api,
|
|
89
|
-
f'{self.path!s}/{ref!s}',
|
|
90
|
-
headers=headers,
|
|
91
|
-
params=params,
|
|
92
|
-
methods=methods,
|
|
93
|
-
cache=cache,
|
|
94
|
-
)
|
|
95
|
-
else:
|
|
96
|
-
raise TypeError
|
|
97
|
-
|
|
98
|
-
return endpoint
|
|
99
|
-
|
|
100
|
-
def __getitem__(self, ref: Union[int, str]) -> BasicEndpoint:
|
|
101
|
-
"""
|
|
102
|
-
Returns a new endpoint with the appended reference.
|
|
103
|
-
|
|
104
|
-
This method is a shortcut for accessing HTTP methods on a
|
|
105
|
-
child endpoint or a nested resource.
|
|
106
|
-
|
|
107
|
-
Args:
|
|
108
|
-
ref: Reference for a collection or nested resource.
|
|
109
|
-
|
|
110
|
-
Returns:
|
|
111
|
-
BasicEndpoint instance.
|
|
112
|
-
|
|
113
|
-
"""
|
|
114
|
-
if isinstance(ref, (int, str)):
|
|
115
|
-
endpoint = BasicEndpoint(
|
|
116
|
-
self.api,
|
|
117
|
-
f'{self.path!s}/{ref!s}'
|
|
118
|
-
)
|
|
119
|
-
else:
|
|
120
|
-
raise TypeError
|
|
121
|
-
|
|
122
|
-
return endpoint
|
|
123
|
-
|
|
124
|
-
def __add__(self, path: Union[int, str]) -> BasicEndpoint:
|
|
125
|
-
"""
|
|
126
|
-
Returns a new endpoint after combining both paths.
|
|
127
|
-
|
|
128
|
-
This is a method for quickly accessing HTTP methods for
|
|
129
|
-
child endpoints or nested resources. It behaves the same
|
|
130
|
-
as the __truediv__ method.
|
|
131
|
-
|
|
132
|
-
Args:
|
|
133
|
-
path: Value to append to the current path.
|
|
134
|
-
|
|
135
|
-
Returns:
|
|
136
|
-
BasicEndpoint instance.
|
|
137
|
-
|
|
138
|
-
"""
|
|
139
|
-
if isinstance(path, (int, str)):
|
|
140
|
-
endpoint = BasicEndpoint(
|
|
141
|
-
self.api,
|
|
142
|
-
f'{self.path!s}/{path!s}'
|
|
143
|
-
)
|
|
144
|
-
else:
|
|
145
|
-
raise TypeError
|
|
146
|
-
|
|
147
|
-
return endpoint
|
|
148
|
-
|
|
149
|
-
def __truediv__(self, path: Union[int, str]) -> BasicEndpoint:
|
|
150
|
-
"""
|
|
151
|
-
Returns a new endpoint after combining both paths.
|
|
152
|
-
|
|
153
|
-
This is a method for quickly accessing HTTP methods for
|
|
154
|
-
child endpoints or nested resources. It behaves the same
|
|
155
|
-
as the __add__ method.
|
|
156
|
-
|
|
157
|
-
Args:
|
|
158
|
-
path: Value to append to the current path.
|
|
159
|
-
|
|
160
|
-
Returns:
|
|
161
|
-
BasicEndpoint instance.
|
|
162
|
-
|
|
163
|
-
"""
|
|
164
|
-
if isinstance(path, (int, str)):
|
|
165
|
-
endpoint = BasicEndpoint(
|
|
166
|
-
self.api,
|
|
167
|
-
f'{self.path!s}/{path!s}'
|
|
168
|
-
)
|
|
169
|
-
else:
|
|
170
|
-
raise TypeError
|
|
171
|
-
|
|
172
|
-
return endpoint
|
|
173
|
-
|
|
174
|
-
@cache_response
|
|
175
|
-
def head(
|
|
176
|
-
self,
|
|
177
|
-
headers: Dict = None,
|
|
178
|
-
params: Dict = None,
|
|
179
|
-
**kwargs
|
|
180
|
-
) -> requests.Response:
|
|
181
|
-
"""
|
|
182
|
-
Sends an HTTP HEAD request to API endpoint.
|
|
183
|
-
|
|
184
|
-
Args:
|
|
185
|
-
headers (optional): Request headers (overrides global headers).
|
|
186
|
-
params (optional): Request parameters (overrides global parameters).
|
|
187
|
-
**kwargs: Data or parameters to include in request.
|
|
188
|
-
|
|
189
|
-
Returns:
|
|
190
|
-
Response object.
|
|
191
|
-
|
|
192
|
-
.. _MDN Web Docs:
|
|
193
|
-
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD
|
|
194
|
-
|
|
195
|
-
"""
|
|
196
|
-
|
|
197
|
-
if self.methods and 'HEAD' not in self.methods:
|
|
198
|
-
raise NotImplementedError
|
|
199
|
-
|
|
200
|
-
response = self.api.head(
|
|
201
|
-
self.path,
|
|
202
|
-
headers=merge(self.headers, headers),
|
|
203
|
-
params=merge(self.params, params),
|
|
204
|
-
**kwargs
|
|
205
|
-
)
|
|
206
|
-
return response
|
|
207
|
-
|
|
208
|
-
@cache_response
|
|
209
|
-
def get(
|
|
210
|
-
self,
|
|
211
|
-
headers: Dict = None,
|
|
212
|
-
params: Dict = None,
|
|
213
|
-
**kwargs
|
|
214
|
-
) -> requests.Response:
|
|
215
|
-
"""
|
|
216
|
-
Sends an HTTP GET request to API endpoint.
|
|
217
|
-
|
|
218
|
-
Args:
|
|
219
|
-
headers (optional): Request headers (overrides global headers).
|
|
220
|
-
params (optional): Request parameters (overrides global parameters).
|
|
221
|
-
**kwargs: Data or parameters to include in request.
|
|
222
|
-
|
|
223
|
-
Returns:
|
|
224
|
-
Response object.
|
|
225
|
-
|
|
226
|
-
.. _MDN Web Docs:
|
|
227
|
-
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET
|
|
228
|
-
|
|
229
|
-
"""
|
|
230
|
-
|
|
231
|
-
if self.methods and 'GET' not in self.methods:
|
|
232
|
-
raise NotImplementedError
|
|
233
|
-
|
|
234
|
-
response = self.api.get(
|
|
235
|
-
self.path,
|
|
236
|
-
headers=merge(self.headers, headers),
|
|
237
|
-
params=merge(self.params, params),
|
|
238
|
-
**kwargs
|
|
239
|
-
)
|
|
240
|
-
return response
|
|
241
|
-
|
|
242
|
-
@cache_response
|
|
243
|
-
def post(
|
|
244
|
-
self,
|
|
245
|
-
headers: Dict = None,
|
|
246
|
-
params: Dict = None,
|
|
247
|
-
**kwargs
|
|
248
|
-
) -> requests.Response:
|
|
249
|
-
"""
|
|
250
|
-
Sends an HTTP POST request to API endpoint.
|
|
251
|
-
|
|
252
|
-
Args:
|
|
253
|
-
headers (optional): Request headers (overrides global headers).
|
|
254
|
-
params (optional): Request parameters (overrides global parameters).
|
|
255
|
-
**kwargs: Data or parameters to include in request.
|
|
256
|
-
|
|
257
|
-
Returns:
|
|
258
|
-
Response object.
|
|
259
|
-
|
|
260
|
-
.. _MDN Web Docs:
|
|
261
|
-
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
|
|
262
|
-
|
|
263
|
-
"""
|
|
264
|
-
|
|
265
|
-
if self.methods and 'POST' not in self.methods:
|
|
266
|
-
raise NotImplementedError
|
|
267
|
-
|
|
268
|
-
response = self.api.post(
|
|
269
|
-
self.path,
|
|
270
|
-
headers=merge(self.headers, headers),
|
|
271
|
-
params=merge(self.params, params),
|
|
272
|
-
**kwargs
|
|
273
|
-
)
|
|
274
|
-
return response
|
|
275
|
-
|
|
276
|
-
@cache_response
|
|
277
|
-
def put(
|
|
278
|
-
self,
|
|
279
|
-
headers: Dict = None,
|
|
280
|
-
params: Dict = None,
|
|
281
|
-
**kwargs
|
|
282
|
-
) -> requests.Response:
|
|
283
|
-
"""
|
|
284
|
-
Sends an HTTP PUT request to API endpoint.
|
|
285
|
-
|
|
286
|
-
Args:
|
|
287
|
-
headers (optional): Request headers (overrides global headers).
|
|
288
|
-
params (optional): Request parameters (overrides global parameters).
|
|
289
|
-
**kwargs: Data or parameters to include in request.
|
|
290
|
-
|
|
291
|
-
Returns:
|
|
292
|
-
Response object.
|
|
293
|
-
|
|
294
|
-
.. _MDN Web Docs:
|
|
295
|
-
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT
|
|
296
|
-
|
|
297
|
-
"""
|
|
298
|
-
|
|
299
|
-
if self.methods and 'PUT' not in self.methods:
|
|
300
|
-
raise NotImplementedError
|
|
301
|
-
|
|
302
|
-
response = self.api.put(
|
|
303
|
-
self.path,
|
|
304
|
-
headers=merge(self.headers, headers),
|
|
305
|
-
params=merge(self.params, params),
|
|
306
|
-
**kwargs
|
|
307
|
-
)
|
|
308
|
-
return response
|
|
309
|
-
|
|
310
|
-
@cache_response
|
|
311
|
-
def patch(
|
|
312
|
-
self,
|
|
313
|
-
headers: Dict = None,
|
|
314
|
-
params: Dict = None,
|
|
315
|
-
**kwargs
|
|
316
|
-
) -> requests.Response:
|
|
317
|
-
"""
|
|
318
|
-
Sends an HTTP PATCH request to API endpoint.
|
|
319
|
-
|
|
320
|
-
Args:
|
|
321
|
-
headers (optional): Request headers (overrides global headers).
|
|
322
|
-
params (optional): Request parameters (overrides global parameters).
|
|
323
|
-
**kwargs: Data or parameters to include in request.
|
|
324
|
-
|
|
325
|
-
Returns:
|
|
326
|
-
Response object.
|
|
327
|
-
|
|
328
|
-
.. _MDN Web Docs:
|
|
329
|
-
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH
|
|
330
|
-
|
|
331
|
-
"""
|
|
332
|
-
|
|
333
|
-
if self.methods and 'PATCH' not in self.methods:
|
|
334
|
-
raise NotImplementedError
|
|
335
|
-
|
|
336
|
-
response = self.api.patch(
|
|
337
|
-
self.path,
|
|
338
|
-
headers=merge(self.headers, headers),
|
|
339
|
-
params=merge(self.params, params),
|
|
340
|
-
**kwargs
|
|
341
|
-
)
|
|
342
|
-
return response
|
|
343
|
-
|
|
344
|
-
@cache_response
|
|
345
|
-
def delete(
|
|
346
|
-
self,
|
|
347
|
-
headers: Dict = None,
|
|
348
|
-
params: Dict = None,
|
|
349
|
-
**kwargs
|
|
350
|
-
) -> requests.Response:
|
|
351
|
-
"""
|
|
352
|
-
Sends an HTTP DELETE request to API endpoint.
|
|
353
|
-
|
|
354
|
-
Args:
|
|
355
|
-
headers (optional): Request headers (overrides global headers).
|
|
356
|
-
params (optional): Request parameters (overrides global parameters).
|
|
357
|
-
**kwargs: Data or parameters to include in request.
|
|
358
|
-
|
|
359
|
-
Returns:
|
|
360
|
-
Response object.
|
|
361
|
-
|
|
362
|
-
.. _MDN Web Docs:
|
|
363
|
-
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE
|
|
364
|
-
|
|
365
|
-
"""
|
|
366
|
-
|
|
367
|
-
if self.methods and 'DELETE' not in self.methods:
|
|
368
|
-
raise NotImplementedError
|
|
369
|
-
|
|
370
|
-
response = self.api.delete(
|
|
371
|
-
self.path,
|
|
372
|
-
headers=merge(self.headers, headers),
|
|
373
|
-
params=merge(self.params, params),
|
|
374
|
-
**kwargs
|
|
375
|
-
)
|
|
376
|
-
return response
|
|
377
|
-
|
|
378
|
-
@cache_response
|
|
379
|
-
def options(
|
|
380
|
-
self,
|
|
381
|
-
headers: Dict = None,
|
|
382
|
-
params: Dict = None,
|
|
383
|
-
**kwargs
|
|
384
|
-
) -> requests.Response:
|
|
385
|
-
"""
|
|
386
|
-
Sends an HTTP OPTIONS request to API endpoint.
|
|
387
|
-
|
|
388
|
-
Args:
|
|
389
|
-
headers (optional): Request headers (overrides global headers).
|
|
390
|
-
params (optional): Request parameters (overrides global parameters).
|
|
391
|
-
**kwargs: Data or parameters to include in request.
|
|
392
|
-
|
|
393
|
-
Returns:
|
|
394
|
-
Response object.
|
|
395
|
-
|
|
396
|
-
.. _MDN Web Docs:
|
|
397
|
-
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS
|
|
398
|
-
|
|
399
|
-
"""
|
|
400
|
-
if self.methods and 'OPTIONS' not in self.methods:
|
|
401
|
-
raise NotImplementedError
|
|
402
|
-
|
|
403
|
-
response = self.api.options(
|
|
404
|
-
self.path,
|
|
405
|
-
headers=merge(self.headers, headers),
|
|
406
|
-
params=merge(self.params, params),
|
|
407
|
-
**kwargs
|
|
408
|
-
)
|
|
409
|
-
return response
|
|
410
|
-
|
|
411
|
-
@cache_response
|
|
412
|
-
def trace(
|
|
413
|
-
self,
|
|
414
|
-
headers: Dict = None,
|
|
415
|
-
params: Dict = None,
|
|
416
|
-
**kwargs
|
|
417
|
-
) -> requests.Response:
|
|
418
|
-
"""
|
|
419
|
-
Sends an HTTP TRACE request to API endpoint.
|
|
420
|
-
|
|
421
|
-
Args:
|
|
422
|
-
headers (optional): Request headers (overrides global headers).
|
|
423
|
-
params (optional): Request parameters (overrides global parameters).
|
|
424
|
-
**kwargs: Data or parameters to include in request.
|
|
425
|
-
|
|
426
|
-
Returns:
|
|
427
|
-
Response object.
|
|
428
|
-
|
|
429
|
-
.. _MDN Web Docs:
|
|
430
|
-
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/TRACE
|
|
431
|
-
|
|
432
|
-
"""
|
|
433
|
-
|
|
434
|
-
if self.methods and 'TRACE' not in self.methods:
|
|
435
|
-
raise NotImplementedError
|
|
436
|
-
|
|
437
|
-
response = self.api.trace(
|
|
438
|
-
self.path,
|
|
439
|
-
headers=merge(self.headers, headers),
|
|
440
|
-
params=merge(self.params, params),
|
|
441
|
-
**kwargs
|
|
442
|
-
)
|
|
443
|
-
return response
|
apytizer/base/model.py
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""Basic model class.
|
|
3
|
-
|
|
4
|
-
This module defines the implementation of a basic model class.
|
|
5
|
-
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
# Standard Library Imports
|
|
9
|
-
from __future__ import annotations
|
|
10
|
-
import collections
|
|
11
|
-
import functools
|
|
12
|
-
import logging
|
|
13
|
-
from typing import Any, List, Mapping, Tuple, Union
|
|
14
|
-
|
|
15
|
-
# Local Imports
|
|
16
|
-
from ..abstracts.model import AbstractModel
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
# Initialize logger.
|
|
20
|
-
log = logging.getLogger(__name__)
|
|
21
|
-
|
|
22
|
-
# Define custom types.
|
|
23
|
-
AttributeKey = Union[List[str], str, Tuple[str]]
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class BasicModel(AbstractModel):
|
|
27
|
-
"""
|
|
28
|
-
Class for representing a basic object model.
|
|
29
|
-
|
|
30
|
-
Args:
|
|
31
|
-
**kwargs: Data with which to set model state.
|
|
32
|
-
|
|
33
|
-
"""
|
|
34
|
-
state: collections.ChainMap
|
|
35
|
-
|
|
36
|
-
def __init__(self, **kwargs):
|
|
37
|
-
self.state = collections.ChainMap({}, kwargs)
|
|
38
|
-
|
|
39
|
-
def __contains__(self, key: str) -> bool:
|
|
40
|
-
return key in self.state
|
|
41
|
-
|
|
42
|
-
def __eq__(self, other: AbstractModel) -> bool:
|
|
43
|
-
return dict(other) == dict(self) if isinstance(other, self.__class__) else False
|
|
44
|
-
|
|
45
|
-
def __getattr__(self, name: str) -> Any:
|
|
46
|
-
attr = self.get(name)
|
|
47
|
-
if not attr:
|
|
48
|
-
cls = self.__class__.__name__
|
|
49
|
-
message = f"type object '{cls!s}' has no attribute '{attr!s}'"
|
|
50
|
-
raise AttributeError(message)
|
|
51
|
-
return attr
|
|
52
|
-
|
|
53
|
-
def __getitem__(self, key: AttributeKey) -> Any:
|
|
54
|
-
return self.get(key)
|
|
55
|
-
|
|
56
|
-
def __iter__(self):
|
|
57
|
-
yield from self.state.items()
|
|
58
|
-
|
|
59
|
-
def __repr__(self) -> str:
|
|
60
|
-
return f"{self.__class__.__name__}({self.state!s})"
|
|
61
|
-
|
|
62
|
-
def commit(self) -> None:
|
|
63
|
-
"""
|
|
64
|
-
Commits changes to local state.
|
|
65
|
-
|
|
66
|
-
"""
|
|
67
|
-
if self.state.maps[0]:
|
|
68
|
-
self.state = self.state.new_child()
|
|
69
|
-
|
|
70
|
-
def get(self, key: AttributeKey, default = None) -> Any:
|
|
71
|
-
"""
|
|
72
|
-
Get value for key(s) in local state.
|
|
73
|
-
|
|
74
|
-
Function allows lookups even within nested dictionaries. When passed multiple keys,
|
|
75
|
-
either separated by periods or as a list or tuple, the function looks up each key
|
|
76
|
-
in sequence.
|
|
77
|
-
|
|
78
|
-
Args:
|
|
79
|
-
key: Key(s) to use to retrieve value.
|
|
80
|
-
|
|
81
|
-
Returns:
|
|
82
|
-
Value for key in state.
|
|
83
|
-
|
|
84
|
-
"""
|
|
85
|
-
if (isinstance(key, (list, tuple))) \
|
|
86
|
-
and all(isinstance(k, str) for k in key):
|
|
87
|
-
key = '.'.join(key)
|
|
88
|
-
|
|
89
|
-
if not isinstance(key, str):
|
|
90
|
-
raise TypeError
|
|
91
|
-
|
|
92
|
-
value = functools.reduce(
|
|
93
|
-
lambda data, key: data.get(key, default) \
|
|
94
|
-
if isinstance(data, (collections.ChainMap, dict)) \
|
|
95
|
-
else data if data else default,
|
|
96
|
-
key.split('.'),
|
|
97
|
-
self.state
|
|
98
|
-
)
|
|
99
|
-
return value
|
|
100
|
-
|
|
101
|
-
def update(self, __m: Mapping = None, **kwargs) -> None:
|
|
102
|
-
"""
|
|
103
|
-
Update local state of model with provided data.
|
|
104
|
-
|
|
105
|
-
Args:
|
|
106
|
-
__m (optional): Mapping with which to update local state.
|
|
107
|
-
**kwargs: Data with which to update local state.
|
|
108
|
-
|
|
109
|
-
"""
|
|
110
|
-
# TODO: Develop method for recursively updating nested dictionaries in local state.
|
|
111
|
-
self.state.update(__m, **kwargs)
|
|
112
|
-
return self
|
|
113
|
-
|
|
114
|
-
def rollback(self) -> None:
|
|
115
|
-
"""
|
|
116
|
-
Rollback changes to local state.
|
|
117
|
-
|
|
118
|
-
"""
|
|
119
|
-
self.state.clear()
|
apytizer/decorators/json.py
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
|
|
3
|
-
# Standard Library Imports
|
|
4
|
-
import functools
|
|
5
|
-
import logging
|
|
6
|
-
from typing import Callable, Dict, List, Union
|
|
7
|
-
|
|
8
|
-
# Third-Party Importd
|
|
9
|
-
from requests import Response
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
log = logging.getLogger(__name__)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def json_response(func: Callable) -> Callable:
|
|
16
|
-
"""
|
|
17
|
-
Automatically parses a JSON response.
|
|
18
|
-
|
|
19
|
-
Args:
|
|
20
|
-
func: Function to decorate.
|
|
21
|
-
|
|
22
|
-
Returns:
|
|
23
|
-
Wrapped function.
|
|
24
|
-
|
|
25
|
-
"""
|
|
26
|
-
|
|
27
|
-
@functools.wraps(func)
|
|
28
|
-
def wrapper(*args, **kwargs) -> Union[Dict, List, Response]:
|
|
29
|
-
log.debug('Parsing JSON response...')
|
|
30
|
-
response = func(*args, **kwargs)
|
|
31
|
-
return response.json() \
|
|
32
|
-
if response.headers.get('Content-Type') == "application/json" \
|
|
33
|
-
else response
|
|
34
|
-
|
|
35
|
-
return wrapper
|
apytizer/utils/generate_key.py
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
|
|
3
|
-
# Third-Party Imports
|
|
4
|
-
from cachetools.keys import hashkey
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def generate_key(*tags):
|
|
8
|
-
"""Generates a hashable key for caching values."""
|
|
9
|
-
|
|
10
|
-
def hash_parameters(*args, **kwargs):
|
|
11
|
-
"""Hashes function parameters."""
|
|
12
|
-
key = hashkey(
|
|
13
|
-
*tags, *args,
|
|
14
|
-
*[f"{k!s}={v!s}" for k, v in sorted(kwargs.items())]
|
|
15
|
-
)
|
|
16
|
-
return key
|
|
17
|
-
|
|
18
|
-
return hash_parameters
|
apytizer/utils/merge.py
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
|
|
3
|
-
# Standard Library Imports
|
|
4
|
-
from typing import Dict
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def merge(*args: Dict) -> Dict:
|
|
8
|
-
"""
|
|
9
|
-
Combines dictionaries.
|
|
10
|
-
|
|
11
|
-
Args:
|
|
12
|
-
*args: Dictionaries to merge.
|
|
13
|
-
|
|
14
|
-
Returns:
|
|
15
|
-
Merged dictionary.
|
|
16
|
-
|
|
17
|
-
"""
|
|
18
|
-
result = {k: v for dictionary in args if dictionary for k, v in dictionary.items()}
|
|
19
|
-
return result if result else None
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: apytizer
|
|
3
|
-
Version: 0.0.1a0
|
|
4
|
-
Summary: Implement wrappers quickly for REST APIs
|
|
5
|
-
Home-page: https://github.com/seanssullivan/apytizer
|
|
6
|
-
Author: Sean Sullivan
|
|
7
|
-
Author-email: seansullivan@seanmedia.ca
|
|
8
|
-
License: UNKNOWN
|
|
9
|
-
Download-URL: https://github.com/seanssullivan/apytizer/archive/refs/tags/v0.0.1-alpha.tar.gz
|
|
10
|
-
Project-URL: Bug Tracker, https://github.com/seanssullivan/apytizer/issues
|
|
11
|
-
Platform: UNKNOWN
|
|
12
|
-
Classifier: Intended Audience :: Developers
|
|
13
|
-
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
-
Classifier: Programming Language :: Python :: 3
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
-
Classifier: Natural Language :: English
|
|
17
|
-
Classifier: Operating System :: OS Independent
|
|
18
|
-
Requires-Python: >=3.8
|
|
19
|
-
Description-Content-Type: text/markdown
|
|
20
|
-
Requires-Dist: cachetools
|
|
21
|
-
Requires-Dist: requests
|
|
22
|
-
|
|
23
|
-
# apytizer
|
|
24
|
-
|
|
25
|
-
Implement wrappers quickly for REST APIs.
|
|
26
|
-
|
|
27
|
-
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
apytizer/__init__.py,sha256=YZcB-OH7axZXlxE_gKW3CR024jvh78GiH0eQT3tn0fM,356
|
|
2
|
-
apytizer/abstracts/__init__.py,sha256=LyYT2mxAeyqPCC1VmU6k5blAJMM6UV2vlzsJX9ukXcg,184
|
|
3
|
-
apytizer/abstracts/api.py,sha256=EOqYEgFYBkqYTJvkSV_S7W6u_Cjdcc9hpge0h4SC_Ac,3849
|
|
4
|
-
apytizer/abstracts/endpoint.py,sha256=srD8vpDcrslhXf7xsN0TJnMGRGEk-B2alkLHtMRYRyw,4434
|
|
5
|
-
apytizer/abstracts/model.py,sha256=P2yuZAkPm1cUPavcy1iv5-W20tVnv19TSQl1C2llBG4,1088
|
|
6
|
-
apytizer/abstracts/session.py,sha256=ddHmgCKymBwJ7W_RrBrZnpKccMSNHhOeIhgi94CmX2E,802
|
|
7
|
-
apytizer/adapters/__init__.py,sha256=Pj1f2o4p4jC3IptghGA-GC4nQuRuBQ173-iwkhprwgg,86
|
|
8
|
-
apytizer/adapters/transport.py,sha256=P0i23ZgoxSoT6BQmOwRpWGgenT2-sQps6aaTGhQ37Vg,1270
|
|
9
|
-
apytizer/base/__init__.py,sha256=C5wxAx9TUxU2-V3ZJaxOm_45hMbyTLQ8END4wUv2ZCE,166
|
|
10
|
-
apytizer/base/api.py,sha256=i-5fqFHp84QeFSAldnu9pSuMB0X_Ga5f-ng5xtYZlWM,13823
|
|
11
|
-
apytizer/base/endpoint.py,sha256=qDXr7DZBsB4ctBm6HuOIXfyQFRYN777Wexy-E3fBzwQ,11962
|
|
12
|
-
apytizer/base/model.py,sha256=xkmRtW3Q0vMlOQTrO66qL57qRNNKJVjsqFr_BG2lNhc,3179
|
|
13
|
-
apytizer/decorators/__init__.py,sha256=p9jpLbVYYsdp2v4OdfIuzZkHG3DuYvWy8-kFumvNn1I,156
|
|
14
|
-
apytizer/decorators/caching.py,sha256=AU_sSgiUeGqfcVnpgIgtg47aUtlPxXgfWKR4ONsi4NY,729
|
|
15
|
-
apytizer/decorators/connection.py,sha256=QrSBzYU3jdKTSVTj1PQjJn0xijVIeWCdZiO8WlWHNLE,1093
|
|
16
|
-
apytizer/decorators/json.py,sha256=L1y4HdInbkSD6-PfJhUMhH4LK5RvQtcn-kzVUY5wG6w,750
|
|
17
|
-
apytizer/decorators/pagination.py,sha256=xeY1NVC_MBLB8NHyAnUqPPjaboSQuoZAM-xEwDXVcPk,1319
|
|
18
|
-
apytizer/utils/__init__.py,sha256=EOIMaFAH013KE_AAJkeT_kHDceoLLCB3Ep-FgW4RmTQ,110
|
|
19
|
-
apytizer/utils/generate_key.py,sha256=tfllCUtYIlqmKxIA4oZ44dg2L_XXaC_9nPc7qlzTk30,421
|
|
20
|
-
apytizer/utils/merge.py,sha256=RWgAm3VThk6s-vL_OhCLR-m8K09h9TaaL3XeVKCTSqY,370
|
|
21
|
-
apytizer-0.0.1a0.dist-info/LICENSE,sha256=rwTrW8f9E015utDMKkNmSWxjW22qM-BDH6xSiLw0lGQ,10351
|
|
22
|
-
apytizer-0.0.1a0.dist-info/METADATA,sha256=Eym7Ppzi6LnV-QhTPqfYO1-EaPIcntcecg9AGEcaCB8,885
|
|
23
|
-
apytizer-0.0.1a0.dist-info/WHEEL,sha256=OqRkF0eY5GHssMorFjlbTIq072vpHpF60fIQA6lS9xA,92
|
|
24
|
-
apytizer-0.0.1a0.dist-info/top_level.txt,sha256=6qWpqA68Ce4ygWKZEhGSg5O1XgZORvPNuD4A0QnD_dA,9
|
|
25
|
-
apytizer-0.0.1a0.dist-info/RECORD,,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
apytizer
|
|
File without changes
|