python-httpfile 0.0.1.3__py3-none-any.whl → 0.0.2.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 +20 -11
- {python_httpfile-0.0.1.3.dist-info → python_httpfile-0.0.2.1.dist-info}/METADATA +3 -4
- python_httpfile-0.0.2.1.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.1.dist-info}/LICENSE +0 -0
- {python_httpfile-0.0.1.3.dist-info → python_httpfile-0.0.2.1.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, /):
|
|
@@ -186,8 +186,7 @@ class HTTPFileReader(RawIOBase, BinaryIO):
|
|
|
186
186
|
def file(self, /) -> BinaryIO:
|
|
187
187
|
return self.response
|
|
188
188
|
|
|
189
|
-
|
|
190
|
-
def fileno(self, /):
|
|
189
|
+
def fileno(self, /) -> int:
|
|
191
190
|
return self.file.fileno()
|
|
192
191
|
|
|
193
192
|
def flush(self, /):
|
|
@@ -225,7 +224,7 @@ class HTTPFileReader(RawIOBase, BinaryIO):
|
|
|
225
224
|
def readinto(self, buffer, /) -> int:
|
|
226
225
|
if self.closed:
|
|
227
226
|
raise ValueError("I/O operation on closed file.")
|
|
228
|
-
if not self.chunked and self.tell() >= self.length:
|
|
227
|
+
if not buffer or not self.chunked and self.tell() >= self.length:
|
|
229
228
|
return 0
|
|
230
229
|
if self.file.closed:
|
|
231
230
|
self.reconnect()
|
|
@@ -302,9 +301,16 @@ class HTTPFileReader(RawIOBase, BinaryIO):
|
|
|
302
301
|
old_pos = self.tell()
|
|
303
302
|
if old_pos == pos:
|
|
304
303
|
return pos
|
|
305
|
-
if pos > old_pos and pos - old_pos <= self.seek_threshold:
|
|
306
|
-
|
|
307
|
-
|
|
304
|
+
if pos > old_pos and (size := pos - old_pos) <= self.seek_threshold:
|
|
305
|
+
if size <= COPY_BUFSIZE:
|
|
306
|
+
self.read(size)
|
|
307
|
+
else:
|
|
308
|
+
buf = bytearray(COPY_BUFSIZE)
|
|
309
|
+
readinto = self.readinto
|
|
310
|
+
while size > COPY_BUFSIZE:
|
|
311
|
+
readinto(buf)
|
|
312
|
+
size -= COPY_BUFSIZE
|
|
313
|
+
self.read(size)
|
|
308
314
|
else:
|
|
309
315
|
self.reconnect(pos)
|
|
310
316
|
return pos
|
|
@@ -378,6 +384,7 @@ class HTTPFileReader(RawIOBase, BinaryIO):
|
|
|
378
384
|
else:
|
|
379
385
|
return buffer
|
|
380
386
|
|
|
387
|
+
|
|
381
388
|
try:
|
|
382
389
|
from requests import Session
|
|
383
390
|
|
|
@@ -416,6 +423,7 @@ try:
|
|
|
416
423
|
if start >= self.length:
|
|
417
424
|
return start
|
|
418
425
|
return start + self.file.tell()
|
|
426
|
+
|
|
419
427
|
__all__.append("RequestsFileReader")
|
|
420
428
|
except ImportError:
|
|
421
429
|
pass
|
|
@@ -437,6 +445,7 @@ except ImportError:
|
|
|
437
445
|
pass
|
|
438
446
|
|
|
439
447
|
|
|
448
|
+
# TODO: 实现 AsyncHTTPFileReader
|
|
440
449
|
# TODO: 支持异步文件,使用 aiohttp,参考 aiofiles 的接口实现
|
|
441
450
|
# TODO: 设计实现一个 HTTPFileWriter,用于实现上传,关闭后视为上传完成
|
|
442
451
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: python-httpfile
|
|
3
|
-
Version: 0.0.1
|
|
4
|
-
Summary: Python httpfile
|
|
3
|
+
Version: 0.0.2.1
|
|
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=9qTmQOShcWtnLtIsqL3NbIeH9M2tAWE9NquEjyFs9ZM,13416
|
|
3
|
+
httpfile/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
python_httpfile-0.0.2.1.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
5
|
+
python_httpfile-0.0.2.1.dist-info/METADATA,sha256=tKxwg73IETWHCmf-F7--YKrQtlgn15r4iUxA7BzDkqQ,1416
|
|
6
|
+
python_httpfile-0.0.2.1.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
7
|
+
python_httpfile-0.0.2.1.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
|