python-httpfile 0.0.4.1__tar.gz → 0.0.4.3__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.
- {python_httpfile-0.0.4.1 → python_httpfile-0.0.4.3}/PKG-INFO +1 -1
- {python_httpfile-0.0.4.1 → python_httpfile-0.0.4.3}/httpfile/__init__.py +40 -5
- {python_httpfile-0.0.4.1 → python_httpfile-0.0.4.3}/pyproject.toml +1 -1
- {python_httpfile-0.0.4.1 → python_httpfile-0.0.4.3}/LICENSE +0 -0
- {python_httpfile-0.0.4.1 → python_httpfile-0.0.4.3}/httpfile/py.typed +0 -0
- {python_httpfile-0.0.4.1 → python_httpfile-0.0.4.3}/readme.md +0 -0
|
@@ -215,6 +215,8 @@ class HTTPFileReader(RawIOBase, BinaryIO):
|
|
|
215
215
|
return self.file.fileno()
|
|
216
216
|
|
|
217
217
|
def flush(self, /):
|
|
218
|
+
if self.closed:
|
|
219
|
+
raise ValueError("I/O operation on closed file.")
|
|
218
220
|
return self.file.flush()
|
|
219
221
|
|
|
220
222
|
def isatty(self, /) -> bool:
|
|
@@ -533,7 +535,8 @@ class AsyncHTTPFileReader(HTTPFileReader):
|
|
|
533
535
|
seek_threshold: int = 1 << 20,
|
|
534
536
|
urlopen = None,
|
|
535
537
|
):
|
|
536
|
-
|
|
538
|
+
self.__dict__.update(closed=False, start=0)
|
|
539
|
+
self.__dict__["_initing"] = run_async(self.__ainit__(
|
|
537
540
|
url=url,
|
|
538
541
|
headers=headers,
|
|
539
542
|
start=start,
|
|
@@ -542,6 +545,9 @@ class AsyncHTTPFileReader(HTTPFileReader):
|
|
|
542
545
|
))
|
|
543
546
|
|
|
544
547
|
async def __aenter__(self, /) -> Self:
|
|
548
|
+
if _initing := self.__dict__.get("_initing"):
|
|
549
|
+
await _initing
|
|
550
|
+
self.__dict__.pop("_initing", None)
|
|
545
551
|
return self
|
|
546
552
|
|
|
547
553
|
async def __aexit__(self, /, *exc_info):
|
|
@@ -602,12 +608,12 @@ class AsyncHTTPFileReader(HTTPFileReader):
|
|
|
602
608
|
length = get_total_length(response) or 0,
|
|
603
609
|
chunked = is_chunked(response),
|
|
604
610
|
start = start,
|
|
605
|
-
closed = False,
|
|
606
611
|
urlopen = urlopen,
|
|
607
612
|
headers = MappingProxyType(headers),
|
|
608
613
|
seek_threshold = max(seek_threshold, 0),
|
|
609
614
|
_seekable = is_range_request(response),
|
|
610
615
|
)
|
|
616
|
+
self.__dict__.pop("_initing", None)
|
|
611
617
|
|
|
612
618
|
async def aclose(self, /):
|
|
613
619
|
if not self.closed:
|
|
@@ -620,7 +626,10 @@ class AsyncHTTPFileReader(HTTPFileReader):
|
|
|
620
626
|
try:
|
|
621
627
|
ret = self.response.aclose()
|
|
622
628
|
except (AttributeError, TypeError):
|
|
623
|
-
|
|
629
|
+
try:
|
|
630
|
+
ret = self.response.close()
|
|
631
|
+
except (AttributeError, TypeError):
|
|
632
|
+
return
|
|
624
633
|
if isawaitable(ret):
|
|
625
634
|
run_async(ret)
|
|
626
635
|
|
|
@@ -628,16 +637,27 @@ class AsyncHTTPFileReader(HTTPFileReader):
|
|
|
628
637
|
try:
|
|
629
638
|
ret = self.response.aclose()
|
|
630
639
|
except (AttributeError, TypeError):
|
|
631
|
-
|
|
640
|
+
try:
|
|
641
|
+
ret = self.response.close()
|
|
642
|
+
except (AttributeError, TypeError):
|
|
643
|
+
return
|
|
632
644
|
if isawaitable(ret):
|
|
633
645
|
await ret
|
|
634
646
|
|
|
635
647
|
async def flush(self, /):
|
|
648
|
+
if self.closed:
|
|
649
|
+
raise ValueError("I/O operation on closed file.")
|
|
650
|
+
if _initing := self.__dict__.get("_initing"):
|
|
651
|
+
await _initing
|
|
652
|
+
self.__dict__.pop("_initing", None)
|
|
636
653
|
return await ensure_async(self.file.flush, threaded=True)()
|
|
637
654
|
|
|
638
655
|
async def read(self, size: int = -1, /) -> bytes: # type: ignore
|
|
639
656
|
if self.closed:
|
|
640
657
|
raise ValueError("I/O operation on closed file.")
|
|
658
|
+
if _initing := self.__dict__.get("_initing"):
|
|
659
|
+
await _initing
|
|
660
|
+
self.__dict__.pop("_initing", None)
|
|
641
661
|
if size == 0 or not self.chunked and self.tell() >= self.length:
|
|
642
662
|
return b""
|
|
643
663
|
if self.file_closed:
|
|
@@ -654,6 +674,9 @@ class AsyncHTTPFileReader(HTTPFileReader):
|
|
|
654
674
|
async def readinto(self, buffer, /) -> int: # type: ignore
|
|
655
675
|
if self.closed:
|
|
656
676
|
raise ValueError("I/O operation on closed file.")
|
|
677
|
+
if _initing := self.__dict__.get("_initing"):
|
|
678
|
+
await _initing
|
|
679
|
+
self.__dict__.pop("_initing", None)
|
|
657
680
|
if not buffer or not self.chunked and self.tell() >= self.length:
|
|
658
681
|
return 0
|
|
659
682
|
if self.file_closed:
|
|
@@ -675,6 +698,9 @@ class AsyncHTTPFileReader(HTTPFileReader):
|
|
|
675
698
|
async def readline(self, size: None | int = -1, /) -> bytes: # type: ignore
|
|
676
699
|
if self.closed:
|
|
677
700
|
raise ValueError("I/O operation on closed file.")
|
|
701
|
+
if _initing := self.__dict__.get("_initing"):
|
|
702
|
+
await _initing
|
|
703
|
+
self.__dict__.pop("_initing", None)
|
|
678
704
|
if size == 0 or not self.chunked and self.tell() >= self.length:
|
|
679
705
|
return b""
|
|
680
706
|
if self.file_closed:
|
|
@@ -691,6 +717,9 @@ class AsyncHTTPFileReader(HTTPFileReader):
|
|
|
691
717
|
async def readlines(self, hint: int = -1, /) -> list[bytes]: # type: ignore
|
|
692
718
|
if self.closed:
|
|
693
719
|
raise ValueError("I/O operation on closed file.")
|
|
720
|
+
if _initing := self.__dict__.get("_initing"):
|
|
721
|
+
await _initing
|
|
722
|
+
self.__dict__.pop("_initing", None)
|
|
694
723
|
if not self.chunked and self.tell() >= self.length:
|
|
695
724
|
return []
|
|
696
725
|
if self.file_closed:
|
|
@@ -702,6 +731,9 @@ class AsyncHTTPFileReader(HTTPFileReader):
|
|
|
702
731
|
return ls
|
|
703
732
|
|
|
704
733
|
async def reconnect(self, /, start: None | int = None) -> int: # type: ignore
|
|
734
|
+
if _initing := self.__dict__.get("_initing"):
|
|
735
|
+
await _initing
|
|
736
|
+
self.__dict__.pop("_initing", None)
|
|
705
737
|
if not self._seekable:
|
|
706
738
|
if start is None and self.tell() or start:
|
|
707
739
|
raise OSError(errno.EOPNOTSUPP, "Unsupport for reconnection of non-seekable streams.")
|
|
@@ -734,6 +766,9 @@ class AsyncHTTPFileReader(HTTPFileReader):
|
|
|
734
766
|
async def seek(self, pos: int, whence: int = 0, /) -> int: # type: ignore
|
|
735
767
|
if self.closed:
|
|
736
768
|
raise ValueError("I/O operation on closed file.")
|
|
769
|
+
if _initing := self.__dict__.get("_initing"):
|
|
770
|
+
await _initing
|
|
771
|
+
self.__dict__.pop("_initing", None)
|
|
737
772
|
if not self._seekable:
|
|
738
773
|
raise OSError(errno.EINVAL, "not a seekable stream")
|
|
739
774
|
if whence == 0:
|
|
@@ -1151,7 +1186,7 @@ if find_spec("httpx"):
|
|
|
1151
1186
|
elif urlopen is None:
|
|
1152
1187
|
if _httpx_urlopen_async is None:
|
|
1153
1188
|
if "__del__" not in AsyncClient.__dict__:
|
|
1154
|
-
|
|
1189
|
+
setattr(AsyncClient, "__del__", lambda self: run_async(self.aclose()))
|
|
1155
1190
|
def async_stream(
|
|
1156
1191
|
method,
|
|
1157
1192
|
url,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|