python-httpfile 0.0.5.1__tar.gz → 0.0.5.3__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,9 +1,9 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: python-httpfile
3
- Version: 0.0.5.1
3
+ Version: 0.0.5.3
4
4
  Summary: Python httpfile.
5
- Home-page: https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-httpfile
6
5
  License: MIT
6
+ License-File: LICENSE
7
7
  Keywords: http,file,wrapper
8
8
  Author: ChenyangGao
9
9
  Author-email: wosiwujm@gmail.com
@@ -18,6 +18,7 @@ Classifier: Programming Language :: Python :: 3.10
18
18
  Classifier: Programming Language :: Python :: 3.11
19
19
  Classifier: Programming Language :: Python :: 3.12
20
20
  Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
21
22
  Classifier: Programming Language :: Python :: 3 :: Only
22
23
  Classifier: Topic :: Software Development
23
24
  Classifier: Topic :: Software Development :: Libraries
@@ -27,7 +28,8 @@ Requires-Dist: python-asynctools (>=0.0.5)
27
28
  Requires-Dist: python-filewrap (>=0.2.1)
28
29
  Requires-Dist: python-property (>=0.0.2)
29
30
  Requires-Dist: python-urlopen (>=0.0.7.1)
30
- Project-URL: Repository, https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-httpfile
31
+ Project-URL: Homepage, https://github.com/ChenyangGao/python-modules/tree/main/python-httpfile
32
+ Project-URL: Repository, https://github.com/ChenyangGao/python-modules/tree/main/python-httpfile
31
33
  Description-Content-Type: text/markdown
32
34
 
33
35
  # Python httpfile.
@@ -18,7 +18,6 @@ from io import (
18
18
  )
19
19
  from os import fstat, stat, PathLike
20
20
  from shutil import COPY_BUFSIZE # type: ignore
21
- from sys import exc_info
22
21
  from typing import cast, overload, Any, BinaryIO, Literal, Self
23
22
  from types import MappingProxyType
24
23
  from warnings import warn
@@ -27,7 +26,6 @@ from asynctools import ensure_async, run_async
27
26
  from filewrap import AsyncBufferedReader, AsyncTextIOWrapper
28
27
  from http_response import get_filename, get_length, get_range, get_total_length, is_chunked, is_range_request
29
28
  from property import funcproperty
30
- from urlopen import urlopen
31
29
 
32
30
 
33
31
  def get_filesize(
@@ -103,7 +101,7 @@ class HTTPFileReader(RawIOBase, BinaryIO):
103
101
  # NOTE: If the offset of the forward seek is not higher than this value,
104
102
  # it will be directly read and discarded, default to 1 MB
105
103
  seek_threshold: int = 1 << 20,
106
- urlopen = urlopen,
104
+ urlopen = None,
107
105
  ):
108
106
  if headers:
109
107
  headers = {**headers, "accept-encoding": "identity"}
@@ -114,7 +112,7 @@ class HTTPFileReader(RawIOBase, BinaryIO):
114
112
  elif start < 0:
115
113
  headers["range"] = f"bytes={start}"
116
114
  if urlopen is None:
117
- urlopen = globals()["urlopen"]
115
+ from http_request.extension.request import urlopen
118
116
  if callable(url):
119
117
  geturl = url
120
118
  def url():
@@ -510,7 +508,7 @@ class HTTPFileReader(RawIOBase, BinaryIO):
510
508
  else:
511
509
  buffer_size = buffering
512
510
  raw = self
513
- buffer = BufferedReader(raw, buffer_size)
511
+ buffer: BufferedReader = BufferedReader(raw, buffer_size)
514
512
  if text_mode:
515
513
  return TextIOWrapper(
516
514
  buffer,
@@ -580,7 +578,7 @@ class AsyncHTTPFileReader(HTTPFileReader):
580
578
  elif start < 0:
581
579
  headers["range"] = f"bytes={start}"
582
580
  if urlopen is None:
583
- urlopen = globals()["urlopen"]
581
+ from http_request.extension.request import urlopen
584
582
  if callable(url):
585
583
  geturl = url
586
584
  async def url() -> str:
@@ -1050,8 +1048,6 @@ if find_spec("requests"):
1050
1048
 
1051
1049
 
1052
1050
  if find_spec("aiohttp"):
1053
- from types import MethodType
1054
-
1055
1051
  _aiohttp_urlopen = None
1056
1052
 
1057
1053
  class AiohttpFileReader(AsyncHTTPFileReader):
@@ -1068,33 +1064,17 @@ if find_spec("aiohttp"):
1068
1064
  global _aiohttp_urlopen
1069
1065
  from aiohttp import request, ClientSession
1070
1066
 
1071
- close_session = True
1072
1067
  if isinstance(urlopen, ClientSession):
1073
1068
  urlopen = urlopen.get
1074
- close_session = False
1075
- if urlopen is None:
1069
+ elif urlopen is None:
1076
1070
  if _aiohttp_urlopen is None:
1077
1071
  urlopen = _aiohttp_urlopen = partial(request, "GET")
1078
1072
  else:
1079
1073
  urlopen = _aiohttp_urlopen
1080
- else:
1081
- func = urlopen
1082
- if isinstance(func, partial):
1083
- func = func.func
1084
- close_session = not (
1085
- isinstance(func, MethodType) and
1086
- isinstance(func.__self__, ClientSession)
1087
- )
1088
1074
  async def urlopen_wrapper(url: str, headers: None | Mapping = headers):
1089
- resp = await urlopen(url, headers=headers).__aenter__()
1090
- async def aclose():
1091
- if close_session:
1092
- try:
1093
- await resp._session.close()
1094
- except AttributeError:
1095
- pass
1096
- resp.close()
1097
- resp.aclose = aclose
1075
+ ctx = urlopen(url, headers=headers)
1076
+ resp = await ctx.__aenter__()
1077
+ resp.aclose = lambda: ctx.__aexit__(None, None, None)
1098
1078
  resp.raise_for_status()
1099
1079
  return resp
1100
1080
  await super().__ainit__(
@@ -1133,7 +1113,7 @@ if find_spec("httpx"):
1133
1113
  if "__del__" not in Client.__dict__:
1134
1114
  setattr(Client, "__del__", lambda self: self.close())
1135
1115
  session = Client()
1136
- return session.send(
1116
+ resp = session.send(
1137
1117
  request=session.build_request(
1138
1118
  method=method,
1139
1119
  url=url,
@@ -1143,6 +1123,8 @@ if find_spec("httpx"):
1143
1123
  follow_redirects=follow_redirects,
1144
1124
  stream=stream,
1145
1125
  )
1126
+ setattr(resp, "session", session)
1127
+ return resp
1146
1128
 
1147
1129
  async def httpx_request_async(
1148
1130
  url,
@@ -1158,7 +1140,7 @@ if find_spec("httpx"):
1158
1140
  if "__del__" not in AsyncClient.__dict__:
1159
1141
  setattr(AsyncClient, "__del__", lambda self: run_async(self.aclose()))
1160
1142
  session = AsyncClient()
1161
- return await session.send(
1143
+ resp = await session.send(
1162
1144
  request=session.build_request(
1163
1145
  method=method,
1164
1146
  url=url,
@@ -1168,6 +1150,8 @@ if find_spec("httpx"):
1168
1150
  follow_redirects=follow_redirects,
1169
1151
  stream=stream,
1170
1152
  )
1153
+ setattr(resp, "session", session)
1154
+ return resp
1171
1155
 
1172
1156
  class HttpxFileReader(HTTPFileReader):
1173
1157
 
@@ -1242,6 +1226,6 @@ if find_spec("httpx"):
1242
1226
  __all__.append("HttpxFileReader")
1243
1227
  __all__.append("AsyncHttpxFileReader")
1244
1228
 
1245
- # TODO: 增加 blacksheep HTTPFileReader
1229
+ # TODO: 实现任意请求模块的 HTTPFileReader,只要它支持流式读取即可(分成 2 种类型:要么支持 read,要么支持迭代器)
1246
1230
  # TODO: 设计实现一个 HTTPFileWriter,用于实现上传,关闭后视为上传完成
1247
1231
  # TODO: httpx 重新实现 stream 和 async_stream 方法,确保不需要用上下文管理器,如此才能真的简化
@@ -1,12 +1,12 @@
1
1
  [tool.poetry]
2
2
  name = "python-httpfile"
3
- version = "0.0.5.1"
3
+ version = "0.0.5.3"
4
4
  description = "Python httpfile."
5
5
  authors = ["ChenyangGao <wosiwujm@gmail.com>"]
6
6
  license = "MIT"
7
7
  readme = "readme.md"
8
- homepage = "https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-httpfile"
9
- repository = "https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-httpfile"
8
+ homepage = "https://github.com/ChenyangGao/python-modules/tree/main/python-httpfile"
9
+ repository = "https://github.com/ChenyangGao/python-modules/tree/main/python-httpfile"
10
10
  keywords = ["http", "file", "wrapper"]
11
11
  classifiers = [
12
12
  "License :: OSI Approved :: MIT License",