MCPcopy Index your code
hub / github.com/python/cpython / _sanitize

Function _sanitize

Lib/email/utils.py:60–66  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

58# How to deal with a string containing bytes before handing it to the
59# application through the 'normal' interface.
60def _sanitize(string):
61 # Turn any escaped bytes into unicode 'unknown' char. If the escaped
62 # bytes happen to be utf-8 they will instead get decoded, even if they
63 # were invalid in the charset the source was supposed to be in. This
64 # seems like it is not a bad thing; a defect was still registered.
65 original_bytes = string.encode('utf-8', 'surrogateescape')
66 return original_bytes.decode('utf-8', 'replace')
67
68
69

Callers

nothing calls this directly

Calls 2

encodeMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…