Encode str to bytes, with round-tripping of "invalid" bytes.
(s, coding="utf-8", errors="surrogateescape")
| 66 | |
| 67 | |
| 68 | def safe_encode(s, coding="utf-8", errors="surrogateescape"): |
| 69 | """Encode str to bytes, with round-tripping of "invalid" bytes.""" |
| 70 | if s is None: |
| 71 | return None |
| 72 | return s.encode(coding, errors) |
| 73 | |
| 74 | |
| 75 | def remove_surrogates(s, errors="replace"): |
no outgoing calls
no test coverage detected