MCPcopy Create free account
hub / github.com/mitmproxy/mitmproxy / convert_to_strings

Method convert_to_strings

examples/contrib/jsondump.py:157–170  ·  view source on GitHub ↗

Recursively convert all list/dict elements of type `bytes` into strings.

(cls, obj)

Source from the content-addressed store, hash-verified

155
156 @classmethod
157 def convert_to_strings(cls, obj):
158 """
159 Recursively convert all list/dict elements of type `bytes` into strings.
160 """
161 if isinstance(obj, dict):
162 return {
163 cls.convert_to_strings(key): cls.convert_to_strings(value)
164 for key, value in obj.items()
165 }
166 elif isinstance(obj, list) or isinstance(obj, tuple):
167 return [cls.convert_to_strings(element) for element in obj]
168 elif isinstance(obj, bytes):
169 return str(obj)[2:-1]
170 return obj
171
172 def worker(self):
173 while True:

Callers 1

dumpMethod · 0.95

Calls 1

itemsMethod · 0.45

Tested by

no test coverage detected