diff --git a/linkcheck/url.py b/linkcheck/url.py index 71433fbc..ac98e297 100644 --- a/linkcheck/url.py +++ b/linkcheck/url.py @@ -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')