python-httpfile 0.0.5__py3-none-any.whl → 0.0.5.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 CHANGED
@@ -106,13 +106,13 @@ class HTTPFileReader(RawIOBase, BinaryIO):
106
106
  urlopen = urlopen,
107
107
  ):
108
108
  if headers:
109
- headers = {**headers, "Accept-Encoding": "identity"}
109
+ headers = {**headers, "accept-encoding": "identity"}
110
110
  else:
111
- headers = {"Accept-Encoding": "identity"}
111
+ headers = {"accept-encoding": "identity"}
112
112
  if start > 0:
113
- headers["Range"] = f"bytes={start}-"
113
+ headers["range"] = f"bytes={start}-"
114
114
  elif start < 0:
115
- headers["Range"] = f"bytes={start}"
115
+ headers["range"] = f"bytes={start}"
116
116
  if urlopen is None:
117
117
  urlopen = globals()["urlopen"]
118
118
  if callable(url):
@@ -316,7 +316,7 @@ class HTTPFileReader(RawIOBase, BinaryIO):
316
316
  url = self.url
317
317
  response = self.urlopen(
318
318
  url() if callable(url) else url,
319
- headers={**self.headers, "Range": f"bytes={start}-"}
319
+ headers={**self.headers, "range": f"bytes={start}-"}
320
320
  )
321
321
  length_new = get_total_length(response)
322
322
  if self.length != length_new:
@@ -572,13 +572,13 @@ class AsyncHTTPFileReader(HTTPFileReader):
572
572
  urlopen = None,
573
573
  ):
574
574
  if headers:
575
- headers = {**headers, "Accept-Encoding": "identity"}
575
+ headers = {**headers, "accept-encoding": "identity"}
576
576
  else:
577
- headers = {"Accept-Encoding": "identity"}
577
+ headers = {"accept-encoding": "identity"}
578
578
  if start > 0:
579
- headers["Range"] = f"bytes={start}-"
579
+ headers["range"] = f"bytes={start}-"
580
580
  elif start < 0:
581
- headers["Range"] = f"bytes={start}"
581
+ headers["range"] = f"bytes={start}"
582
582
  if urlopen is None:
583
583
  urlopen = globals()["urlopen"]
584
584
  if callable(url):
@@ -751,7 +751,7 @@ class AsyncHTTPFileReader(HTTPFileReader):
751
751
  url = self.url
752
752
  response = await self.urlopen(
753
753
  (await url()) if callable(url) else url,
754
- headers={**self.headers, "Range": f"bytes={start}-"}
754
+ headers={**self.headers, "range": f"bytes={start}-"}
755
755
  )
756
756
  length_new = get_total_length(response)
757
757
  if self.length != length_new:
@@ -1068,33 +1068,17 @@ if find_spec("aiohttp"):
1068
1068
  global _aiohttp_urlopen
1069
1069
  from aiohttp import request, ClientSession
1070
1070
 
1071
- close_session = True
1072
1071
  if isinstance(urlopen, ClientSession):
1073
1072
  urlopen = urlopen.get
1074
- close_session = False
1075
- if urlopen is None:
1073
+ elif urlopen is None:
1076
1074
  if _aiohttp_urlopen is None:
1077
1075
  urlopen = _aiohttp_urlopen = partial(request, "GET")
1078
1076
  else:
1079
1077
  urlopen = _aiohttp_urlopen
1080
- else:
1081
- func = urlopen
1082
- if isinstance(func, partial):
1083
- func = func.func
1084
- close_session = not (
1085
- isinstance(func, MethodType) and
1086
- isinstance(func.__self__, ClientSession)
1087
- )
1088
1078
  async def urlopen_wrapper(url: str, headers: None | Mapping = headers):
1089
- resp = await urlopen(url, headers=headers).__aenter__()
1090
- async def aclose():
1091
- if close_session:
1092
- try:
1093
- await resp._session.close()
1094
- except AttributeError:
1095
- pass
1096
- resp.close()
1097
- resp.aclose = aclose
1079
+ ctx = urlopen(url, headers=headers)
1080
+ resp = await ctx.__aenter__()
1081
+ resp.aclose = lambda: ctx.__aexit__(None, None, None)
1098
1082
  resp.raise_for_status()
1099
1083
  return resp
1100
1084
  await super().__ainit__(
@@ -1133,7 +1117,7 @@ if find_spec("httpx"):
1133
1117
  if "__del__" not in Client.__dict__:
1134
1118
  setattr(Client, "__del__", lambda self: self.close())
1135
1119
  session = Client()
1136
- return session.send(
1120
+ resp = session.send(
1137
1121
  request=session.build_request(
1138
1122
  method=method,
1139
1123
  url=url,
@@ -1143,6 +1127,8 @@ if find_spec("httpx"):
1143
1127
  follow_redirects=follow_redirects,
1144
1128
  stream=stream,
1145
1129
  )
1130
+ setattr(resp, "session", session)
1131
+ return resp
1146
1132
 
1147
1133
  async def httpx_request_async(
1148
1134
  url,
@@ -1158,7 +1144,7 @@ if find_spec("httpx"):
1158
1144
  if "__del__" not in AsyncClient.__dict__:
1159
1145
  setattr(AsyncClient, "__del__", lambda self: run_async(self.aclose()))
1160
1146
  session = AsyncClient()
1161
- return await session.send(
1147
+ resp = await session.send(
1162
1148
  request=session.build_request(
1163
1149
  method=method,
1164
1150
  url=url,
@@ -1168,6 +1154,8 @@ if find_spec("httpx"):
1168
1154
  follow_redirects=follow_redirects,
1169
1155
  stream=stream,
1170
1156
  )
1157
+ setattr(resp, "session", session)
1158
+ return resp
1171
1159
 
1172
1160
  class HttpxFileReader(HTTPFileReader):
1173
1161
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-httpfile
3
- Version: 0.0.5
3
+ Version: 0.0.5.2
4
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
@@ -17,6 +17,7 @@ Classifier: Programming Language :: Python :: 3
17
17
  Classifier: Programming Language :: Python :: 3.10
18
18
  Classifier: Programming Language :: Python :: 3.11
19
19
  Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
20
21
  Classifier: Programming Language :: Python :: 3 :: Only
21
22
  Classifier: Topic :: Software Development
22
23
  Classifier: Topic :: Software Development :: Libraries
@@ -0,0 +1,7 @@
1
+ LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
2
+ httpfile/__init__.py,sha256=Yvl34ufRAYFn2-838EsMrI76b35RIUs7Eoe6w1By9nI,39596
3
+ httpfile/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ python_httpfile-0.0.5.2.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
5
+ python_httpfile-0.0.5.2.dist-info/METADATA,sha256=uDfS48QDTCjGCV_6JPeWZFwQZWUnjYnmrM0D-GGK_mw,1573
6
+ python_httpfile-0.0.5.2.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
7
+ python_httpfile-0.0.5.2.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.8.1
2
+ Generator: poetry-core 1.9.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,7 +0,0 @@
1
- LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
2
- httpfile/__init__.py,sha256=2T_eq8cMUIciKfxX2ZQZxm1Uv-XHCHfMqK970i2wjm0,40057
3
- httpfile/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- python_httpfile-0.0.5.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
5
- python_httpfile-0.0.5.dist-info/METADATA,sha256=R4AglpLv8hg9G4Aa5RhNrY_NTJqS5Yk7BB2NeEeA_gk,1520
6
- python_httpfile-0.0.5.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
7
- python_httpfile-0.0.5.dist-info/RECORD,,