http_client_request 0.0.7__tar.gz → 0.0.8__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: http_client_request
3
- Version: 0.0.7
3
+ Version: 0.0.8
4
4
  Summary: ttp.client request extension.
5
5
  Home-page: https://github.com/ChenyangGao/python-modules/tree/main/http_client_request
6
6
  License: MIT
@@ -22,7 +22,7 @@ Classifier: Topic :: Software Development :: Libraries
22
22
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
23
  Requires-Dist: http_response (>=0.0.9)
24
24
  Requires-Dist: python-argtools (>=0.0.2)
25
- Requires-Dist: python-cookietools (>=0.1.2)
25
+ Requires-Dist: python-cookietools (>=0.1.3)
26
26
  Requires-Dist: python-dicttools (>=0.0.4)
27
27
  Requires-Dist: python-filewrap (>=0.2.8)
28
28
  Requires-Dist: python-http_request (>=0.1.4)
@@ -4,7 +4,7 @@
4
4
  from __future__ import annotations
5
5
 
6
6
  __author__ = "ChenyangGao <https://chenyanggao.github.io>"
7
- __version__ = (0, 0, 7)
7
+ __version__ = (0, 0, 8)
8
8
  __all__ = [
9
9
  "CONNECTION_POOL", "HTTPConnection", "HTTPSConnection", "HTTPResponse",
10
10
  "ConnectionPool", "request",
@@ -26,6 +26,7 @@ from inspect import signature
26
26
  from os import PathLike
27
27
  from select import select
28
28
  from socket import socket as Socket
29
+ from ssl import SSLWantReadError
29
30
  from types import EllipsisType
30
31
  from typing import cast, overload, Any, Final, Literal
31
32
  from urllib.error import HTTPError
@@ -108,11 +109,17 @@ class HTTPResponse(BaseHTTPResponse):
108
109
  def buffer_size(self, /) -> int:
109
110
  fp = self._fp
110
111
  sock = fp.raw._sock
111
- cache_size = len(fp.peek())
112
- while True:
113
- buffer_size = cache_size + sock_bufsize(sock)
114
- if cache_size == (cache_size := len(fp.peek())):
115
- return buffer_size
112
+ sock.setblocking(False)
113
+ try:
114
+ cache_size = len(fp.peek() or b"")
115
+ while True:
116
+ buffer_size = cache_size + sock_bufsize(sock)
117
+ if cache_size == (cache_size := len(fp.peek() or b"")):
118
+ return buffer_size
119
+ except (BlockingIOError, SSLWantReadError):
120
+ return 0
121
+ finally:
122
+ sock.setblocking(True)
116
123
 
117
124
  @property
118
125
  def unbuffer_size(self, /) -> int:
@@ -211,7 +218,7 @@ class HTTPConnection(BaseHTTPConnection):
211
218
 
212
219
  @property
213
220
  def response(self, /) -> None | HTTPResponse:
214
- return self.__response # type: ignore
221
+ return self._HTTPConnection__response # type: ignore
215
222
 
216
223
  def getresponse(self, /) -> HTTPResponse:
217
224
  return cast(HTTPResponse, super().getresponse())
@@ -232,7 +239,7 @@ class HTTPSConnection(BaseHTTPSConnection):
232
239
 
233
240
  @property
234
241
  def response(self, /) -> None | HTTPResponse:
235
- return self.__response # type: ignore
242
+ return self._HTTPConnection__response # type: ignore
236
243
 
237
244
  def getresponse(self, /) -> HTTPResponse:
238
245
  return cast(HTTPResponse, super().getresponse())
@@ -290,12 +297,11 @@ class ConnectionPool:
290
297
  resp = con.response
291
298
  if not sock or getattr(sock, "_closed"):
292
299
  con.connect()
293
- elif resp and 0 <= resp.unbuffer_size <= 1024 * 1024:
294
- if resp.unread_size:
295
- try:
296
- resp.read()
297
- except (ConnectionResetError, BrokenPipeError):
298
- con.connect()
300
+ elif resp and 0 < resp.unbuffer_size <= 1024 * 1024:
301
+ try:
302
+ resp.read()
303
+ except (ConnectionResetError, BrokenPipeError):
304
+ con.connect()
299
305
  else:
300
306
  sock.setblocking(False)
301
307
  try:
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "http_client_request"
3
- version = "0.0.7"
3
+ version = "0.0.8"
4
4
  description = "ttp.client request extension."
5
5
  authors = ["ChenyangGao <wosiwujm@gmail.com>"]
6
6
  license = "MIT"
@@ -29,7 +29,7 @@ include = [
29
29
  python = "^3.12"
30
30
  http_response = ">=0.0.9"
31
31
  python-argtools = ">=0.0.2"
32
- python-cookietools = ">=0.1.2"
32
+ python-cookietools = ">=0.1.3"
33
33
  python-dicttools = ">=0.0.4"
34
34
  python-filewrap = ">=0.2.8"
35
35
  python-http_request = ">=0.1.4"