def expand_unicode(s):
""" Convert unicode reference in to a Unicode string. """
if s.startswith(r'\u') or s.startswith(r'\U'):
return chr(int(s,16))
if s.startswith(r'\N{'):
name = s[3:-1]
try:
return unicodedata.lookup(name)
except:
raise ConfigError("Failed to find unicode value with name {}\n".format(name))
else:
return s
评论列表
文章目录