diff options
-rw-r--r-- | six.py | 5 | ||||
-rw-r--r-- | test_six.py | 8 |
2 files changed, 8 insertions, 5 deletions
@@ -21,6 +21,7 @@ # SOFTWARE. import operator +import re import sys import types @@ -467,8 +468,10 @@ if PY3: else: def b(s): return s + # Workaround for standalone backslash + _U = re.compile(r'\\(?!u)') def u(s): - return unicode(s, "unicode_escape") + return unicode(_U.sub('\\u005C', s), "unicode_escape") unichr = unichr int2byte = chr def byte2int(bs): diff --git a/test_six.py b/test_six.py index efeb33e..e233e97 100644 --- a/test_six.py +++ b/test_six.py @@ -385,9 +385,9 @@ if six.PY3: def test_u(): - s = six.u("hi") + s = six.u("hi \u0439 \\ \\\\ \n") assert isinstance(s, str) - assert s == "hi" + assert s == "hi \u0439 \\ \\\\ \n" else: @@ -399,9 +399,9 @@ else: def test_u(): - s = six.u("hi") + s = six.u("hi \u0439 \\ \\\\ \n") assert isinstance(s, unicode) - assert s == "hi" + assert s == "hi \xd0\xb9 \\ \\\\ \n".decode("utf8") def test_u_escapes(): |