mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-04-19 22:01:00 +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 urlparse
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
from builtins import str as str_text
|
||||||
|
|
||||||
from . import log, LOG_CHECK
|
from . import log, LOG_CHECK
|
||||||
|
|
||||||
|
|
@ -178,7 +179,7 @@ def idna_encode (host):
|
||||||
to RFC 3490.
|
to RFC 3490.
|
||||||
@raise: UnicodeError if hostname is not properly IDN encoded.
|
@raise: UnicodeError if hostname is not properly IDN encoded.
|
||||||
"""
|
"""
|
||||||
if host and isinstance(host, unicode):
|
if host and isinstance(host, str_text):
|
||||||
try:
|
try:
|
||||||
host.encode('ascii')
|
host.encode('ascii')
|
||||||
return host, False
|
return host, False
|
||||||
|
|
@ -258,7 +259,7 @@ def url_fix_wayback_query(path):
|
||||||
|
|
||||||
def url_parse_query (query, encoding=None):
|
def url_parse_query (query, encoding=None):
|
||||||
"""Parse and re-join the given CGI query."""
|
"""Parse and re-join the given CGI query."""
|
||||||
if isinstance(query, unicode):
|
if isinstance(query, str_text):
|
||||||
if encoding is None:
|
if encoding is None:
|
||||||
encoding = url_encoding
|
encoding = url_encoding
|
||||||
query = query.encode(encoding, 'ignore')
|
query = query.encode(encoding, 'ignore')
|
||||||
|
|
@ -301,7 +302,7 @@ def url_norm (url, encoding=None):
|
||||||
@return: (normed url, idna flag)
|
@return: (normed url, idna flag)
|
||||||
@rtype: tuple of length two
|
@rtype: tuple of length two
|
||||||
"""
|
"""
|
||||||
if isinstance(url, unicode):
|
if isinstance(url, str_text):
|
||||||
# try to decode the URL to ascii since urllib.unquote()
|
# try to decode the URL to ascii since urllib.unquote()
|
||||||
# handles non-unicode strings differently
|
# handles non-unicode strings differently
|
||||||
try:
|
try:
|
||||||
|
|
@ -416,7 +417,7 @@ def url_quote (url):
|
||||||
def url_quote_part (s, safechars='/', encoding=None):
|
def url_quote_part (s, safechars='/', encoding=None):
|
||||||
"""Wrap urllib.quote() to support unicode strings. A unicode string
|
"""Wrap urllib.quote() to support unicode strings. A unicode string
|
||||||
is first converted to UTF-8. After that urllib.quote() is called."""
|
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:
|
if encoding is None:
|
||||||
encoding = url_encoding
|
encoding = url_encoding
|
||||||
s = s.encode(encoding, 'ignore')
|
s = s.encode(encoding, 'ignore')
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue