mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-03-28 11:40:28 +00:00
Python3: fix unicode in url.py
This commit is contained in:
parent
5d26d2d93e
commit
f4b73c6d42
1 changed files with 5 additions and 4 deletions
|
|
@ -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')
|
||||
|
|
|
|||
Loading…
Reference in a new issue