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

Function _has_surrogates

Lib/email/utils.py:47–56  ·  view source on GitHub ↗

Return True if s may contain surrogate-escaped binary data.

(s)

Source from the content-addressed store, hash-verified

45
46
47def _has_surrogates(s):
48 """Return True if s may contain surrogate-escaped binary data."""
49 # This check is based on the fact that unless there are surrogates, utf8
50 # (Python's default encoding) can encode any string. This is the fastest
51 # way to check for surrogates, see bpo-11454 (moved to gh-55663) for timings.
52 try:
53 s.encode()
54 return False
55 except UnicodeEncodeError:
56 return True
57
58# How to deal with a string containing bytes before handing it to the
59# application through the 'normal' interface.

Callers 5

_foldMethod · 0.90
_sanitize_headerMethod · 0.90
_foldMethod · 0.90
_handle_textMethod · 0.90
_handle_textMethod · 0.90

Calls 1

encodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…