MCPcopy Create free account
hub / github.com/EasyIME/PIME / recursive_unicode

Function recursive_unicode

python/python3/tornado/escape.py:242–258  ·  view source on GitHub ↗

Walks a simple data structure, converting byte strings to unicode. Supports lists, tuples, and dictionaries.

(obj: Any)

Source from the content-addressed store, hash-verified

240
241
242def recursive_unicode(obj: Any) -> Any:
243 """Walks a simple data structure, converting byte strings to unicode.
244
245 Supports lists, tuples, and dictionaries.
246 """
247 if isinstance(obj, dict):
248 return dict(
249 (recursive_unicode(k), recursive_unicode(v)) for (k, v) in obj.items()
250 )
251 elif isinstance(obj, list):
252 return list(recursive_unicode(i) for i in obj)
253 elif isinstance(obj, tuple):
254 return tuple(recursive_unicode(i) for i in obj)
255 elif isinstance(obj, bytes):
256 return to_unicode(obj)
257 else:
258 return obj
259
260
261# I originally used the regex from

Callers 4

getMethod · 0.90
postMethod · 0.90
getMethod · 0.90

Calls 3

listFunction · 0.85
to_unicodeFunction · 0.85
itemsMethod · 0.80

Tested by 4

getMethod · 0.72
postMethod · 0.72
getMethod · 0.72