python-httpfile 0.0.5.1__py3-none-any.whl → 0.0.5.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.
- httpfile/__init__.py +15 -31
- {python_httpfile-0.0.5.1.dist-info → python_httpfile-0.0.5.3.dist-info}/METADATA +6 -4
- python_httpfile-0.0.5.3.dist-info/RECORD +6 -0
- {python_httpfile-0.0.5.1.dist-info → python_httpfile-0.0.5.3.dist-info}/WHEEL +1 -1
- python_httpfile-0.0.5.1.dist-info/LICENSE +0 -21
- python_httpfile-0.0.5.1.dist-info/RECORD +0 -7
- /LICENSE → /python_httpfile-0.0.5.3.dist-info/licenses/LICENSE +0 -0
httpfile/__init__.py
CHANGED
|
@@ -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 =
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
1229
|
+
# TODO: 实现任意请求模块的 HTTPFileReader,只要它支持流式读取即可(分成 2 种类型:要么支持 read,要么支持迭代器)
|
|
1246
1230
|
# TODO: 设计实现一个 HTTPFileWriter,用于实现上传,关闭后视为上传完成
|
|
1247
1231
|
# TODO: httpx 重新实现 stream 和 async_stream 方法,确保不需要用上下文管理器,如此才能真的简化
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: python-httpfile
|
|
3
|
-
Version: 0.0.5.
|
|
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:
|
|
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.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
httpfile/__init__.py,sha256=vdI9_1Smyy-Phaxo8wDGVkH_ti7Ba1c5GkWM_-qqVIg,39672
|
|
2
|
+
httpfile/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
python_httpfile-0.0.5.3.dist-info/METADATA,sha256=0uofeQZx13DCW4JhUFu8_YNsExBvNOLcxDoRehDqNRM,1628
|
|
4
|
+
python_httpfile-0.0.5.3.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
5
|
+
python_httpfile-0.0.5.3.dist-info/licenses/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
6
|
+
python_httpfile-0.0.5.3.dist-info/RECORD,,
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 ChenyangGao <https://github.com/ChenyangGao>
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
2
|
-
httpfile/__init__.py,sha256=D9ZnL0TvKpSpv8HljjvYEPTPhu0_hGdhY_OLGfcNNB8,40057
|
|
3
|
-
httpfile/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
python_httpfile-0.0.5.1.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
5
|
-
python_httpfile-0.0.5.1.dist-info/METADATA,sha256=n4-l5Bw0QaRT3Zq7E9KS3vUxKzIiv0d1G1cazYq6p6Q,1573
|
|
6
|
-
python_httpfile-0.0.5.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
7
|
-
python_httpfile-0.0.5.1.dist-info/RECORD,,
|
|
File without changes
|