From facf96b253205d58d46fe6ea780a81c2c7203d26 Mon Sep 17 00:00:00 2001 From: alexanderlukanin13 Date: Thu, 7 Nov 2013 14:45:15 +0600 Subject: fixed six.u('\\\\') in Python 2 --- six.py | 5 ++++- test_six.py | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/six.py b/six.py index 176196c..729ba7a 100644 --- a/six.py +++ b/six.py @@ -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(): -- cgit v1.2.1