def u(s):
"""Generate Unicode string from a string input, encoding Unicode characters.
This is expected to work in the same way as u'<string>' would work in Python
2.x (although it is not completely robust as it is based on a simple set of
regexps).
"""
us = re.sub(_U16_RE, lambda m: unichr(int(m.group('hexval'), 16)), unicode(s))
us = re.sub(_U32_RE, lambda m: unichr(int(m.group('hexval'), 16)), us)
us = re.sub(_UNAME_RE, lambda m: unicodedata.lookup(m.group('name')), us)
return us
评论列表
文章目录