+def normalize(name):
+ """Strips irrelevant formatting junk from name input.
+
+ Specifically: everything is lowercased, and accents are removed.
+ """
+ # http://stackoverflow.com/questions/517923/what-is-the-best-way-to-remove-accents-in-a-python-unicode-string
+ # Makes sense to me. Decompose by Unicode rules, then remove combining
+ # characters, then recombine. I'm explicitly doing it this way instead of
+ # testing combining() because Korean characters apparently decompose! But
+ # the results are considered letters, not combining characters, so testing
+ # for Mn works well, and combining them again makes them look right.
+ nkfd_form = unicodedata.normalize('NFKD', unicode(name))
+ name = u"".join(c for c in nkfd_form
+ if unicodedata.category(c) != 'Mn')
+ name = unicodedata.normalize('NFC', name)
+
+ name = name.strip()
+ name = name.lower()
+
+ return name
+
+