diff --git a/linkcheck/checker/fileurl.py b/linkcheck/checker/fileurl.py index 6e0753e2..8f0134e3 100644 --- a/linkcheck/checker/fileurl.py +++ b/linkcheck/checker/fileurl.py @@ -234,8 +234,7 @@ class FileUrl(urlbase.UrlBase): with links to the files.""" if self.is_directory(): data = get_index_html(get_files(self.get_os_filename())) - if isinstance(data, str): - data = data.encode("iso8859-1", "ignore") + data = data.encode("iso8859-1", "ignore") else: data = super().read_content() return data diff --git a/linkcheck/fileutil.py b/linkcheck/fileutil.py index 5c8c8948..cc39342d 100644 --- a/linkcheck/fileutil.py +++ b/linkcheck/fileutil.py @@ -70,7 +70,7 @@ else: def path_safe(path): """Ensure path string is compatible with the platform file system encoding.""" - if isinstance(path, str) and not os.path.supports_unicode_filenames: + if path and not os.path.supports_unicode_filenames: path = path.encode(FSCODING, "replace").decode(FSCODING) return path diff --git a/linkcheck/robotparser2.py b/linkcheck/robotparser2.py index d4ca6ee2..1a5af387 100644 --- a/linkcheck/robotparser2.py +++ b/linkcheck/robotparser2.py @@ -276,10 +276,6 @@ class RobotFileParser: useragent, url, ) - if not isinstance(useragent, str): - useragent = useragent.encode("ascii", "ignore") - if not isinstance(url, str): - url = url.encode("ascii", "ignore") if self.disallow_all: log.debug(LOG_CHECK, " ... disallow all.") return False diff --git a/linkcheck/strformat.py b/linkcheck/strformat.py index 62338042..aced2d42 100644 --- a/linkcheck/strformat.py +++ b/linkcheck/strformat.py @@ -39,12 +39,12 @@ def ascii_safe(s): """Get ASCII string without raising encoding errors. Unknown characters of the given encoding will be ignored. - @param s: the Unicode string to be encoded - @type s: unicode or None - @return: encoded ASCII version of s, or None if s was None - @rtype: string + @param s: the string to be encoded + @type s: string or None + @return: version of s containing only ASCII characters, or None if s was None + @rtype: string or None """ - if isinstance(s, str): + if s: s = s.encode('ascii', 'ignore').decode('ascii') return s diff --git a/linkcheck/url.py b/linkcheck/url.py index 13ae3f91..eb8fc171 100644 --- a/linkcheck/url.py +++ b/linkcheck/url.py @@ -183,7 +183,7 @@ def idna_encode(host): to RFC 3490. @raise: UnicodeError if hostname is not properly IDN encoded. """ - if host and isinstance(host, str): + if host: try: host.encode('ascii') return host, False @@ -255,7 +255,7 @@ def url_fix_common_typos(url): def url_fix_mailto_urlsplit(urlparts): """Split query part of mailto url if found.""" - sep = b"?" if isinstance(urlparts[2], bytes) else "?" + sep = "?" if sep in urlparts[2]: urlparts[2], urlparts[3] = urlparts[2].split(sep, 1)