unzip-http 0.8__tar.gz → 0.9__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.4
2
2
  Name: unzip-http
3
- Version: 0.8
3
+ Version: 0.9
4
4
  Summary: extract files from .zip files over http without downloading entire archive
5
5
  Author: Saul Pwanson
6
6
  Project-URL: Homepage, https://github.com/saulpw/unzip-http
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "unzip-http"
7
- version = "0.8"
7
+ version = "0.9"
8
8
  description = "extract files from .zip files over http without downloading entire archive"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: unzip-http
3
- Version: 0.8
3
+ Version: 0.9
4
4
  Summary: extract files from .zip files over http without downloading entire archive
5
5
  Author: Saul Pwanson
6
6
  Project-URL: Homepage, https://github.com/saulpw/unzip-http
@@ -56,7 +56,7 @@ import pathlib
56
56
  import urllib.parse
57
57
 
58
58
 
59
- __version__ = '0.8'
59
+ __version__ = '0.9'
60
60
 
61
61
 
62
62
  def error(s):
@@ -137,6 +137,11 @@ class RemoteZipFile:
137
137
  import urllib3
138
138
  self.url = url
139
139
  self.http = urllib3.PoolManager()
140
+ self.default_headers = {
141
+ 'User-Agent': f'unzip-http/{__version__}',
142
+ 'Accept': '*/*',
143
+ 'Connection': 'keep-alive',
144
+ }
140
145
  self.zip_size = 0
141
146
 
142
147
  def __enter__(self):
@@ -158,7 +163,7 @@ class RemoteZipFile:
158
163
  return list(r.filename for r in self.infoiter())
159
164
 
160
165
  def infoiter(self):
161
- resp = self.http.request('HEAD', self.url)
166
+ resp = self._request('HEAD')
162
167
  if not (200 <= resp.status <= 299):
163
168
  error(f'cannot open URL: HTTP status {resp.status}')
164
169
 
@@ -245,8 +250,14 @@ class RemoteZipFile:
245
250
  for fn in members or self.namelist():
246
251
  self.extract(fn, path, pwd=pwd)
247
252
 
253
+ def _request(self, method, headers=None, preload_content=True):
254
+ h = dict(self.default_headers)
255
+ if headers:
256
+ h.update(headers)
257
+ return self.http.request(method, self.url, headers=h, preload_content=preload_content)
258
+
248
259
  def get_range(self, start, n):
249
- return self.http.request('GET', self.url, headers={'Range': f'bytes={start}-{start+n-1}'}, preload_content=False)
260
+ return self._request('GET', headers={'Range': f'bytes={start}-{start+n-1}'}, preload_content=False)
250
261
 
251
262
  def matching_files(self, *globs):
252
263
  for f in self.files.values():
File without changes
File without changes
File without changes
File without changes