Last active
May 10, 2017 11:57
-
-
Save hornc/cd4d476b39f6d6a4fa9f0c10a3151e5d to your computer and use it in GitHub Desktop.
This file contains 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
from unicodedata import normalize | |
def norm(s): | |
return normalize('NFC', s) | |
def is_nfc(s): | |
norm = normalize('NFC', s) | |
print "%s => %s" % (s, norm) | |
return s == norm | |
def fix_half(s): | |
return s.replace(u'\ufe21', '') | |
def fix_unicode(record): | |
for k,v in record.iteritems(): | |
if type(v) == unicode: | |
record[k] = norm(fix_half(v)) | |
record['_comment'] = "fix unicode" | |
return record |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment