httprest 0.2.0__tar.gz → 0.3.0__tar.gz
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.
- {httprest-0.2.0 → httprest-0.3.0}/PKG-INFO +2 -1
- {httprest-0.2.0 → httprest-0.3.0}/httprest/http/__init__.py +2 -1
- {httprest-0.2.0 → httprest-0.3.0}/httprest/http/base.py +3 -2
- {httprest-0.2.0 → httprest-0.3.0}/httprest/http/requests_client.py +8 -3
- httprest-0.3.0/httprest/http/timeout.py +18 -0
- {httprest-0.2.0 → httprest-0.3.0}/httprest/http/urllib_client.py +1 -1
- {httprest-0.2.0 → httprest-0.3.0}/pyproject.toml +1 -1
- {httprest-0.2.0 → httprest-0.3.0}/LICENSE +0 -0
- {httprest-0.2.0 → httprest-0.3.0}/README.md +0 -0
- {httprest-0.2.0 → httprest-0.3.0}/httprest/__init__.py +0 -0
- {httprest-0.2.0 → httprest-0.3.0}/httprest/api.py +0 -0
- {httprest-0.2.0 → httprest-0.3.0}/httprest/http/auth.py +0 -0
- {httprest-0.2.0 → httprest-0.3.0}/httprest/http/cert.py +0 -0
- {httprest-0.2.0 → httprest-0.3.0}/httprest/http/errors.py +0 -0
- {httprest-0.2.0 → httprest-0.3.0}/httprest/http/fake_client.py +0 -0
- {httprest-0.2.0 → httprest-0.3.0}/httprest/http/response.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: httprest
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: A library for making simple REST-like HTTP requests
|
|
5
5
|
Home-page: https://github.com/litteratum/httprest
|
|
6
6
|
License: MIT
|
|
@@ -17,6 +17,7 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.10
|
|
18
18
|
Classifier: Programming Language :: Python :: 3.11
|
|
19
19
|
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
21
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
21
22
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
22
23
|
Classifier: Topic :: Software Development :: Libraries
|
|
@@ -8,13 +8,14 @@ from urllib.parse import urlencode
|
|
|
8
8
|
from .auth import BaseAuth
|
|
9
9
|
from .cert import ClientCertificate
|
|
10
10
|
from .response import HTTPResponse
|
|
11
|
+
from .timeout import Timeout
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
class HTTPClient(ABC):
|
|
14
15
|
"""Base HTTP client."""
|
|
15
16
|
|
|
16
|
-
def __init__(self,
|
|
17
|
-
self.
|
|
17
|
+
def __init__(self, timeout: Optional[Timeout] = None) -> None:
|
|
18
|
+
self._timeout = timeout
|
|
18
19
|
|
|
19
20
|
@abstractmethod
|
|
20
21
|
def _request(
|
|
@@ -8,13 +8,14 @@ from httprest.http import errors as _errors
|
|
|
8
8
|
|
|
9
9
|
from .base import HTTPClient, HTTPResponse
|
|
10
10
|
from .cert import ClientCertificate
|
|
11
|
+
from .timeout import Timeout
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
class RequestsHTTPClient(HTTPClient):
|
|
14
15
|
"""`requests` HTTP client."""
|
|
15
16
|
|
|
16
|
-
def __init__(self,
|
|
17
|
-
super().__init__(
|
|
17
|
+
def __init__(self, timeout: Optional[Timeout] = None) -> None:
|
|
18
|
+
super().__init__(timeout)
|
|
18
19
|
self._session = requests.Session()
|
|
19
20
|
|
|
20
21
|
def _request(
|
|
@@ -39,7 +40,11 @@ class RequestsHTTPClient(HTTPClient):
|
|
|
39
40
|
)(
|
|
40
41
|
url,
|
|
41
42
|
json=json,
|
|
42
|
-
timeout=
|
|
43
|
+
timeout=(
|
|
44
|
+
(self._timeout.connect, self._timeout.read)
|
|
45
|
+
if self._timeout
|
|
46
|
+
else None
|
|
47
|
+
),
|
|
43
48
|
headers=headers,
|
|
44
49
|
cert=client_cert,
|
|
45
50
|
)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""Timeout wrappers."""
|
|
2
|
+
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Timeout:
|
|
7
|
+
"""HTTP request timeout."""
|
|
8
|
+
|
|
9
|
+
def __init__(
|
|
10
|
+
self, connect: Optional[float] = None, read: Optional[float] = None
|
|
11
|
+
) -> None:
|
|
12
|
+
"""Init timeout.
|
|
13
|
+
|
|
14
|
+
:param connect: connect timeout in seconds
|
|
15
|
+
:param read: read timeout in seconds
|
|
16
|
+
"""
|
|
17
|
+
self.connect = connect
|
|
18
|
+
self.read = read
|
|
@@ -40,7 +40,7 @@ class UrllibHTTPClient(HTTPClient):
|
|
|
40
40
|
headers=headers,
|
|
41
41
|
method=method.upper(),
|
|
42
42
|
),
|
|
43
|
-
timeout=self.
|
|
43
|
+
timeout=self._timeout.read if self._timeout else None,
|
|
44
44
|
) as response:
|
|
45
45
|
return HTTPResponse(
|
|
46
46
|
response.status, response.read(), dict(response.headers)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|