Created
June 18, 2020 09:15
-
-
Save jenskutilek/c9adaf1630665c43a7b5e5cc3c7f8b1e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import codecs | |
def afdko_escape_handler(exc): | |
if not isinstance(exc, UnicodeEncodeError): | |
raise TypeError("don't know how to handle %r" % exc) | |
result = [] | |
for c in exc.object[exc.start:exc.end]: | |
result.append(r"\%04x" % ord(c)) | |
return ("".join(result), exc.end) | |
codecs.register_error("afdko_escape", afdko_escape_handler) | |
name = "üöäß" | |
name = name.encode("ascii", "afdko_escape").decode() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment