drb-driver-http 1.3.1__tar.gz → 1.3.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.
Files changed (31) hide show
  1. {drb-driver-http-1.3.1/drb_driver_http.egg-info → drb_driver_http-1.3.3}/PKG-INFO +1 -1
  2. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/drb/drivers/http/_version.py +3 -3
  3. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/drb/drivers/http/http.py +44 -21
  4. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3/drb_driver_http.egg-info}/PKG-INFO +1 -1
  5. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/tests/test_drb_impl_http.py +22 -11
  6. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/LICENCE.txt +0 -0
  7. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/README.md +0 -0
  8. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/drb/drivers/http/__init__.py +0 -0
  9. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/drb/drivers/http/oauth2/HTTPOAuth2.py +0 -0
  10. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/drb/drivers/http/oauth2/__init__.py +0 -0
  11. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/drb/drivers/http/oauth2/oauth2.py +0 -0
  12. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/drb/exceptions/http.py +0 -0
  13. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/drb/topics/http/__init__.py +0 -0
  14. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/drb/topics/http/cortex.yml +0 -0
  15. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/drb_driver_http.egg-info/SOURCES.txt +0 -0
  16. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/drb_driver_http.egg-info/dependency_links.txt +0 -0
  17. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/drb_driver_http.egg-info/entry_points.txt +0 -0
  18. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/drb_driver_http.egg-info/not-zip-safe +0 -0
  19. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/drb_driver_http.egg-info/requires.txt +0 -0
  20. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/drb_driver_http.egg-info/top_level.txt +0 -0
  21. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/pyproject.toml +0 -0
  22. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/requirements.txt +0 -0
  23. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/setup.cfg +0 -0
  24. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/setup.py +0 -0
  25. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/tests/test_drb_http_basic_auth.py +0 -0
  26. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/tests/test_drb_http_bearer.py +0 -0
  27. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/tests/test_drb_http_factory.py +0 -0
  28. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/tests/test_drb_http_keyring.py +0 -0
  29. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/tests/test_drb_http_signature.py +0 -0
  30. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/tests/test_drb_https_signature.py +0 -0
  31. {drb-driver-http-1.3.1 → drb_driver_http-1.3.3}/versioneer.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: drb-driver-http
3
- Version: 1.3.1
3
+ Version: 1.3.3
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-14T16:16:21+0200",
11
+ "date": "2024-07-17T16:46:34+0200",
12
12
  "dirty": false,
13
13
  "error": null,
14
- "full-revisionid": "e8e3f8c3ce65c7a98575a78a465359b93985cd40",
15
- "version": "1.3.1"
14
+ "full-revisionid": "01ab0f4e348f4e8040b143a8b51ae258bb9c7662",
15
+ "version": "1.3.3"
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,20 +249,30 @@ 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
- self @= (x, res.headers[x])
275
+ self.__imatmul__((x, res.headers[x]))
262
276
 
263
277
  @property
264
278
  def name(self) -> str:
@@ -297,6 +311,18 @@ class DrbHttpNode(AbstractNode):
297
311
  def __delitem__(self, key):
298
312
  raise NotImplementedError
299
313
 
314
+ def __matmul__(self, other):
315
+ new_other = other
316
+ if isinstance(other, str):
317
+ new_other = other.lower(), None
318
+ if isinstance(other, tuple):
319
+ new_other = (other[0].lower(), *other[1:])
320
+ return super().__matmul__(new_other)
321
+
322
+ def __imatmul__(self, other):
323
+ new_other = (other[0].lower(), *other[1:])
324
+ super().__imatmul__(new_other)
325
+
300
326
  @property
301
327
  def params(self):
302
328
  return self._params
@@ -314,20 +340,13 @@ class DrbHttpNode(AbstractNode):
314
340
  reason='Usage of the @ operator is recommended')
315
341
  def attributes(self) -> Dict[Tuple[str | Any, None], Any]:
316
342
  self.__init_header()
317
- attributes = {}
318
- for k, v in self._attrs.items():
319
- if k[0].lower() == 'content-type':
320
- new_k = 'Content-Type'
321
- else:
322
- new_k = k[0]
323
- attributes[(new_k, None)] = self @ k[0]
324
- return attributes
343
+ return self._attrs.copy()
325
344
 
326
345
  @deprecated(version='1.2.0',
327
346
  reason='Usage of the @ operator is recommended')
328
347
  def get_attribute(self, name: str, namespace_uri: str = None) -> Any:
329
348
  self.__init_header()
330
- key = (name, namespace_uri)
349
+ key = (name.lower(), namespace_uri)
331
350
  if namespace_uri is None and key in self.attributes.keys():
332
351
  return self.attributes[key]
333
352
  raise DrbException(f'Attribute not found name: {name}, '
@@ -337,7 +356,8 @@ class DrbHttpNode(AbstractNode):
337
356
  def post(url: str,
338
357
  headers: dict = None,
339
358
  data: dict = None,
340
- auth: AuthBase = None
359
+ auth: AuthBase = None,
360
+ redirect=True
341
361
  ) -> DrbNode:
342
362
  """
343
363
  Send a post request with the headers and
@@ -349,10 +369,12 @@ class DrbHttpNode(AbstractNode):
349
369
  object to send in the body.
350
370
  data (dict): json data to send in the body.
351
371
  auth (AuthBase)
372
+ redirect (Bool)
352
373
  """
353
374
  response = requests.post(url=url,
354
375
  headers=headers,
355
376
  json=data,
377
+ allow_redirects=redirect,
356
378
  auth=auth)
357
379
  return DrbHttpResponse(path=url, response=response)
358
380
 
@@ -365,7 +387,8 @@ def _to_stream(node: DrbHttpNode, **kwargs):
365
387
  else:
366
388
  headers = (kwargs.get('start'),)
367
389
  return Download(node.path.name, node.auth, node.params, headers,
368
- kwargs.get('chunk_size', 4 * 1048576))
390
+ kwargs.get('chunk_size', 4 * 1048576),
391
+ kwargs.get('redirect', True))
369
392
 
370
393
 
371
394
  class DrbHttpResponse(DrbHttpNode):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: drb-driver-http
3
- Version: 1.3.1
3
+ Version: 1.3.3
4
4
  Summary: DRB Http driver
5
5
  Author: GAEL Systems
6
6
  Author-email: drb-python@gael.fr
@@ -1,5 +1,6 @@
1
1
  import io
2
2
  import json
3
+ import sys
3
4
  import unittest
4
5
  from multiprocessing import Process
5
6
 
@@ -101,18 +102,15 @@ class TestDrbHttp(unittest.TestCase):
101
102
  self.assertEqual('test', stream.read(4).decode())
102
103
 
103
104
  def test_impl_argument(self):
104
- key = ('params', None)
105
- self.assertEqual(
106
- requests.head(self.url_ok,
107
- params={'key': 'value'}).headers[key[0]],
108
- DrbHttpNode(self.url_ok,
109
- params={'key': 'value'}).attributes[key]
110
- )
105
+ header_key = 'Content-Type'
106
+ header_value = requests.head(self.url_ok).headers[header_key]
107
+ node = DrbHttpNode(self.url_ok, params={"cookies": None})
108
+ self.assertEqual(header_value, node.get_attribute(header_key))
111
109
 
112
110
  def test_impl_none_argument(self):
113
111
  key = ('params', None)
114
112
  with self.assertRaises(KeyError):
115
- DrbHttpNode(self.url_ok, params=None).attributes[key]
113
+ DrbHttpNode(self.url_ok, params={}).attributes[key]
116
114
 
117
115
  def test_impl_no_argument(self):
118
116
  key = ('params', None)
@@ -136,10 +134,22 @@ class TestDrbHttp(unittest.TestCase):
136
134
  self.assertIsNone(node.parent)
137
135
 
138
136
  def test_attributes(self):
139
- key = ('Content-Type', None)
137
+ header_key = "Content-Type"
138
+ header_value = requests.head(self.url_ok).headers[header_key]
139
+ node = DrbHttpNode(self.url_ok)
140
+
140
141
  self.assertEqual(
141
- requests.head(self.url_ok).headers[key[0]],
142
- DrbHttpNode(self.url_ok).attributes[key])
142
+ header_value,
143
+ node.attributes[header_key.lower(), None]
144
+ )
145
+
146
+ self.assertEqual(header_value, node.get_attribute(header_key))
147
+ self.assertEqual(header_value, node.get_attribute(header_key.lower()))
148
+
149
+ self.assertEqual(header_value, node @ header_key)
150
+ self.assertEqual(header_value, node @ (header_key, None))
151
+ self.assertEqual(header_value, node @ header_key.lower())
152
+ self.assertEqual(header_value, node @ (header_key.lower(), None))
143
153
 
144
154
  def test_wrong_attributes(self):
145
155
  with self.assertRaises(DrbException):
@@ -197,4 +207,5 @@ class TestDrbHttp(unittest.TestCase):
197
207
  url='http://localhost:8756/resources/test.txt',
198
208
  headers={'Content-Type': 'application/json'},
199
209
  json='{"test1": "value1", "test2": "value2"}',
210
+ allow_redirects=True,
200
211
  auth=None)