From 7a8da48a306dfc8e43239d7f2a141c465e40ab77 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Wed, 25 May 2016 19:16:02 -0700 Subject: escaped_str_to_bytes: support unicode on python 2 --- netlib/utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'netlib/utils.py') diff --git a/netlib/utils.py b/netlib/utils.py index 7499f71f..fe11cb5b 100644 --- a/netlib/utils.py +++ b/netlib/utils.py @@ -439,10 +439,14 @@ def escaped_str_to_bytes(data): """ Take an escaped string and return the unescaped bytes equivalent. """ - if not isinstance(data, str): + if not isinstance(data, six.string_types): + if six.PY2: + raise ValueError("data must be str or unicode") raise ValueError("data must be str") if six.PY2: + if isinstance(data, unicode): + data = data.encode("utf8") return data.decode("string-escape") # This one is difficult - we use an undocumented Python API here -- cgit v1.2.3