python3-commons 0.6.18__py3-none-any.whl → 0.6.20__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.
@@ -1,6 +1,7 @@
1
1
  import logging
2
2
  from contextlib import asynccontextmanager
3
3
  from datetime import datetime, UTC
4
+ from http import HTTPStatus
4
5
  from json import dumps
5
6
  from typing import AsyncGenerator, Literal, Mapping, Sequence
6
7
  from uuid import uuid4
@@ -62,7 +63,7 @@ async def request(
62
63
  curl_request = None
63
64
 
64
65
  if method == 'get':
65
- if query:
66
+ if headers or query:
66
67
  curl_request = request_to_curl(url, query, method, headers)
67
68
  else:
68
69
  curl_request = request_to_curl(url, query, method, headers, json, data)
@@ -83,7 +84,20 @@ async def request(
83
84
  if audit_name:
84
85
  await _store_response_for_audit(response, audit_name, uri_path, method, request_id)
85
86
 
86
- yield response
87
+ if response.ok:
88
+ yield response
89
+ else:
90
+ match response.status:
91
+ case HTTPStatus.UNAUTHORIZED:
92
+ raise PermissionError('Unauthorized')
93
+ case HTTPStatus.FORBIDDEN:
94
+ raise PermissionError('Forbidden')
95
+ case HTTPStatus.NOT_FOUND:
96
+ raise LookupError('Not found')
97
+ case HTTPStatus.BAD_REQUEST:
98
+ raise ValueError('Bad request')
99
+ case _:
100
+ response.raise_for_status()
87
101
  else:
88
102
  if json:
89
103
  data = dumps(json, cls=CustomJSONEncoder).encode('utf-8')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: python3-commons
3
- Version: 0.6.18
3
+ Version: 0.6.20
4
4
  Summary: Re-usable Python3 code
5
5
  Author-email: Oleg Korsak <kamikaze.is.waiting.you@gmail.com>
6
6
  License: gpl-3
@@ -1,5 +1,5 @@
1
1
  python3_commons/__init__.py,sha256=0KgaYU46H_IMKn-BuasoRN3C4Hi45KlkHHoPbU9cwiA,189
2
- python3_commons/api_client.py,sha256=yt15XtnHl_9oqlwuepabq_IUjozNrO_KM9sQ1NaGdxI,3734
2
+ python3_commons/api_client.py,sha256=6F99vSGCV8pqcKJE9dECijlgggm40FB9TzkFZRgwDq4,4419
3
3
  python3_commons/audit.py,sha256=DMQ-nrWSs0qilD7wkz_8PV4jXcee75O8FgAm2YIuOiY,6256
4
4
  python3_commons/conf.py,sha256=qm2a2yWOhfawicBPjWnUett8TrsMtoyQXDxEJ_N-v-Y,637
5
5
  python3_commons/db.py,sha256=qhaDIdzBWgFyeP_XPKfHZlYVlwS2bpBPYMv84yV6820,738
@@ -13,9 +13,9 @@ python3_commons/serializers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMp
13
13
  python3_commons/serializers/json.py,sha256=P288wWz9ic38QWEMrpp_uwKPYkQiOgvE1cI4WZn6ZCg,808
14
14
  python3_commons/serializers/msgpack.py,sha256=tzIGGyDL3UpZnnouCtnxuYDx6InKM_C3PP1N4PN8wd4,1269
15
15
  python3_commons/serializers/msgspec.py,sha256=FuZVqOLJb0-lEKrs7dtjhwEbHIpfMUk5yu1hD64zRdc,2038
16
- python3_commons-0.6.18.dist-info/AUTHORS.rst,sha256=3R9JnfjfjH5RoPWOeqKFJgxVShSSfzQPIrEr1nxIo9Q,90
17
- python3_commons-0.6.18.dist-info/LICENSE,sha256=xxILuojHm4fKQOrMHPSslbyy6WuKAN2RiG74HbrYfzM,34575
18
- python3_commons-0.6.18.dist-info/METADATA,sha256=ItbZzMpdplskhGnW4k-n0HQ4fKTRRPRvhw3ap3B6sUU,986
19
- python3_commons-0.6.18.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
20
- python3_commons-0.6.18.dist-info/top_level.txt,sha256=lJI6sCBf68eUHzupCnn2dzG10lH3jJKTWM_hrN1cQ7M,16
21
- python3_commons-0.6.18.dist-info/RECORD,,
16
+ python3_commons-0.6.20.dist-info/AUTHORS.rst,sha256=3R9JnfjfjH5RoPWOeqKFJgxVShSSfzQPIrEr1nxIo9Q,90
17
+ python3_commons-0.6.20.dist-info/LICENSE,sha256=xxILuojHm4fKQOrMHPSslbyy6WuKAN2RiG74HbrYfzM,34575
18
+ python3_commons-0.6.20.dist-info/METADATA,sha256=k4xVOGoFKRMpICx37j9DZ5Wzp1cNpTBUapsmhRZ8w1Q,986
19
+ python3_commons-0.6.20.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
20
+ python3_commons-0.6.20.dist-info/top_level.txt,sha256=lJI6sCBf68eUHzupCnn2dzG10lH3jJKTWM_hrN1cQ7M,16
21
+ python3_commons-0.6.20.dist-info/RECORD,,