Return True if s may contain surrogate-escaped binary data.
(s)
| 45 | |
| 46 | |
| 47 | def _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. |
no test coverage detected
searching dependent graphs…