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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: httprest
3
- Version: 0.2.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
@@ -1,8 +1,9 @@
1
1
  """Package for dealing with HTTP."""
2
2
 
3
- from .base import HTTPClient, HTTPResponse
3
+ from .base import HTTPClient, HTTPResponse, Timeout
4
4
 
5
5
  __all__ = [
6
6
  "HTTPClient",
7
7
  "HTTPResponse",
8
+ "Timeout",
8
9
  ]
@@ -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, request_timeout: float = 5) -> None:
17
- self.request_timeout = request_timeout
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, request_timeout: float = 5) -> None:
17
- super().__init__(request_timeout)
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=self.request_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.request_timeout,
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)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "httprest"
3
- version = "0.2.0"
3
+ version = "0.3.0"
4
4
  description = "A library for making simple REST-like HTTP requests"
5
5
  authors = ["Andrii Nechaiev <andrewnech@gmail.com>"]
6
6
  readme = "README.md"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes