drb-driver-http 1.3.0__tar.gz → 1.3.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.
Files changed (31) hide show
  1. {drb-driver-http-1.3.0/drb_driver_http.egg-info → drb-driver-http-1.3.2}/PKG-INFO +1 -1
  2. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/drb/drivers/http/_version.py +3 -3
  3. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/drb/drivers/http/http.py +35 -11
  4. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2/drb_driver_http.egg-info}/PKG-INFO +1 -1
  5. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/tests/test_drb_impl_http.py +5 -4
  6. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/LICENCE.txt +0 -0
  7. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/README.md +0 -0
  8. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/drb/drivers/http/__init__.py +0 -0
  9. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/drb/drivers/http/oauth2/HTTPOAuth2.py +0 -0
  10. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/drb/drivers/http/oauth2/__init__.py +0 -0
  11. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/drb/drivers/http/oauth2/oauth2.py +0 -0
  12. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/drb/exceptions/http.py +0 -0
  13. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/drb/topics/http/__init__.py +0 -0
  14. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/drb/topics/http/cortex.yml +0 -0
  15. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/drb_driver_http.egg-info/SOURCES.txt +0 -0
  16. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/drb_driver_http.egg-info/dependency_links.txt +0 -0
  17. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/drb_driver_http.egg-info/entry_points.txt +0 -0
  18. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/drb_driver_http.egg-info/not-zip-safe +0 -0
  19. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/drb_driver_http.egg-info/requires.txt +0 -0
  20. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/drb_driver_http.egg-info/top_level.txt +0 -0
  21. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/pyproject.toml +0 -0
  22. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/requirements.txt +0 -0
  23. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/setup.cfg +0 -0
  24. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/setup.py +0 -0
  25. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/tests/test_drb_http_basic_auth.py +0 -0
  26. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/tests/test_drb_http_bearer.py +0 -0
  27. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/tests/test_drb_http_factory.py +0 -0
  28. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/tests/test_drb_http_keyring.py +0 -0
  29. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/tests/test_drb_http_signature.py +0 -0
  30. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/tests/test_drb_https_signature.py +0 -0
  31. {drb-driver-http-1.3.0 → drb-driver-http-1.3.2}/versioneer.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: drb-driver-http
3
- Version: 1.3.0
3
+ Version: 1.3.2
4
4
  Summary: DRB Http driver
5
5
  Author: GAEL Systems
6
6
  Author-email: drb-python@gael.fr
@@ -8,11 +8,11 @@ import json
8
8
 
9
9
  version_json = '''
10
10
  {
11
- "date": "2023-09-12T17:43:20+0200",
11
+ "date": "2023-12-11T14:19:01+0100",
12
12
  "dirty": false,
13
13
  "error": null,
14
- "full-revisionid": "38308644bfd44c075f46f5b42c6f3c2daca93a1e",
15
- "version": "1.3.0"
14
+ "full-revisionid": "fb65d1f92910d9d6874fa59b58719538fd74f5d5",
15
+ "version": "1.3.2"
16
16
  }
17
17
  ''' # END VERSION_JSON
18
18
 
@@ -6,9 +6,9 @@ import re
6
6
  import keyring
7
7
  from deprecated import deprecated
8
8
  from drb.core import DrbNode, ParsedPath, DrbFactory
9
- from drb.exceptions.core import DrbException, DrbNotImplementationException
9
+ from drb.exceptions.core import DrbException
10
10
  from drb.nodes.abstract_node import AbstractNode
11
- from typing import Any, Dict, List, Optional, Tuple
11
+ from typing import Any, Dict, List, Tuple
12
12
  from urllib.parse import urlparse
13
13
 
14
14
  import requests
@@ -27,9 +27,9 @@ from drb.exceptions.http import DrbHttpServerException, \
27
27
  @retry(stop=(stop_after_delay(120) | stop_after_attempt(5)),
28
28
  wait=wait_fixed(15),
29
29
  retry=retry_if_exception_type(DrbHttpNodeException))
30
- def get(path: str, auth: AuthBase, headers, params: Dict[str, str]):
31
- return requests.get(path, stream=True, auth=auth,
32
- headers=headers, params=params)
30
+ def get(path: str, auth: AuthBase, redirect, headers, params: Dict[str, Any]):
31
+ return requests.get(path, stream=True, auth=auth, allow_redirects=redirect,
32
+ headers=headers, **params)
33
33
 
34
34
 
35
35
  @retry(stop=stop_after_attempt(5),
@@ -38,11 +38,12 @@ def get(path: str, auth: AuthBase, headers, params: Dict[str, str]):
38
38
  @retry(stop=(stop_after_delay(120) | stop_after_attempt(5)),
39
39
  wait=wait_fixed(15),
40
40
  retry=retry_if_exception_type(DrbHttpNodeException))
41
- def head(path: str, auth: AuthBase, params: Dict[str, str]):
41
+ def head(path: str, auth: AuthBase, redirect, params: Dict[str, Any]):
42
42
  return requests.head(
43
43
  path,
44
44
  auth=auth,
45
- params=params
45
+ allow_redirects=redirect,
46
+ **params
46
47
  )
47
48
 
48
49
 
@@ -80,6 +81,7 @@ class Download(io.BytesIO):
80
81
  params: Dict[str, str],
81
82
  headers,
82
83
  chunk_size: int,
84
+ redirect=True
83
85
  ):
84
86
  self.__res = None
85
87
  self._chunk_size = chunk_size
@@ -91,6 +93,7 @@ class Download(io.BytesIO):
91
93
  self._buff = bytearray(0)
92
94
  self._pos = 0
93
95
  self._seekable = True
96
+ self._redirect = redirect
94
97
  self.content_length = -1
95
98
  super().__init__()
96
99
 
@@ -169,6 +172,7 @@ class Download(io.BytesIO):
169
172
  self.__res = get(
170
173
  self._path,
171
174
  self._auth,
175
+ self._redirect,
172
176
  heads,
173
177
  self._params
174
178
  )
@@ -245,17 +249,27 @@ class DrbHttpNode(AbstractNode):
245
249
  """
246
250
 
247
251
  def __init__(self, path, auth: AuthBase = None,
248
- params: Dict[str, str] = None):
252
+ redirect=True,
253
+ params: Dict[str, Any] = {}):
249
254
  super().__init__()
250
255
  self._path = path
251
256
  self._auth = auth
252
257
  self._params = params
253
258
  self._children = []
259
+ self._redirect = redirect
254
260
  self.add_impl(io.BytesIO, _to_stream)
255
261
 
256
262
  def __init_header(self):
257
263
  if len(self._attrs) == 0:
258
- res = head(self._path, self.auth, self._params)
264
+ res = head(self._path, self.auth, self._redirect, self._params)
265
+ if res.status_code == 405:
266
+ headers = {"Range": "bytes=0-0"}
267
+ res = get(path=self._path,
268
+ auth=self.auth,
269
+ redirect=self._redirect,
270
+ params=self._params,
271
+ headers=headers
272
+ )
259
273
  check_response(res)
260
274
  for x in res.headers:
261
275
  self @= (x, res.headers[x])
@@ -337,7 +351,8 @@ class DrbHttpNode(AbstractNode):
337
351
  def post(url: str,
338
352
  headers: dict = None,
339
353
  data: dict = None,
340
- auth: AuthBase = None
354
+ auth: AuthBase = None,
355
+ redirect=True
341
356
  ) -> DrbNode:
342
357
  """
343
358
  Send a post request with the headers and
@@ -349,10 +364,12 @@ class DrbHttpNode(AbstractNode):
349
364
  object to send in the body.
350
365
  data (dict): json data to send in the body.
351
366
  auth (AuthBase)
367
+ redirect (Bool)
352
368
  """
353
369
  response = requests.post(url=url,
354
370
  headers=headers,
355
371
  json=data,
372
+ allow_redirects=redirect,
356
373
  auth=auth)
357
374
  return DrbHttpResponse(path=url, response=response)
358
375
 
@@ -365,7 +382,8 @@ def _to_stream(node: DrbHttpNode, **kwargs):
365
382
  else:
366
383
  headers = (kwargs.get('start'),)
367
384
  return Download(node.path.name, node.auth, node.params, headers,
368
- kwargs.get('chunk_size', 4 * 1048576))
385
+ kwargs.get('chunk_size', 4 * 1048576),
386
+ kwargs.get('redirect', True))
369
387
 
370
388
 
371
389
  class DrbHttpResponse(DrbHttpNode):
@@ -377,6 +395,12 @@ class DrbHttpResponse(DrbHttpNode):
377
395
  (k, None): v for k, v in self._resp.headers.items()
378
396
  }
379
397
  self.value = response.content
398
+ self.add_impl(io.BytesIO, self._to_stream)
399
+
400
+ @staticmethod
401
+ def _to_stream(node: DrbNode, **kwargs):
402
+ if isinstance(node, DrbHttpResponse):
403
+ return io.BytesIO(node.value)
380
404
 
381
405
 
382
406
  class DrbHttpFactory(DrbFactory):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: drb-driver-http
3
- Version: 1.3.0
3
+ Version: 1.3.2
4
4
  Summary: DRB Http driver
5
5
  Author: GAEL Systems
6
6
  Author-email: drb-python@gael.fr
@@ -101,18 +101,18 @@ class TestDrbHttp(unittest.TestCase):
101
101
  self.assertEqual('test', stream.read(4).decode())
102
102
 
103
103
  def test_impl_argument(self):
104
- key = ('params', None)
104
+ key = ('Content-Type', None)
105
105
  self.assertEqual(
106
106
  requests.head(self.url_ok,
107
- params={'key': 'value'}).headers[key[0]],
107
+ params={"cookies": None}).headers[key[0]],
108
108
  DrbHttpNode(self.url_ok,
109
- params={'key': 'value'}).attributes[key]
109
+ params={"cookies": None}).attributes[key]
110
110
  )
111
111
 
112
112
  def test_impl_none_argument(self):
113
113
  key = ('params', None)
114
114
  with self.assertRaises(KeyError):
115
- DrbHttpNode(self.url_ok, params=None).attributes[key]
115
+ DrbHttpNode(self.url_ok, params={}).attributes[key]
116
116
 
117
117
  def test_impl_no_argument(self):
118
118
  key = ('params', None)
@@ -197,4 +197,5 @@ class TestDrbHttp(unittest.TestCase):
197
197
  url='http://localhost:8756/resources/test.txt',
198
198
  headers={'Content-Type': 'application/json'},
199
199
  json='{"test1": "value1", "test2": "value2"}',
200
+ allow_redirects=True,
200
201
  auth=None)