Python3: fix unicode in url.py

This commit is contained in:
Petr Dlouhý 2018-01-05 18:40:26 +01:00 committed by Chris Mayo
parent 5d26d2d93e
commit f4b73c6d42

View file

@ -28,6 +28,7 @@ except ImportError: # Python 2
import urlparse
import requests
from builtins import str as str_text
from . import log, LOG_CHECK
@ -178,7 +179,7 @@ def idna_encode (host):
to RFC 3490.
@raise: UnicodeError if hostname is not properly IDN encoded.
"""
if host and isinstance(host, unicode):
if host and isinstance(host, str_text):
try:
host.encode('ascii')
return host, False
@ -258,7 +259,7 @@ def url_fix_wayback_query(path):
def url_parse_query (query, encoding=None):
"""Parse and re-join the given CGI query."""
if isinstance(query, unicode):
if isinstance(query, str_text):
if encoding is None:
encoding = url_encoding
query = query.encode(encoding, 'ignore')
@ -301,7 +302,7 @@ def url_norm (url, encoding=None):
@return: (normed url, idna flag)
@rtype: tuple of length two
"""
if isinstance(url, unicode):
if isinstance(url, str_text):
# try to decode the URL to ascii since urllib.unquote()
# handles non-unicode strings differently
try:
@ -416,7 +417,7 @@ def url_quote (url):
def url_quote_part (s, safechars='/', encoding=None):
"""Wrap urllib.quote() to support unicode strings. A unicode string
is first converted to UTF-8. After that urllib.quote() is called."""
if isinstance(s, unicode):
if isinstance(s, str_text):
if encoding is None:
encoding = url_encoding
s = s.encode(encoding, 'ignore')