python-httpfile 0.0.1.3__tar.gz → 0.0.2.1__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,7 +1,7 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-httpfile
3
- Version: 0.0.1.3
4
- Summary: Python httpfile classes.
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 classes.
30
+ # Python httpfile.
32
31
 
33
32
  ## Installation
34
33
 
@@ -2,8 +2,8 @@
2
2
  # encoding: utf-8
3
3
 
4
4
  __author__ = "ChenyangGao <https://chenyanggao.github.io>"
5
- __version__ = (0, 0, 1)
6
- __all__ = ["HTTPFileReader", "RequestsFileReader"]
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.response.close()
179
- self.__dict__["closed"] = True
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
- @funcproperty
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
- for _ in bio_skip_iter(self, pos - old_pos):
307
- pass
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
  [tool.poetry]
2
2
  name = "python-httpfile"
3
- version = "0.0.1.3"
4
- description = "Python httpfile classes."
3
+ version = "0.0.2.1"
4
+ description = "Python httpfile."
5
5
  authors = ["ChenyangGao <wosiwujm@gmail.com>"]
6
6
  license = "MIT"
7
7
  readme = "readme.md"
@@ -28,7 +28,6 @@ include = [
28
28
  [tool.poetry.dependencies]
29
29
  python = "^3.10"
30
30
  http_response = "*"
31
- python-filewrap = "*"
32
31
  python-property = "*"
33
32
  python-urlopen = "*"
34
33
 
@@ -1,4 +1,4 @@
1
- # Python httpfile classes.
1
+ # Python httpfile.
2
2
 
3
3
  ## Installation
4
4