From cec9b78f5e028a1a171855f37f7317d14c87b4f5 Mon Sep 17 00:00:00 2001 From: Chris Mayo Date: Wed, 3 Jun 2020 20:06:36 +0100 Subject: [PATCH] Additional review comments on black linkcheck/ --- linkcheck/checker/fileurl.py | 10 +++++----- linkcheck/checker/mailtourl.py | 16 ++++++++-------- linkcheck/configuration/__init__.py | 4 ++-- linkcheck/configuration/confparse.py | 10 +++++----- linkcheck/director/aggregator.py | 4 ++-- linkcheck/logger/html.py | 3 +-- linkcheck/plugins/locationinfo.py | 2 +- linkcheck/robotparser2.py | 8 ++++---- linkcheck/strformat.py | 4 ++-- linkcheck/url.py | 8 ++++++-- setup.cfg | 1 + 11 files changed, 37 insertions(+), 33 deletions(-) diff --git a/linkcheck/checker/fileurl.py b/linkcheck/checker/fileurl.py index f93c4e9b..725c0476 100644 --- a/linkcheck/checker/fileurl.py +++ b/linkcheck/checker/fileurl.py @@ -197,8 +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(): @@ -221,9 +221,9 @@ class FileUrl(urlbase.UrlBase): if path != realpath: self.add_warning( _( - "The URL path %(path)r is not the same as the " - "system path %(realpath)r. You should always use " - "the system path in URLs." + "The URL path %(path)r is not the same as the" + " system path %(realpath)r. You should always use" + " the system path in URLs." ) % {"path": path, "realpath": realpath}, tag=WARN_FILE_SYSTEM_PATH, diff --git a/linkcheck/checker/mailtourl.py b/linkcheck/checker/mailtourl.py index cacf5ef7..2833cb18 100644 --- a/linkcheck/checker/mailtourl.py +++ b/linkcheck/checker/mailtourl.py @@ -154,8 +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, @@ -188,8 +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, @@ -199,8 +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, @@ -249,8 +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, diff --git a/linkcheck/configuration/__init__.py b/linkcheck/configuration/__init__.py index b7ef6005..63458340 100644 --- a/linkcheck/configuration/__init__.py +++ b/linkcheck/configuration/__init__.py @@ -432,8 +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) diff --git a/linkcheck/configuration/confparse.py b/linkcheck/configuration/confparse.py index 562aebcd..1b8ff9e6 100644 --- a/linkcheck/configuration/confparse.py +++ b/linkcheck/configuration/confparse.py @@ -233,9 +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, @@ -246,8 +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." ), ) diff --git a/linkcheck/director/aggregator.py b/linkcheck/director/aggregator.py index a18a3bc0..13c5d753 100644 --- a/linkcheck/director/aggregator.py +++ b/linkcheck/director/aggregator.py @@ -175,8 +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, ) diff --git a/linkcheck/logger/html.py b/linkcheck/logger/html.py index ecba706e..569f1370 100644 --- a/linkcheck/logger/html.py +++ b/linkcheck/logger/html.py @@ -295,8 +295,7 @@ class HtmlLogger(_Logger): sep = "
" + os.linesep text = sep.join(html.escape(x[1]) for x in url_data.warnings) self.writeln( - '' + '' + self.part("warning") + '' + text diff --git a/linkcheck/plugins/locationinfo.py b/linkcheck/plugins/locationinfo.py index e92e794d..32c2e028 100644 --- a/linkcheck/plugins/locationinfo.py +++ b/linkcheck/plugins/locationinfo.py @@ -91,7 +91,7 @@ if geoip_dat: else: def get_geoip_record(host): return { - 'country_name': geoip.country_name_by_name(host) + 'country_name': geoip.country_name_by_name(host) } diff --git a/linkcheck/robotparser2.py b/linkcheck/robotparser2.py index 53b35401..d4ca6ee2 100644 --- a/linkcheck/robotparser2.py +++ b/linkcheck/robotparser2.py @@ -154,8 +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, ) @@ -180,8 +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, ) diff --git a/linkcheck/strformat.py b/linkcheck/strformat.py index a95a7ddc..fa12f610 100644 --- a/linkcheck/strformat.py +++ b/linkcheck/strformat.py @@ -338,8 +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 ) diff --git a/linkcheck/url.py b/linkcheck/url.py index fab2e67b..13ae3f91 100644 --- a/linkcheck/url.py +++ b/linkcheck/url.py @@ -60,12 +60,16 @@ _basic = { "_hex_full": r"0-9a-f", "_part": r"([a-z0-9][-a-z0-9]{0,61}|[a-z])", } -_safe_char = r"([a-z0-9%(_path)s\+]|" r"(%%[%(_hex_safe)s][%(_hex_full)s]))" % _basic +_safe_char = ( + r"([a-z0-9%(_path)s\+]|" + r"(%%[%(_hex_safe)s][%(_hex_full)s]))" % _basic +) _safe_scheme_pattern = r"(https?|ftp)" _safe_domain_pattern = r"(%(_part)s(\.%(_part)s)*\.?)" % _basic _safe_host_pattern = _safe_domain_pattern + r"(:(80|8080|8000|443))?" % _basic _safe_path_pattern = ( - r"((/([a-z0-9%(_path)s]|" r"(%%[%(_hex_safe)s][%(_hex_full)s]))+)*/?)" % _basic + r"((/([a-z0-9%(_path)s]|" + r"(%%[%(_hex_safe)s][%(_hex_full)s]))+)*/?)" % _basic ) _safe_fragment_pattern = r"%s*" % _safe_char _safe_cgi = r"%s+(=(%s|/)+)?" % (_safe_char, _safe_char) diff --git a/setup.cfg b/setup.cfg index 14da2d56..5f733dd2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -47,6 +47,7 @@ per-file-ignores = linkcheck/ftpparse.py: E501 tests/test_ftpparse.py: E501 # F821 undefined name +# https://github.com/PyCQA/pyflakes/issues/548 linkcheck/logger/__init__.py: F821 extend-ignore = # https://pep8.readthedocs.org/en/latest/intro.html#error-codes