From 4972248e3370c6d56d75ff081a329cfdfe172a8b Mon Sep 17 00:00:00 2001 From: frostming Date: Tue, 6 Nov 2018 16:56:27 +0800 Subject: [PATCH] fix unicode for py2 --- pipenv/patched/prettytoml/tokens/toml2py.py | 1 + .../patches/patched/prettytoml-unicode.patch | 23 ++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/pipenv/patched/prettytoml/tokens/toml2py.py b/pipenv/patched/prettytoml/tokens/toml2py.py index 98186ca5..56804437 100644 --- a/pipenv/patched/prettytoml/tokens/toml2py.py +++ b/pipenv/patched/prettytoml/tokens/toml2py.py @@ -40,6 +40,7 @@ def _unescape_str(text): """ Unescapes a string according the TOML spec. Raises BadEscapeCharacter when appropriate. """ + text = text.decode('utf-8') if isinstance(text, six.binary_type) else text tokens = [] i = 0 basicstr_re = re.compile(r'[^"\\\000-\037]*') diff --git a/tasks/vendoring/patches/patched/prettytoml-unicode.patch b/tasks/vendoring/patches/patched/prettytoml-unicode.patch index 6b9ffecf..4001b285 100644 --- a/tasks/vendoring/patches/patched/prettytoml-unicode.patch +++ b/tasks/vendoring/patches/patched/prettytoml-unicode.patch @@ -1,5 +1,5 @@ diff --git a/pipenv/patched/prettytoml/tokens/py2toml.py b/pipenv/patched/prettytoml/tokens/py2toml.py -index 8299195..2decd02 100644 +index 82991958..2decd021 100644 --- a/pipenv/patched/prettytoml/tokens/py2toml.py +++ b/pipenv/patched/prettytoml/tokens/py2toml.py @@ -2,6 +2,7 @@ @@ -11,8 +11,8 @@ index 8299195..2decd02 100644 import datetime import six @@ -81,10 +82,30 @@ def create_string_token(text, bare_string_allowed=False, multiline_strings_allow - - + + def _escape_single_line_quoted_string(text): - if six.PY2: - return text.encode('unicode-escape').encode('string-escape').replace('"', '\\"').replace("\\'", "'") @@ -42,11 +42,11 @@ index 8299195..2decd02 100644 + + flush() + return ''.join(res) - - + + def _create_multiline_string_token(text): diff --git a/pipenv/patched/prettytoml/tokens/toml2py.py b/pipenv/patched/prettytoml/tokens/toml2py.py -index 2bf9c1c..98186ca 100644 +index 2bf9c1c2..56804437 100644 --- a/pipenv/patched/prettytoml/tokens/toml2py.py +++ b/pipenv/patched/prettytoml/tokens/toml2py.py @@ -1,3 +1,4 @@ @@ -55,15 +55,15 @@ index 2bf9c1c..98186ca 100644 import string import iso8601 @@ -19,7 +20,7 @@ def deserialize(token): - + Raises DeserializationError when appropriate. """ -- +- + if token.type == TYPE_BOOLEAN: return _to_boolean(token) elif token.type == TYPE_INTEGER: -@@ -39,42 +40,39 @@ def _unescape_str(text): +@@ -39,42 +40,40 @@ def _unescape_str(text): """ Unescapes a string according the TOML spec. Raises BadEscapeCharacter when appropriate. """ @@ -94,6 +94,7 @@ index 2bf9c1c..98186ca 100644 - def escape_unicode_char(x): - if six.PY2: - return x.encode('unicode-escape') ++ text = text.decode('utf-8') if isinstance(text, six.binary_type) else text + tokens = [] + i = 0 + basicstr_re = re.compile(r'[^"\\\000-\037]*') @@ -135,6 +136,6 @@ index 2bf9c1c..98186ca 100644 + tokens.append(escapes[text[i]]) + i += 1 + return ''.join(tokens) - - + + def _to_string(token):