Return True if s may contain surrogate-escaped binary data.
(s)
| 49 | escapesre = re.compile(r'[\\"]') |
| 50 | |
| 51 | def _has_surrogates(s): |
| 52 | """Return True if s may contain surrogate-escaped binary data.""" |
| 53 | # This check is based on the fact that unless there are surrogates, utf8 |
| 54 | # (Python's default encoding) can encode any string. This is the fastest |
| 55 | # way to check for surrogates, see bpo-11454 (moved to gh-55663) for timings. |
| 56 | try: |
| 57 | s.encode() |
| 58 | return False |
| 59 | except UnicodeEncodeError: |
| 60 | return True |
| 61 | |
| 62 | # How to deal with a string containing bytes before handing it to the |
| 63 | # application through the 'normal' interface. |
no test coverage detected