edq-utils 0.1.5__py3-none-any.whl → 0.1.7__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.

Potentially problematic release.


This version of edq-utils might be problematic. Click here for more details.

edq/__init__.py CHANGED
@@ -2,4 +2,4 @@
2
2
  General Python tools used by several EduLinq projects.
3
3
  """
4
4
 
5
- __version__ = '0.1.5'
5
+ __version__ = '0.1.7'
edq/util/net.py CHANGED
@@ -62,6 +62,7 @@ DEFAULT_EXCHANGE_IGNORE_HEADERS: typing.List[str] = [
62
62
  'etag',
63
63
  'host',
64
64
  'link',
65
+ 'location',
65
66
  'priority',
66
67
  'referrer-policy',
67
68
  'sec-fetch-dest',
@@ -174,11 +175,11 @@ class HTTPExchange(edq.util.json.DictConverter):
174
175
  parameters: typing.Union[typing.Dict[str, typing.Any], None] = None,
175
176
  files: typing.Union[typing.List[typing.Union[FileInfo, typing.Dict[str, str]]], None] = None,
176
177
  headers: typing.Union[typing.Dict[str, typing.Any], None] = None,
178
+ allow_redirects: typing.Union[bool, None] = None,
177
179
  response_code: int = http.HTTPStatus.OK,
178
180
  response_headers: typing.Union[typing.Dict[str, typing.Any], None] = None,
179
181
  json_body: typing.Union[bool, None] = None,
180
182
  response_body: typing.Union[str, dict, list, None] = None,
181
- read_write: bool = False,
182
183
  source_path: typing.Union[str, None] = None,
183
184
  response_modifier: typing.Union[str, None] = None,
184
185
  extra_options: typing.Union[typing.Dict[str, typing.Any], None] = None,
@@ -239,6 +240,12 @@ class HTTPExchange(edq.util.json.DictConverter):
239
240
  self.headers: typing.Dict[str, typing.Any] = headers
240
241
  """ Headers in the request. """
241
242
 
243
+ if (allow_redirects is None):
244
+ allow_redirects = True
245
+
246
+ self.allow_redirects: bool = allow_redirects
247
+ """ Follow redirects. """
248
+
242
249
  self.response_code: int = response_code
243
250
  """ The HTTP status code of the response. """
244
251
 
@@ -266,13 +273,6 @@ class HTTPExchange(edq.util.json.DictConverter):
266
273
  The response that should be sent in this exchange.
267
274
  """
268
275
 
269
- self.read_write: bool = read_write
270
- """
271
- Indicates that this exchange will change data on the server (regardless of the HTTP method).
272
- This field may be ignored by test servers,
273
- but may be observed by tools that generate or validate test data.
274
- """
275
-
276
276
  self.response_modifier: typing.Union[str, None] = response_modifier
277
277
  """
278
278
  This function reference will be used to modify responses (in HTTPExchange.make_request() and HTTPExchange.from_response())
@@ -320,7 +320,7 @@ class HTTPExchange(edq.util.json.DictConverter):
320
320
  if (url_path is not None):
321
321
  url_path = url_path.strip()
322
322
  if (url_path == ''):
323
- url_path = None
323
+ url_path = ''
324
324
  else:
325
325
  url_path = url_path.lstrip('/')
326
326
 
@@ -488,6 +488,7 @@ class HTTPExchange(edq.util.json.DictConverter):
488
488
  data = self.parameters,
489
489
  files = files,
490
490
  raise_for_status = raise_for_status,
491
+ allow_redirects = self.allow_redirects,
491
492
  **kwargs,
492
493
  )
493
494
 
@@ -577,6 +578,7 @@ class HTTPExchange(edq.util.json.DictConverter):
577
578
  response: requests.Response,
578
579
  headers_to_skip: typing.Union[typing.List[str], None] = None,
579
580
  params_to_skip: typing.Union[typing.List[str], None] = None,
581
+ allow_redirects: typing.Union[bool, None] = None,
580
582
  ) -> 'HTTPExchange':
581
583
  """ Create a full excahnge from a response. """
582
584
 
@@ -622,6 +624,7 @@ class HTTPExchange(edq.util.json.DictConverter):
622
624
  'response_headers': response_headers,
623
625
  'response_body': body,
624
626
  'response_modifier': _exchanges_clean_func,
627
+ 'allow_redirects': allow_redirects,
625
628
  }
626
629
 
627
630
  return HTTPExchange(**data)
@@ -688,6 +691,7 @@ def make_request(method: str, url: str,
688
691
  add_http_prefix: bool = True,
689
692
  additional_requests_options: typing.Union[typing.Dict[str, typing.Any], None] = None,
690
693
  exchange_complete_func: typing.Union[HTTPExchangeComplete, None] = None,
694
+ allow_redirects: typing.Union[bool, None] = None,
691
695
  **kwargs: typing.Any) -> typing.Tuple[requests.Response, str]:
692
696
  """
693
697
  Make an HTTP request and return the response object and text body.
@@ -725,6 +729,9 @@ def make_request(method: str, url: str,
725
729
  'timeout': timeout_secs,
726
730
  })
727
731
 
732
+ if (allow_redirects is not None):
733
+ options['allow_redirects'] = allow_redirects
734
+
728
735
  if (method == 'GET'):
729
736
  options['params'] = data
730
737
  else:
@@ -745,10 +752,16 @@ def make_request(method: str, url: str,
745
752
 
746
753
  exchange = None
747
754
  if ((output_dir is not None) or (exchange_complete_func is not None) or (_make_request_exchange_complete_func is not None)):
748
- exchange = HTTPExchange.from_response(response, headers_to_skip = headers_to_skip, params_to_skip = params_to_skip)
755
+ exchange = HTTPExchange.from_response(response,
756
+ headers_to_skip = headers_to_skip, params_to_skip = params_to_skip,
757
+ allow_redirects = options.get('allow_redirects', None))
749
758
 
750
759
  if ((output_dir is not None) and (exchange is not None)):
751
- path = os.path.abspath(os.path.join(output_dir, *exchange.get_url().split('/')))
760
+ url = exchange.get_url()
761
+ if (url == ''):
762
+ url = '_index_'
763
+
764
+ path = os.path.abspath(os.path.join(output_dir, *url.split('/')))
752
765
 
753
766
  query = urllib.parse.urlencode(exchange.parameters)
754
767
  if (query != ''):
@@ -887,13 +900,14 @@ def parse_content_dispositions(headers: typing.Union[email.message.Message, typi
887
900
 
888
901
  def parse_query_string(text: str,
889
902
  replace_single_lists: bool = True,
890
- ) -> typing.Dict[str, typing.Any]:
903
+ keep_blank_values: bool = True,
904
+ **kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
891
905
  """
892
906
  Parse a query string (like urllib.parse.parse_qs()), and normalize the result.
893
907
  If specified, lists with single values (as returned from urllib.parse.parse_qs()) will be replaced with the single value.
894
908
  """
895
909
 
896
- results = urllib.parse.parse_qs(text)
910
+ results = urllib.parse.parse_qs(text, keep_blank_values = True)
897
911
  for (key, value) in results.items():
898
912
  if (replace_single_lists and (len(value) == 1)):
899
913
  results[key] = value[0] # type: ignore[assignment]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: edq-utils
3
- Version: 0.1.5
3
+ Version: 0.1.7
4
4
  Summary: Common utilities used by EduLinq Python projects.
5
5
  Author-email: Eriq Augustine <eriq@edulinq.org>
6
6
  License: MIT License
@@ -1,4 +1,4 @@
1
- edq/__init__.py,sha256=JWuQig2oh9EbAaMaO0ZUA1GK6IWZ6OTe1Zv7BiGki-o,86
1
+ edq/__init__.py,sha256=xbXC-HRJTI836O3iQF83fS5uZKa5ZKLtVZepsb4VNYI,86
2
2
  edq/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  edq/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  edq/cli/version.py,sha256=SxarRVD_AVA-nD4pLVMe6ZjSJpMr7h_r3DgYYs42vjE,591
@@ -68,15 +68,15 @@ edq/util/hash.py,sha256=yjXGBCZNvMm49RaPCi9Ygf5FLUpGUrbVU7v8l8hn5Hc,1369
68
68
  edq/util/hash_test.py,sha256=GzvCwgPdzsOn5o63lE8cUurAnj-4arHnYCUcctTnWMQ,2714
69
69
  edq/util/json.py,sha256=nl_cxrlP97RX1BFtys8IT_3IfO0-XvBDQBe6YdrblB4,5936
70
70
  edq/util/json_test.py,sha256=utUVRbw3z42ke4fpRVI294RrFHcMKms8khVYRkISNk4,8009
71
- edq/util/net.py,sha256=3heVBv2PR8SkiNwFK3sW8qrdXiafpD1_TB2lbfFC0KE,34527
71
+ edq/util/net.py,sha256=nqpPBrPpSgRtZt3T28n812HGij_FTJlA9qFY3gbbVj4,34994
72
72
  edq/util/parse.py,sha256=zA-GGbY5WF-rfAcWFlnYjDXQaNkxhoyLJ8X81UceCLw,786
73
73
  edq/util/pyimport.py,sha256=26OIuCXELyqtwlooMqDEs4GJQrkrAgxnXNYTlqqtsBY,2852
74
74
  edq/util/pyimport_test.py,sha256=Xno0MIa3yMTfBfoTgjKCIMpr1ZShU6bvo9rBRdecXQU,4202
75
75
  edq/util/reflection.py,sha256=jPcW6h0fwSDYh04O5rUxlgoF7HK6fVQ2mq7DD9qPrEg,972
76
76
  edq/util/time.py,sha256=anoNM_KniARLombv2BnsoHuCzDqMKiDdIzV7RUe2ZOk,2648
77
77
  edq/util/time_test.py,sha256=iQZwzVTVQQ4TdXrLb9MUMCYlKrIe8qyF-hiC9YLTaMo,4610
78
- edq_utils-0.1.5.dist-info/licenses/LICENSE,sha256=MS4iYEl4rOxMoprZuc86iYVoyk4YgaVoMt7WmGvVF8w,1064
79
- edq_utils-0.1.5.dist-info/METADATA,sha256=hzjgzjrj2uICOExh_Ca7jHTMIMXmkImmvM-_1GY-69w,7535
80
- edq_utils-0.1.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
81
- edq_utils-0.1.5.dist-info/top_level.txt,sha256=znBHSj6tgXtcMKrUVtovLli5fIEJCb7d-BMxTLRK4zk,4
82
- edq_utils-0.1.5.dist-info/RECORD,,
78
+ edq_utils-0.1.7.dist-info/licenses/LICENSE,sha256=MS4iYEl4rOxMoprZuc86iYVoyk4YgaVoMt7WmGvVF8w,1064
79
+ edq_utils-0.1.7.dist-info/METADATA,sha256=EVIl5QNi9vaHmZLn_ngFKOPrjqeRZMCmm6trltRLR1I,7535
80
+ edq_utils-0.1.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
81
+ edq_utils-0.1.7.dist-info/top_level.txt,sha256=znBHSj6tgXtcMKrUVtovLli5fIEJCb7d-BMxTLRK4zk,4
82
+ edq_utils-0.1.7.dist-info/RECORD,,