Remove str_text from checker/

This commit is contained in:
Chris Mayo 2020-05-19 19:56:42 +01:00
parent a127902607
commit 6bddd4ac60
3 changed files with 11 additions and 18 deletions

View file

@ -21,7 +21,6 @@ import re
import os
import urllib.parse
import urllib.request
from builtins import str as str_text
from datetime import datetime
from . import urlbase, get_index_html
@ -202,7 +201,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_text):
if isinstance(data, str):
data = data.encode("iso8859-1", "ignore")
else:
data = super(FileUrl, self).read_content()

View file

@ -20,8 +20,6 @@ Handle itms-services URLs.
from . import urlbase
from .. import log, LOG_CHECK
from builtins import str as str_text
class ItmsServicesUrl(urlbase.UrlBase):
"""Apple iOS application download URLs."""
@ -33,7 +31,7 @@ class ItmsServicesUrl(urlbase.UrlBase):
def local_check(self):
"""Disable content checks."""
log.debug(LOG_CHECK, "Checking %s", str_text(self))
log.debug(LOG_CHECK, "Checking %s", self)
pass
def check_content(self):

View file

@ -25,7 +25,6 @@ import errno
import socket
import select
from io import BytesIO
from builtins import str as str_text
from . import absolute_url, get_url_from
from .. import (log, LOG_CHECK,
@ -224,9 +223,7 @@ class UrlBase:
"Double result %r (previous %r) for %s", msg, self.result, self)
else:
self.has_result = True
if not isinstance(msg, str_text):
log.warn(LOG_CHECK, "Non-unicode result for %s: %r", self, msg)
elif not msg:
if not msg:
log.warn(LOG_CHECK, "Empty result for %s", self)
self.result = msg
self.valid = valid
@ -439,7 +436,7 @@ class UrlBase:
def local_check(self):
"""Local check function can be overridden in subclasses."""
log.debug(LOG_CHECK, "Checking %s", str_text(self))
log.debug(LOG_CHECK, "Checking %s", self)
# strict extern URLs should not be checked
assert not self.extern[1], 'checking strict extern URL'
# check connection
@ -456,7 +453,7 @@ class UrlBase:
value = _('Hostname not found')
elif isinstance(exc, UnicodeError):
# idna.encode(host) failed
value = _('Bad hostname %(host)r: %(msg)s') % {'host': self.host, 'msg': str_text(value)}
value = _('Bad hostname %(host)r: %(msg)s') % {'host': self.host, 'msg': value}
self.set_result(unicode_safe(value), valid=False)
def check_content(self):
@ -473,7 +470,7 @@ class UrlBase:
except tuple(ExcList):
value = self.handle_exception()
self.add_warning(_("could not get content: %(msg)s") %
{"msg": str_text(value)}, tag=WARN_URL_ERROR_GETTING_CONTENT)
{"msg": value}, tag=WARN_URL_ERROR_GETTING_CONTENT)
return False
def close_connection(self):
@ -502,11 +499,10 @@ class UrlBase:
not evalue:
# EBADF occurs when operating on an already socket
self.caching = False
# format unicode message "<exception name>: <error message>"
errmsg = str_text(etype.__name__)
uvalue = strformat.unicode_safe(evalue)
if uvalue:
errmsg += ": %s" % uvalue
# format message "<exception name>: <error message>"
errmsg = etype.__name__
if evalue:
errmsg += ": %s" % evalue
# limit length to 240
return strformat.limit(errmsg, length=240)
@ -734,7 +730,7 @@ class UrlBase:
@return: URL info, encoded with the output logger encoding
@rtype: string
"""
s = str_text(self)
s = str(self)
return self.aggregate.config['logger'].encode(s)
def __repr__(self):