Generate Unicode string from a string input, encoding Unicode characters. This is expected to work in the same way as u' ' would work in Python 2.x (although it is not completely robust as it is based on a simple set of regexps).
(s)
| 67 | _U32_RE = re.compile(r'\\U(?P<hexval>[0-9a-fA-F]{8})') |
| 68 | |
| 69 | def u(s): |
| 70 | """Generate Unicode string from a string input, encoding Unicode characters. |
| 71 | |
| 72 | This is expected to work in the same way as u'<string>' would work in Python |
| 73 | 2.x (although it is not completely robust as it is based on a simple set of |
| 74 | regexps). |
| 75 | """ |
| 76 | us = re.sub(_U16_RE, lambda m: unichr(int(m.group('hexval'), 16)), unicode(s)) |
| 77 | us = re.sub(_U32_RE, lambda m: unichr(int(m.group('hexval'), 16)), us) |
| 78 | us = re.sub(_UNAME_RE, lambda m: unicodedata.lookup(m.group('name')), us) |
| 79 | return us |
| 80 | |
| 81 | to_long = long |
| 82 |
no outgoing calls