python-httpfile 0.0.4__py3-none-any.whl → 0.0.4.1__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 +29 -5
- {python_httpfile-0.0.4.dist-info → python_httpfile-0.0.4.1.dist-info}/METADATA +1 -1
- python_httpfile-0.0.4.1.dist-info/RECORD +7 -0
- python_httpfile-0.0.4.dist-info/RECORD +0 -7
- {python_httpfile-0.0.4.dist-info → python_httpfile-0.0.4.1.dist-info}/LICENSE +0 -0
- {python_httpfile-0.0.4.dist-info → python_httpfile-0.0.4.1.dist-info}/WHEEL +0 -0
httpfile/__init__.py
CHANGED
|
@@ -253,7 +253,16 @@ class HTTPFileReader(RawIOBase, BinaryIO):
|
|
|
253
253
|
return 0
|
|
254
254
|
if self.file_closed:
|
|
255
255
|
self.reconnect()
|
|
256
|
-
|
|
256
|
+
try:
|
|
257
|
+
readinto = self.file.readinto
|
|
258
|
+
except AttributeError:
|
|
259
|
+
read = self.file.read
|
|
260
|
+
def readinto(buffer, /):
|
|
261
|
+
data = read(len(buffer))
|
|
262
|
+
size = len(data)
|
|
263
|
+
buffer[:size] = data
|
|
264
|
+
return data
|
|
265
|
+
size = readinto(buffer)
|
|
257
266
|
if size:
|
|
258
267
|
self._add_start(size)
|
|
259
268
|
return size
|
|
@@ -265,6 +274,7 @@ class HTTPFileReader(RawIOBase, BinaryIO):
|
|
|
265
274
|
return b""
|
|
266
275
|
if self.file_closed:
|
|
267
276
|
self.reconnect()
|
|
277
|
+
# TODO: if no readline method, give a default impl
|
|
268
278
|
if size is None or size < 0:
|
|
269
279
|
data = self.file.readline()
|
|
270
280
|
else:
|
|
@@ -280,6 +290,7 @@ class HTTPFileReader(RawIOBase, BinaryIO):
|
|
|
280
290
|
return []
|
|
281
291
|
if self.file_closed:
|
|
282
292
|
self.reconnect()
|
|
293
|
+
# TODO: if no readlines method, give a default impl
|
|
283
294
|
ls = self.file.readlines(hint)
|
|
284
295
|
if ls:
|
|
285
296
|
self._add_start(sum(map(len, ls)))
|
|
@@ -520,7 +531,7 @@ class AsyncHTTPFileReader(HTTPFileReader):
|
|
|
520
531
|
headers: None | Mapping = None,
|
|
521
532
|
start: int = 0,
|
|
522
533
|
seek_threshold: int = 1 << 20,
|
|
523
|
-
urlopen =
|
|
534
|
+
urlopen = None,
|
|
524
535
|
):
|
|
525
536
|
run_async(self.__ainit__(
|
|
526
537
|
url=url,
|
|
@@ -631,10 +642,11 @@ class AsyncHTTPFileReader(HTTPFileReader):
|
|
|
631
642
|
return b""
|
|
632
643
|
if self.file_closed:
|
|
633
644
|
await self.reconnect()
|
|
645
|
+
read = ensure_async(self.file.read, threaded=True)
|
|
634
646
|
if size is None or size < 0:
|
|
635
|
-
data = await
|
|
647
|
+
data = await read(-1)
|
|
636
648
|
else:
|
|
637
|
-
data = await
|
|
649
|
+
data = await read(size)
|
|
638
650
|
if data:
|
|
639
651
|
self._add_start(len(data))
|
|
640
652
|
return data
|
|
@@ -646,7 +658,16 @@ class AsyncHTTPFileReader(HTTPFileReader):
|
|
|
646
658
|
return 0
|
|
647
659
|
if self.file_closed:
|
|
648
660
|
await self.reconnect()
|
|
649
|
-
|
|
661
|
+
try:
|
|
662
|
+
readinto = ensure_async(self.file.readinto, threaded=True)
|
|
663
|
+
except AttributeError:
|
|
664
|
+
read = ensure_async(self.file.read, threaded=True)
|
|
665
|
+
async def readinto(buffer, /):
|
|
666
|
+
data = await read(len(buffer))
|
|
667
|
+
size = len(data)
|
|
668
|
+
buffer[:size] = data
|
|
669
|
+
return size
|
|
670
|
+
size = await readinto(buffer)
|
|
650
671
|
if size:
|
|
651
672
|
self._add_start(size)
|
|
652
673
|
return size
|
|
@@ -658,6 +679,7 @@ class AsyncHTTPFileReader(HTTPFileReader):
|
|
|
658
679
|
return b""
|
|
659
680
|
if self.file_closed:
|
|
660
681
|
await self.reconnect()
|
|
682
|
+
# TODO: if no readline method, give a default impl
|
|
661
683
|
if size is None or size < 0:
|
|
662
684
|
data = await ensure_async(self.file.readline, threaded=True)()
|
|
663
685
|
else:
|
|
@@ -673,6 +695,7 @@ class AsyncHTTPFileReader(HTTPFileReader):
|
|
|
673
695
|
return []
|
|
674
696
|
if self.file_closed:
|
|
675
697
|
await self.reconnect()
|
|
698
|
+
# TODO: if no readlines method, give a default impl
|
|
676
699
|
ls = await ensure_async(self.file.readlines, threaded=True)(hint)
|
|
677
700
|
if ls:
|
|
678
701
|
self._add_start(sum(map(len, ls)))
|
|
@@ -1197,4 +1220,5 @@ if find_spec("httpx"):
|
|
|
1197
1220
|
__all__.append("HttpxFileReader")
|
|
1198
1221
|
__all__.append("AsyncHttpxFileReader")
|
|
1199
1222
|
|
|
1223
|
+
# TODO: 增加 blacksheep 的 HTTPFileReader
|
|
1200
1224
|
# TODO: 设计实现一个 HTTPFileWriter,用于实现上传,关闭后视为上传完成
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
2
|
+
httpfile/__init__.py,sha256=ffww3j6Gk2dFLSy18a1PlRlT-yez5V857HbZp080Bxs,39533
|
|
3
|
+
httpfile/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
python_httpfile-0.0.4.1.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
5
|
+
python_httpfile-0.0.4.1.dist-info/METADATA,sha256=XreyhqBNvwXua7uaRsVBHkf88xLuhhi2Vmd4UAe5eEk,1522
|
|
6
|
+
python_httpfile-0.0.4.1.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
7
|
+
python_httpfile-0.0.4.1.dist-info/RECORD,,
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
2
|
-
httpfile/__init__.py,sha256=PAqvhrEAfTEzVSZ7wbLrPplYX-8G1epkW7MZt2sWWaw,38657
|
|
3
|
-
httpfile/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
python_httpfile-0.0.4.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
5
|
-
python_httpfile-0.0.4.dist-info/METADATA,sha256=1CtTQ_EoeIP9eVYlevzlEBdA9D26S9pHfZmdTOnXB0Q,1520
|
|
6
|
-
python_httpfile-0.0.4.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
7
|
-
python_httpfile-0.0.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|