urllib.quote/unquote must be str on Python 2

This commit is contained in:
MinRK 2013-10-17 21:08:28 -07:00
parent 06d9b99141
commit 99282f9e6b

View File

@ -15,6 +15,8 @@ Authors:
import os import os
from urllib import quote, unquote from urllib import quote, unquote
from IPython.utils import py3compat
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# Imports # Imports
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
@ -54,13 +56,16 @@ def url_escape(path):
Turns '/foo bar/' into '/foo%20bar/' Turns '/foo bar/' into '/foo%20bar/'
""" """
parts = path.split('/') parts = py3compat.unicode_to_str(path).split('/')
return '/'.join([quote(p) for p in parts]) return u'/'.join([quote(p) for p in parts])
def url_unescape(path): def url_unescape(path):
"""Unescape special characters in a URL path """Unescape special characters in a URL path
Turns '/foo%20bar/' into '/foo bar/' Turns '/foo%20bar/' into '/foo bar/'
""" """
return '/'.join([unquote(p) for p in path.split('/')]) return u'/'.join([
py3compat.str_to_unicode(unquote(p))
for p in py3compat.unicode_to_str(path).split('/')
])