mm-http 0.0.1__py3-none-any.whl → 0.0.3__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.
mm_http/response.py CHANGED
@@ -22,6 +22,8 @@ class HttpError(str, enum.Enum):
22
22
 
23
23
  @dataclass
24
24
  class HttpResponse:
25
+ """HTTP response with status, error, body, and headers."""
26
+
25
27
  status_code: int | None = None
26
28
  error: HttpError | None = None
27
29
  error_message: str | None = None
@@ -29,6 +31,7 @@ class HttpResponse:
29
31
  headers: dict[str, str] | None = None
30
32
 
31
33
  def parse_json_body(self, path: str | None = None, none_on_error: bool = False) -> Any: # noqa: ANN401
34
+ """Parse JSON body and optionally extract value by path."""
32
35
  if self.body is None:
33
36
  if none_on_error:
34
37
  return None
@@ -43,15 +46,19 @@ class HttpResponse:
43
46
  raise
44
47
 
45
48
  def is_err(self) -> bool:
49
+ """Check if response represents an error (has error or status >= 400)."""
46
50
  return self.error is not None or (self.status_code is not None and self.status_code >= 400)
47
51
 
48
- def to_err[T](self, error: str | Exception | tuple[str, Exception] | None = None) -> Result[T]:
52
+ def to_result_err[T](self, error: str | Exception | tuple[str, Exception] | None = None) -> Result[T]:
53
+ """Create error Result[T] from HttpResponse."""
49
54
  return Result.err(error or self.error or "error", extra=self.to_dict())
50
55
 
51
- def to_ok[T](self, value: T) -> Result[T]:
56
+ def to_result_ok[T](self, value: T) -> Result[T]:
57
+ """Create success Result[T] from HttpResponse with given value."""
52
58
  return Result.ok(value, extra=self.to_dict())
53
59
 
54
60
  def to_dict(self) -> dict[str, Any]:
61
+ """Convert HttpResponse to dictionary."""
55
62
  return {
56
63
  "status_code": self.status_code,
57
64
  "error": self.error.value if self.error else None,
@@ -62,6 +69,7 @@ class HttpResponse:
62
69
 
63
70
  @property
64
71
  def content_type(self) -> str | None:
72
+ """Get Content-Type header value (case-insensitive)."""
65
73
  if self.headers is None:
66
74
  return None
67
75
  for key in self.headers:
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mm-http
3
- Version: 0.0.1
3
+ Version: 0.0.3
4
4
  Requires-Python: >=3.13
5
5
  Requires-Dist: aiohttp-socks~=0.10.1
6
- Requires-Dist: aiohttp~=3.12.2
7
- Requires-Dist: mm-result>=0.0.2
6
+ Requires-Dist: aiohttp~=3.12.12
7
+ Requires-Dist: mm-result>=0.0.4
8
8
  Requires-Dist: pydantic>=2.11.5
9
9
  Requires-Dist: pydash>=8.0.5
10
- Requires-Dist: requests[socks]~=2.32.3
10
+ Requires-Dist: requests[socks]~=2.32.4
@@ -2,7 +2,7 @@ mm_http/__init__.py,sha256=vW7ASPktUjm6S2Q7_biiA4F_PzG7gPF8gK3E7bBO4yQ,212
2
2
  mm_http/http_request.py,sha256=3yapH-ADtSGqV7pMQj1cGWrGywDmRnTIE53AzM6ECtg,4116
3
3
  mm_http/http_request_sync.py,sha256=lajd4Xt_wHKuRYyPtybO5CHHvquLzGPZEMHzKjN1wlM,1819
4
4
  mm_http/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- mm_http/response.py,sha256=Ve0uE6BzQ4FPoaF-DbJ_9iCI2vqyDfbxGTMm1L3Bndc,3576
6
- mm_http-0.0.1.dist-info/METADATA,sha256=CgOzxJf2MJaO6k2EC5JBtJNQsD888ievm2BNszyHKGg,275
7
- mm_http-0.0.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8
- mm_http-0.0.1.dist-info/RECORD,,
5
+ mm_http/response.py,sha256=ajTjL3wWbYYt5OFD_IJ47pVRF7mwb1SX3QgCI-Ipfos,4049
6
+ mm_http-0.0.3.dist-info/METADATA,sha256=UARW-4rzfSlXyxitc33qG0iDcNrC9W4liw9F6n1Jxhk,276
7
+ mm_http-0.0.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8
+ mm_http-0.0.3.dist-info/RECORD,,