diff -r cf70f030a744 Lib/cookielib.py --- a/Lib/cookielib.py Wed Jun 18 23:07:46 2014 -0400 +++ b/Lib/cookielib.py Mon Jun 23 21:49:11 2014 +0300 @@ -37,6 +37,14 @@ import httplib # only for the default HTTP port from calendar import timegm +try: + _unicode = unicode +except NameError: + # If Python is built without Unicode support, the unicode type + # will not exist. Fake one. + class _unicode(object): + pass + debug = False # set to True to enable debugging via the logging module logger = None @@ -646,7 +654,7 @@ # And here, kind of: draft-fielding-uri-rfc2396bis-03 # (And in draft IRI specification: draft-duerst-iri-05) # (And here, for new URI schemes: RFC 2718) - if isinstance(path, unicode): + if isinstance(path, _unicode): path = path.encode("utf-8") path = urllib.quote(path, HTTP_PATH_SAFE) path = ESCAPED_CHAR_RE.sub(uppercase_escaped_char, path) diff -r cf70f030a744 Lib/test/test_cookielib.py --- a/Lib/test/test_cookielib.py Wed Jun 18 23:07:46 2014 -0400 +++ b/Lib/test/test_cookielib.py Mon Jun 23 21:49:11 2014 +0300 @@ -594,9 +594,11 @@ # unquoted unsafe ("/foo\031/bar", "/foo%19/bar"), ("/\175foo/bar", "/%7Dfoo/bar"), + ] + if test_support.have_unicode: # unicode - (u"/foo/bar\uabcd", "/foo/bar%EA%AF%8D"), # UTF-8 encoded - ] + cases.append((test_support.u(r"/foo/bar\uabcd"), + "/foo/bar%EA%AF%8D")) # UTF-8 encoded for arg, result in cases: self.assertEqual(escape_path(arg), result)