python-httpfile 0.0.1.3__py3-none-any.whl → 0.0.2__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 +19 -9
- {python_httpfile-0.0.1.3.dist-info → python_httpfile-0.0.2.dist-info}/METADATA +3 -4
- python_httpfile-0.0.2.dist-info/RECORD +7 -0
- python_httpfile-0.0.1.3.dist-info/RECORD +0 -7
- {python_httpfile-0.0.1.3.dist-info → python_httpfile-0.0.2.dist-info}/LICENSE +0 -0
- {python_httpfile-0.0.1.3.dist-info → python_httpfile-0.0.2.dist-info}/WHEEL +0 -0
httpfile/__init__.py
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
# encoding: utf-8
|
|
3
3
|
|
|
4
4
|
__author__ = "ChenyangGao <https://chenyanggao.github.io>"
|
|
5
|
-
__version__ = (0, 0,
|
|
6
|
-
__all__ = ["HTTPFileReader", "
|
|
5
|
+
__version__ = (0, 0, 2)
|
|
6
|
+
__all__ = ["HTTPFileReader", "AsyncHTTPFileReader"]
|
|
7
7
|
|
|
8
8
|
import errno
|
|
9
9
|
|
|
@@ -19,7 +19,6 @@ from typing import Any, BinaryIO, IO, Optional, Protocol, Self, TypeVar
|
|
|
19
19
|
from types import MappingProxyType
|
|
20
20
|
from warnings import warn
|
|
21
21
|
|
|
22
|
-
from filewrap import bio_skip_iter
|
|
23
22
|
from http_response import get_filename, get_length, get_range, get_total_length, is_chunked, is_range_request
|
|
24
23
|
from property import funcproperty
|
|
25
24
|
from urlopen import urlopen
|
|
@@ -175,8 +174,9 @@ class HTTPFileReader(RawIOBase, BinaryIO):
|
|
|
175
174
|
self.__dict__["start"] += delta
|
|
176
175
|
|
|
177
176
|
def close(self, /):
|
|
178
|
-
self.
|
|
179
|
-
|
|
177
|
+
if not self.closed:
|
|
178
|
+
self.response.close()
|
|
179
|
+
self.__dict__["closed"] = True
|
|
180
180
|
|
|
181
181
|
@funcproperty
|
|
182
182
|
def closed(self, /):
|
|
@@ -225,7 +225,7 @@ class HTTPFileReader(RawIOBase, BinaryIO):
|
|
|
225
225
|
def readinto(self, buffer, /) -> int:
|
|
226
226
|
if self.closed:
|
|
227
227
|
raise ValueError("I/O operation on closed file.")
|
|
228
|
-
if not self.chunked and self.tell() >= self.length:
|
|
228
|
+
if not buffer or not self.chunked and self.tell() >= self.length:
|
|
229
229
|
return 0
|
|
230
230
|
if self.file.closed:
|
|
231
231
|
self.reconnect()
|
|
@@ -302,9 +302,16 @@ class HTTPFileReader(RawIOBase, BinaryIO):
|
|
|
302
302
|
old_pos = self.tell()
|
|
303
303
|
if old_pos == pos:
|
|
304
304
|
return pos
|
|
305
|
-
if pos > old_pos and pos - old_pos <= self.seek_threshold:
|
|
306
|
-
|
|
307
|
-
|
|
305
|
+
if pos > old_pos and (size := pos - old_pos) <= self.seek_threshold:
|
|
306
|
+
if size <= COPY_BUFSIZE:
|
|
307
|
+
self.read(size)
|
|
308
|
+
else:
|
|
309
|
+
buf = bytearray(COPY_BUFSIZE)
|
|
310
|
+
readinto = self.readinto
|
|
311
|
+
while size > COPY_BUFSIZE:
|
|
312
|
+
readinto(buf)
|
|
313
|
+
size -= COPY_BUFSIZE
|
|
314
|
+
self.read(size)
|
|
308
315
|
else:
|
|
309
316
|
self.reconnect(pos)
|
|
310
317
|
return pos
|
|
@@ -378,6 +385,7 @@ class HTTPFileReader(RawIOBase, BinaryIO):
|
|
|
378
385
|
else:
|
|
379
386
|
return buffer
|
|
380
387
|
|
|
388
|
+
|
|
381
389
|
try:
|
|
382
390
|
from requests import Session
|
|
383
391
|
|
|
@@ -416,6 +424,7 @@ try:
|
|
|
416
424
|
if start >= self.length:
|
|
417
425
|
return start
|
|
418
426
|
return start + self.file.tell()
|
|
427
|
+
|
|
419
428
|
__all__.append("RequestsFileReader")
|
|
420
429
|
except ImportError:
|
|
421
430
|
pass
|
|
@@ -437,6 +446,7 @@ except ImportError:
|
|
|
437
446
|
pass
|
|
438
447
|
|
|
439
448
|
|
|
449
|
+
# TODO: 实现 AsyncHTTPFileReader
|
|
440
450
|
# TODO: 支持异步文件,使用 aiohttp,参考 aiofiles 的接口实现
|
|
441
451
|
# TODO: 设计实现一个 HTTPFileWriter,用于实现上传,关闭后视为上传完成
|
|
442
452
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: python-httpfile
|
|
3
|
-
Version: 0.0.
|
|
4
|
-
Summary: Python httpfile
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: Python httpfile.
|
|
5
5
|
Home-page: https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-httpfile
|
|
6
6
|
License: MIT
|
|
7
7
|
Keywords: http,file,wrapper
|
|
@@ -22,13 +22,12 @@ Classifier: Topic :: Software Development
|
|
|
22
22
|
Classifier: Topic :: Software Development :: Libraries
|
|
23
23
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
24
|
Requires-Dist: http_response
|
|
25
|
-
Requires-Dist: python-filewrap
|
|
26
25
|
Requires-Dist: python-property
|
|
27
26
|
Requires-Dist: python-urlopen
|
|
28
27
|
Project-URL: Repository, https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-httpfile
|
|
29
28
|
Description-Content-Type: text/markdown
|
|
30
29
|
|
|
31
|
-
# Python httpfile
|
|
30
|
+
# Python httpfile.
|
|
32
31
|
|
|
33
32
|
## Installation
|
|
34
33
|
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
2
|
+
httpfile/__init__.py,sha256=cZZjfftX2nWqEZQ0jjDnrTOW2NLbfnQy8ZEnP52y_tY,13427
|
|
3
|
+
httpfile/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
python_httpfile-0.0.2.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
5
|
+
python_httpfile-0.0.2.dist-info/METADATA,sha256=-hanQvHDGCiX4-fYjubZmioS7o3nAnGPtSkF47eEXr0,1414
|
|
6
|
+
python_httpfile-0.0.2.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
7
|
+
python_httpfile-0.0.2.dist-info/RECORD,,
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
2
|
-
httpfile/__init__.py,sha256=HB4QguYNM1Jri_2ZIkERW9LN6-BXS4ZnLKf7F06aQkg,13090
|
|
3
|
-
httpfile/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
python_httpfile-0.0.1.3.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
5
|
-
python_httpfile-0.0.1.3.dist-info/METADATA,sha256=2OM3725fbgLkcH7ZgWXXI0uRwAY1H1RdYag7Ng5KRR4,1463
|
|
6
|
-
python_httpfile-0.0.1.3.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
7
|
-
python_httpfile-0.0.1.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|