summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralexanderlukanin13 <alexander.lukanin.13@gmail.com>2013-11-07 14:45:15 +0600
committeralexanderlukanin13 <alexander.lukanin.13@gmail.com>2013-11-07 14:45:15 +0600
commitfacf96b253205d58d46fe6ea780a81c2c7203d26 (patch)
tree7db7e4ff3d59970dcb35c4fdf735f3a13634abf7
parentc2312c1c26a9c68d4c7dad96eba5b39695adbd3f (diff)
downloadsix-facf96b253205d58d46fe6ea780a81c2c7203d26.tar.gz
fixed six.u('\\\\') in Python 2
-rw-r--r--six.py5
-rw-r--r--test_six.py8
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():