4
4
from json .decoder import JSONDecodeError
5
5
from typing import Any
6
6
from typing import Callable
7
- from typing import Dict
8
7
from typing import List
8
+ from typing import Mapping
9
+ from typing import MutableMapping
9
10
from typing import Optional
10
11
from typing import Pattern
11
12
from typing import Tuple
17
18
from urllib3 .util .url import parse_url
18
19
19
20
20
- def _create_key_val_str (input_dict : Union [Dict [Any , Any ], Any ]) -> str :
21
+ def _create_key_val_str (input_dict : Union [Mapping [Any , Any ], Any ]) -> str :
21
22
"""
22
23
Returns string of format {'key': val, 'key2': val2}
23
24
Function is called recursively for nested dictionaries
@@ -57,8 +58,8 @@ def list_to_str(input_list: List[str]) -> str:
57
58
58
59
59
60
def _filter_dict_recursively (
60
- dict1 : Dict [Any , Any ], dict2 : Dict [Any , Any ]
61
- ) -> Dict [Any , Any ]:
61
+ dict1 : Mapping [Any , Any ], dict2 : Mapping [Any , Any ]
62
+ ) -> Mapping [Any , Any ]:
62
63
filtered_dict = {}
63
64
for k , val in dict1 .items ():
64
65
if k in dict2 :
@@ -70,7 +71,7 @@ def _filter_dict_recursively(
70
71
71
72
72
73
def urlencoded_params_matcher (
73
- params : Optional [Dict [str , str ]], * , allow_blank : bool = False
74
+ params : Optional [Mapping [str , str ]], * , allow_blank : bool = False
74
75
) -> Callable [..., Any ]:
75
76
"""
76
77
Matches URL encoded data
@@ -100,7 +101,7 @@ def match(request: PreparedRequest) -> Tuple[bool, str]:
100
101
101
102
102
103
def json_params_matcher (
103
- params : Optional [Union [Dict [str , Any ], List [Any ]]], * , strict_match : bool = True
104
+ params : Optional [Union [Mapping [str , Any ], List [Any ]]], * , strict_match : bool = True
104
105
) -> Callable [..., Any ]:
105
106
"""Matches JSON encoded data of request body.
106
107
@@ -192,7 +193,7 @@ def match(request: PreparedRequest) -> Tuple[bool, str]:
192
193
193
194
194
195
def query_param_matcher (
195
- params : Optional [Dict [str , Any ]], * , strict_match : bool = True
196
+ params : Optional [MutableMapping [str , Any ]], * , strict_match : bool = True
196
197
) -> Callable [..., Any ]:
197
198
"""Matcher to match 'params' argument in request.
198
199
@@ -276,7 +277,7 @@ def match(request: PreparedRequest) -> Tuple[bool, str]:
276
277
return match
277
278
278
279
279
- def request_kwargs_matcher (kwargs : Optional [Dict [str , Any ]]) -> Callable [..., Any ]:
280
+ def request_kwargs_matcher (kwargs : Optional [Mapping [str , Any ]]) -> Callable [..., Any ]:
280
281
"""
281
282
Matcher to match keyword arguments provided to request
282
283
@@ -308,7 +309,7 @@ def match(request: PreparedRequest) -> Tuple[bool, str]:
308
309
309
310
310
311
def multipart_matcher (
311
- files : Dict [str , Any ], data : Optional [Dict [str , str ]] = None
312
+ files : Mapping [str , Any ], data : Optional [Mapping [str , str ]] = None
312
313
) -> Callable [..., Any ]:
313
314
"""
314
315
Matcher to match 'multipart/form-data' content-type.
@@ -392,7 +393,7 @@ def match(request: PreparedRequest) -> Tuple[bool, str]:
392
393
393
394
394
395
def header_matcher (
395
- headers : Dict [str , Union [str , Pattern [str ]]], strict_match : bool = False
396
+ headers : Mapping [str , Union [str , Pattern [str ]]], strict_match : bool = False
396
397
) -> Callable [..., Any ]:
397
398
"""
398
399
Matcher to match 'headers' argument in request using the responses library.
@@ -408,7 +409,7 @@ def header_matcher(
408
409
:return: (func) matcher
409
410
"""
410
411
411
- def _compare_with_regex (request_headers : Union [Dict [Any , Any ], Any ]) -> bool :
412
+ def _compare_with_regex (request_headers : Union [Mapping [Any , Any ], Any ]) -> bool :
412
413
if strict_match and len (request_headers ) != len (headers ):
413
414
return False
414
415
@@ -426,7 +427,7 @@ def _compare_with_regex(request_headers: Union[Dict[Any, Any], Any]) -> bool:
426
427
return True
427
428
428
429
def match (request : PreparedRequest ) -> Tuple [bool , str ]:
429
- request_headers : Union [Dict [Any , Any ], Any ] = request .headers or {}
430
+ request_headers : Union [Mapping [Any , Any ], Any ] = request .headers or {}
430
431
431
432
if not strict_match :
432
433
# filter down to just the headers specified in the matcher
0 commit comments