99from datetime import datetime , timedelta
1010from urllib .parse import urlparse , urlunsplit , parse_qs
1111
12+
13+ try :
14+ from os import PathLike
15+ except ImportError :
16+ # PathLike was added in Python 3.6 so fallback to PurePath on Python 3.5 as
17+ # all builtin Path objects inherit from PurePath
18+ from pathlib import PurePath as PathLike # type: ignore
19+
20+
1221MAX_PAYLOAD_LENGTH = 128 * 1024
1322MAX_STRING_LENGTH = 1024
1423
@@ -81,6 +90,9 @@ def filter_string_values(self, obj, ignored=None, seen=None):
8190 clean_dict [key ] = self .filter_string_values (
8291 value , ignored , seen )
8392
93+ # Only ignore whilst encoding children
94+ ignored .remove (id (obj ))
95+
8496 return clean_dict
8597
8698 return obj
@@ -119,16 +131,25 @@ def _sanitize(self, obj, trim_strings, ignored=None, seen=None):
119131 if id (obj ) in ignored :
120132 return self .recursive_value
121133 elif isinstance (obj , dict ):
122- ignored .add (id (obj ))
123134 seen .append (obj )
124- return self ._sanitize_dict (obj , trim_strings , ignored , seen )
125- elif isinstance (obj , (set , tuple , list )):
135+
126136 ignored .add (id (obj ))
137+ sanitized = self ._sanitize_dict (obj , trim_strings , ignored , seen )
138+ # Only ignore whilst encoding children
139+ ignored .remove (id (obj ))
140+
141+ return sanitized
142+ elif isinstance (obj , (set , tuple , list )):
127143 seen .append (obj )
144+
145+ ignored .add (id (obj ))
128146 items = []
129147 for value in obj :
130148 items .append (
131149 self ._sanitize (value , trim_strings , ignored , seen ))
150+ # Only ignore whilst encoding children
151+ ignored .remove (id (obj ))
152+
132153 return items
133154 elif trim_strings and isinstance (obj , str ):
134155 return obj [:MAX_STRING_LENGTH ]
@@ -243,7 +264,7 @@ def is_json_content_type(value: str) -> bool:
243264_ignore_modules = ('__main__' , 'builtins' )
244265
245266
246- def fully_qualified_class_name (obj ):
267+ def partly_qualified_class_name (obj ):
247268 module = inspect .getmodule (obj )
248269
249270 if module is None or module .__name__ in _ignore_modules :
@@ -252,6 +273,19 @@ def fully_qualified_class_name(obj):
252273 return module .__name__ + '.' + obj .__class__ .__name__
253274
254275
276+ def fully_qualified_class_name (obj ):
277+ module = inspect .getmodule (obj )
278+ if hasattr (obj .__class__ , "__qualname__" ):
279+ qualified_name = obj .__class__ .__qualname__
280+ else :
281+ qualified_name = obj .__class__ .__name__
282+
283+ if module is None or module .__name__ in _ignore_modules :
284+ return qualified_name
285+
286+ return module .__name__ + '.' + qualified_name
287+
288+
255289def package_version (package_name ):
256290 try :
257291 import pkg_resources
@@ -293,6 +327,7 @@ def wrapper(obj, value):
293327validate_bool_setter = partial (_validate_setter , (bool ,))
294328validate_iterable_setter = partial (_validate_setter , (list , tuple ))
295329validate_int_setter = partial (_validate_setter , (int ,))
330+ validate_path_setter = partial (_validate_setter , (str , PathLike ))
296331
297332
298333class ThreadContextVar :
0 commit comments