python-httpfile 0.0.5.1__tar.gz → 0.0.5.2__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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-httpfile
3
- Version: 0.0.5.1
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
@@ -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
  [tool.poetry]
2
2
  name = "python-httpfile"
3
- version = "0.0.5.1"
3
+ version = "0.0.5.2"
4
4
  description = "Python httpfile."
5
5
  authors = ["ChenyangGao <wosiwujm@gmail.com>"]
6
6
  license = "MIT"