Fix remaining flake8 violations in linkcheck/

linkcheck/better_exchook2.py:28:89: E501 line too long (90 > 88 characters)
linkcheck/better_exchook2.py:155:9: E722 do not use bare 'except'
linkcheck/better_exchook2.py:166:9: E722 do not use bare 'except'
linkcheck/better_exchook2.py:289:13: E741 ambiguous variable name 'l'
linkcheck/better_exchook2.py:299:9: E722 do not use bare 'except'
linkcheck/containers.py:48:13: E731 do not assign a lambda expression, use a def
linkcheck/ftpparse.py:123:89: E501 line too long (93 > 88 characters)
linkcheck/loader.py:46:47: E203 whitespace before ':'
linkcheck/logconf.py:45:29: E231 missing whitespace after ','
linkcheck/robotparser2.py:157:89: E501 line too long (95 > 88 characters)
linkcheck/robotparser2.py:182:89: E501 line too long (89 > 88 characters)
linkcheck/strformat.py:181:16: E203 whitespace before ':'
linkcheck/strformat.py:181:43: E203 whitespace before ':'
linkcheck/strformat.py:253:9: E731 do not assign a lambda expression, use a def
linkcheck/strformat.py:254:9: E731 do not assign a lambda expression, use a def
linkcheck/strformat.py:341:89: E501 line too long (111 > 88 characters)
linkcheck/url.py:102:32: E203 whitespace before ':'
linkcheck/url.py:277:5: E741 ambiguous variable name 'l'
linkcheck/url.py:402:5: E741 ambiguous variable name 'l'
linkcheck/checker/__init__.py:203:1: E402 module level import not at top of file
linkcheck/checker/fileurl.py:200:89: E501 line too long (103 > 88 characters)
linkcheck/checker/mailtourl.py:122:60: E203 whitespace before ':'
linkcheck/checker/mailtourl.py:157:89: E501 line too long (96 > 88 characters)
linkcheck/checker/mailtourl.py:190:89: E501 line too long (109 > 88 characters)
linkcheck/checker/mailtourl.py:200:89: E501 line too long (111 > 88 characters)
linkcheck/checker/mailtourl.py:249:89: E501 line too long (106 > 88 characters)
linkcheck/checker/unknownurl.py:226:23: W291 trailing whitespace
linkcheck/checker/urlbase.py:245:89: E501 line too long (101 > 88 characters)
linkcheck/configuration/confparse.py:236:89: E501 line too long (186 > 88 characters)
linkcheck/configuration/confparse.py:247:89: E501 line too long (111 > 88 characters)
linkcheck/configuration/__init__.py:164:9: E266 too many leading '#' for block comment
linkcheck/configuration/__init__.py:184:9: E266 too many leading '#' for block comment
linkcheck/configuration/__init__.py:190:9: E266 too many leading '#' for block comment
linkcheck/configuration/__init__.py:195:9: E266 too many leading '#' for block comment
linkcheck/configuration/__init__.py:198:9: E266 too many leading '#' for block comment
linkcheck/configuration/__init__.py:435:89: E501 line too long (90 > 88 characters)
linkcheck/director/aggregator.py:45:43: E231 missing whitespace after ','
linkcheck/director/aggregator.py:178:89: E501 line too long (106 > 88 characters)
linkcheck/logger/__init__.py:29:1: E731 do not assign a lambda expression, use a def
linkcheck/logger/__init__.py:108:13: E741 ambiguous variable name 'l'
linkcheck/logger/__init__.py:275:19: F821 undefined name '_'
linkcheck/logger/__init__.py:342:16: F821 undefined name '_'
linkcheck/logger/__init__.py:380:13: F821 undefined name '_'
linkcheck/logger/__init__.py:384:13: F821 undefined name '_'
linkcheck/logger/__init__.py:387:13: F821 undefined name '_'
linkcheck/logger/__init__.py:396:13: F821 undefined name '_'
linkcheck/network/__init__.py:1:1: W391 blank line at end of file
linkcheck/plugins/locationinfo.py:89:9: E731 do not assign a lambda expression, use a def
linkcheck/plugins/locationinfo.py:91:9: E731 do not assign a lambda expression, use a def
linkcheck/plugins/markdowncheck.py:112:89: E501 line too long (111 > 88 characters)
linkcheck/plugins/markdowncheck.py:141:9: E741 ambiguous variable name 'l'
linkcheck/plugins/markdowncheck.py:165:23: E203 whitespace before ':'
linkcheck/plugins/viruscheck.py:95:42: E203 whitespace before ':'
This commit is contained in:
Chris Mayo 2020-05-30 17:01:36 +01:00
parent 8dc2f12b94
commit ac0967e251
21 changed files with 80 additions and 61 deletions

View file

@ -25,7 +25,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# This is a simple replacement for the standard Python exception handler (sys.excepthook).
# This is a replacement for the standard Python exception handler (sys.excepthook).
# In addition to what the standard handler does, it also prints all referenced variables
# (no matter if local, global or builtin) of the code line of each stack frame.
# See below for some examples and some example output.
@ -152,7 +152,7 @@ def pp_extra_info(obj, depthlimit=3):
pass # don't print len in this case
else:
s += ["len = " + str(obj.__len__())]
except:
except Exception:
pass
if depthlimit > 0 and hasattr(obj, "__getitem__"):
try:
@ -163,7 +163,7 @@ def pp_extra_info(obj, depthlimit=3):
extra_info = pp_extra_info(subobj, depthlimit - 1)
if extra_info != "":
s += ["_[0]: {" + extra_info + "}"]
except:
except Exception:
pass
return ", ".join(s)
@ -286,8 +286,8 @@ def better_exchook(etype, value, tb, out=sys.stdout):
output("ERROR: cannot get more detailed exception info because:", out=out)
import traceback
for l in traceback.format_exc().split("\n"):
output(" " + l, out=out)
for line in traceback.format_exc().split("\n"):
output(" " + line, out=out)
output("simple traceback:", out=out)
traceback.print_tb(tb, None, out)
@ -296,7 +296,7 @@ def better_exchook(etype, value, tb, out=sys.stdout):
def _some_str(value):
try:
return str(value)
except:
except Exception:
return '<unprintable %s object>' % type(value).__name__
def _format_final_exc_line(etype, value):

View file

@ -200,7 +200,7 @@ def get_index_html(urls):
# all the URL classes
from . import (
from . import ( # noqa: E402
fileurl,
unknownurl,
ftpurl,
@ -211,4 +211,4 @@ from . import (
nntpurl,
ignoreurl,
itmsservicesurl,
) # noqa: E402
)

View file

@ -197,7 +197,8 @@ class FileUrl(urlbase.UrlBase):
"""
if self.parent_url is not None and not self.parent_url.startswith("file:"):
msg = _(
"local files are only checked without parent URL or when the parent URL is also a file"
"local files are only checked without parent URL or when "
"the parent URL is also a file"
)
raise LinkCheckerError(msg)
if self.is_directory():

View file

@ -119,7 +119,7 @@ class MailtoUrl(urlbase.UrlBase):
if i < (len(url) - 1):
self.addresses.update(getaddresses(url[:i]))
try:
headers = urllib.parse.parse_qs(url[(i + 1) :], strict_parsing=True)
headers = urllib.parse.parse_qs(url[(i + 1):], strict_parsing=True)
for key, vals in headers.items():
if key.lower() in EMAIL_CGI_ADDRESS:
# Only the first header value is added
@ -154,7 +154,8 @@ class MailtoUrl(urlbase.UrlBase):
if len(mail) > 256:
self.set_result(
_(
"Mail address `%(addr)s' too long. Allowed 256 chars, was %(length)d chars."
"Mail address `%(addr)s' too long. Allowed 256 chars, "
"was %(length)d chars."
)
% {"addr": mail, "length": len(mail)},
valid=False,
@ -187,7 +188,8 @@ class MailtoUrl(urlbase.UrlBase):
if len(local) > 64:
self.set_result(
_(
"Local part of mail address `%(addr)s' too long. Allowed 64 chars, was %(length)d chars."
"Local part of mail address `%(addr)s' too long. "
"Allowed 64 chars, was %(length)d chars."
)
% {"addr": mail, "length": len(local)},
valid=False,
@ -197,7 +199,8 @@ class MailtoUrl(urlbase.UrlBase):
if len(domain) > 255:
self.set_result(
_(
"Domain part of mail address `%(addr)s' too long. Allowed 255 chars, was %(length)d chars."
"Domain part of mail address `%(addr)s' too long. "
"Allowed 255 chars, was %(length)d chars."
)
% {"addr": mail, "length": len(local)},
valid=False,
@ -246,7 +249,8 @@ class MailtoUrl(urlbase.UrlBase):
if char in local.replace("\\%s" % char, ""):
self.set_result(
_(
"Local part of mail address `%(addr)s' contains unquoted character `%(char)s."
"Local part of mail address `%(addr)s' contains "
"unquoted character `%(char)s."
)
% {"addr": mail, "char": char},
valid=False,

View file

@ -223,7 +223,7 @@ ignored_schemes_provisional = r"""
|ut2004 # ut2004
|ventrilo # ventrilo
|view\-source # view-source
|whatsapp # whatsapp
|whatsapp # whatsapp
|webcal # webcal
|wtai # wtai
|wyciwyg # wyciwyg

View file

@ -242,7 +242,8 @@ class UrlBase:
self.info = []
# content size
self.size = -1
# last modification time of content in HTTP-date format as specified in RFC2616 chapter 3.3.1
# last modification time of content in HTTP-date format
# as specified in RFC2616 chapter 3.3.1
self.modified = None
# download time
self.dltime = -1

View file

@ -161,7 +161,7 @@ class Configuration(dict):
Initialize the default options.
"""
super(Configuration, self).__init__()
## checking options
# checking options
self["allowedschemes"] = []
self['cookiefile'] = None
self['robotstxt'] = True
@ -181,21 +181,21 @@ class Configuration(dict):
self["aborttimeout"] = 300
self["recursionlevel"] = -1
self["useragent"] = UserAgent
## authentication
# authentication
self["authentication"] = []
self["loginurl"] = None
self["loginuserfield"] = "login"
self["loginpasswordfield"] = "password"
self["loginextrafields"] = {}
## filtering
# filtering
self["externlinks"] = []
self["ignorewarnings"] = []
self["internlinks"] = []
self["checkextern"] = False
## plugins
# plugins
self["pluginfolders"] = get_plugin_folders()
self["enabledplugins"] = []
## output
# output
self['trace'] = False
self['quiet'] = False
self["verbose"] = False
@ -432,7 +432,8 @@ def get_user_config():
shutil.copy(initialconf, userconf)
except Exception as errmsg:
msg = _(
"could not copy initial configuration file %(src)r to %(dst)r: %(errmsg)r"
"could not copy initial configuration file %(src)r "
"to %(dst)r: %(errmsg)r"
)
args = dict(src=initialconf, dst=userconf, errmsg=errmsg)
log.warn(LOG_CHECK, msg % args)

View file

@ -233,7 +233,9 @@ class LCConfigParser(RawConfigParser):
if fileutil.is_accessable_by_others(fn):
log.warn(
LOG_CHECK,
"The configuration file %s contains password information (in section [%s] and options %s) and the file is readable by others. Please make the file only readable by you.",
"The configuration file %s contains password information (in "
"section [%s] and options %s) and the file is readable by "
"others. Please make the file only readable by you.",
fn,
section,
fields,
@ -244,7 +246,8 @@ class LCConfigParser(RawConfigParser):
log.warn(
LOG_CHECK,
_(
"See http://support.microsoft.com/kb/308419 for more info on setting file permissions."
"See http://support.microsoft.com/kb/308419 for "
"more info on setting file permissions."
),
)

View file

@ -45,7 +45,7 @@ class LFUCache(dict):
if trim:
items = super(LFUCache, self).items()
# sorting function for items
keyfunc = lambda x: x[1][0]
def keyfunc(x): return x[1][0]
values = sorted(items, key=keyfunc)
for item in values[0:trim]:
del self[item[0]]

View file

@ -42,7 +42,7 @@ def new_request_session(config, cookies):
session.cookies = cookies
session.max_redirects = config["maxhttpredirects"]
session.headers.update(
{"User-Agent": config["useragent"],}
{"User-Agent": config["useragent"]}
)
if config["cookiefile"]:
for cookie in from_file(config["cookiefile"]):
@ -175,7 +175,8 @@ class Aggregate:
log.info(
LOG_CHECK,
_(
"%(num)d URLs are still active. After a timeout of %(timeout)s the active URLs will stop."
"%(num)d URLs are still active. After a timeout of %(timeout)s "
"the active URLs will stop."
)
% args,
)

View file

@ -43,7 +43,7 @@ def get_package_modules(packagename):
with zipfile.ZipFile(zipname, 'r') as f:
prefix = "%s/%s/" % (parentmodule, packagename)
modnames = [
os.path.splitext(n[len(prefix) :])[0]
os.path.splitext(n[len(prefix):])[0]
for n in f.namelist()
if n.startswith(prefix) and "__init__" not in n
]

View file

@ -42,7 +42,7 @@ lognamelist = ", ".join(repr(name) for name in lognames)
configdict = {
'version': 1,
'loggers': {},
'root': {'level': 'WARN',},
'root': {'level': 'WARN'},
'incremental': True,
}

View file

@ -26,7 +26,7 @@ import abc
from .. import log, LOG_CHECK, strformat, dummy, configuration, i18n
_ = lambda x: x
_ = lambda x: x # noqa: E731
Fields = dict(
realurl=_("Real URL"),
cachekey=_("Cache key"),
@ -105,16 +105,16 @@ class LogStatistics:
key = "other"
self.link_types[key] += 1
if url_data.url:
l = len(url_data.url)
self.max_url_length = max(l, self.max_url_length)
n = len(url_data.url)
self.max_url_length = max(n, self.max_url_length)
if self.min_url_length == 0:
self.min_url_length = l
self.min_url_length = n
else:
self.min_url_length = min(l, self.min_url_length)
self.min_url_length = min(n, self.min_url_length)
# track average number separately since empty URLs do not count
self.avg_number += 1
# calculate running average
self.avg_url_length += (l - self.avg_url_length) / self.avg_number
self.avg_url_length += (n - self.avg_url_length) / self.avg_number
def log_internal_error(self):
"""Increase internal error count."""

View file

@ -1 +0,0 @@

View file

@ -86,11 +86,13 @@ if geoip_dat:
except ImportError:
pass
if geoip_dat.endswith('GeoIPCity.dat'):
get_geoip_record = lambda host: geoip.record_by_name(host)
def get_geoip_record(host):
return geoip.record_by_name(host)
else:
get_geoip_record = lambda host: {
'country_name': geoip.country_name_by_name(host)
}
def get_geoip_record(host):
return {
'country_name': geoip.country_name_by_name(host)
}
@synchronized(_lock)

View file

@ -109,7 +109,8 @@ class MarkdownCheck(_ContentPlugin):
self._check_inline_links(url_data, content)
def _save_url(self, url_data, content, url_text, url_pos):
"""Saves url. Converts url to 1-line text and url position as offset from the file beginning to (line, column).
"""Saves url. Converts url to 1-line text and url position as offset
from the file beginning to (line, column).
:param url_data: object for url storing
:param content: file content
@ -138,9 +139,9 @@ class MarkdownCheck(_ContentPlugin):
end of string if it's reached before the balance point is found.
"""
i = start
l = len(text)
n = len(text)
count = 1
while count > 0 and i < l:
while count > 0 and i < n:
if text[i] == open_c:
count += 1
elif text[i] == close_c:
@ -162,7 +163,7 @@ class MarkdownCheck(_ContentPlugin):
match = self._inline_link_title.search(text, idx, end_idx)
if not match:
return None, None
url = text[idx : match.start()]
url = text[idx:match.start()]
if has_anglebrackets:
url = self._strip_anglebrackets.sub(r'\1', url)
return url, end_idx

View file

@ -92,7 +92,7 @@ class ClamdScanner:
data = self.sock.recv(self.sock_rcvbuf)
i = data.find(b"PORT")
if i != -1:
port = int(data[i + 5 :])
port = int(data[i + 5:])
break
except socket.error:
self.sock.close()

View file

@ -154,7 +154,8 @@ class RobotFileParser:
if state == 1:
log.debug(
LOG_CHECK,
"%r line %d: allow or disallow directives without any user-agent line",
"%r line %d: allow or disallow directives without any "
"user-agent line",
self.url,
linenumber,
)
@ -179,7 +180,8 @@ class RobotFileParser:
if state == 2:
log.debug(
LOG_CHECK,
"%r line %d: missing blank line before user-agent directive",
"%r line %d: missing blank line before "
"user-agent directive",
self.url,
linenumber,
)

View file

@ -178,7 +178,7 @@ def remove_markup(s):
"""Remove all <*> html markup tags from s."""
mo = _markup_re.search(s)
while mo:
s = s[0 : mo.start()] + s[mo.end() :]
s = s[0:mo.start()] + s[mo.end():]
mo = _markup_re.search(s)
return s
@ -250,8 +250,8 @@ def strduration_long(duration, do_translate=True):
global _, _n
else:
# do not translate
_ = lambda x: x
_n = lambda a, b, n: a if n == 1 else b
def _(x): return x
def _n(a, b, n): return a if n == 1 else b
if duration < 0:
duration = abs(duration)
prefix = "-"
@ -338,7 +338,8 @@ def format_feature_warning(**kwargs):
"""
return (
_(
"Could not import %(module)s for %(feature)s. Install %(module)s from %(url)s to use this feature."
"Could not import %(module)s for %(feature)s. "
"Install %(module)s from %(url)s to use this feature."
)
% kwargs
)

View file

@ -99,7 +99,7 @@ def splitparams(path):
i = path.find(';')
if i < 0:
return path, ''
return path[:i], path[i + 1 :]
return path[:i], path[i + 1:]
def is_numeric_port(portstr):
@ -274,18 +274,18 @@ def url_parse_query(query, encoding):
while '?' in query:
query, rest = query.rsplit('?', 1)
append = '?' + url_parse_query(rest, encoding=encoding) + append
l = []
f = []
for k, v, sep in parse_qsl(query, keep_blank_values=True, encoding=encoding):
k = urllib.parse.quote(k, safe='/-:,;')
if v:
v = urllib.parse.quote(v, safe='/-:,;')
l.append("%s=%s%s" % (k, v, sep))
f.append("%s=%s%s" % (k, v, sep))
elif v is None:
l.append("%s%s" % (k, sep))
f.append("%s%s" % (k, sep))
else:
# some sites do not work when the equal sign is missing
l.append("%s=%s" % (k, sep))
return ''.join(l) + append
f.append("%s=%s" % (k, sep))
return ''.join(f) + append
def urlunsplit(urlparts):
@ -399,17 +399,17 @@ def url_quote(url, encoding):
urlparts[1] = urllib.parse.quote(urlparts[1], safe=':') # host
urlparts[2] = urllib.parse.quote(urlparts[2], safe='/=,') # path
urlparts[3] = urllib.parse.quote(urlparts[3], safe='&=,') # query
l = []
f = []
for k, v, sep in parse_qsl(
urlparts[3], encoding=encoding, keep_blank_values=True
): # query
k = urllib.parse.quote(k, safe='/-:,;')
if v:
v = urllib.parse.quote(v, safe='/-:,;')
l.append("%s=%s%s" % (k, v, sep))
f.append("%s=%s%s" % (k, v, sep))
else:
l.append("%s%s" % (k, sep))
urlparts[3] = ''.join(l)
f.append("%s%s" % (k, sep))
urlparts[3] = ''.join(f)
urlparts[4] = urllib.parse.quote(urlparts[4]) # anchor
return urlunsplit(urlparts)

View file

@ -41,7 +41,10 @@ per-file-ignores =
linkcheck/parser/__init__.py: E402
tests/__init__.py: F401
# E501: line too long
linkcheck/ftpparse.py: E501
tests/test_ftpparse.py: E501
# F821 undefined name
linkcheck/logger/__init__.py: F821
extend-ignore =
# https://pep8.readthedocs.org/en/latest/intro.html#error-codes
# these are ignored by default: