From 8a294be95feecf642df486579f9e4487518ced29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Dlouh=C3=BD?= Date: Fri, 5 Jan 2018 20:59:34 +0100 Subject: [PATCH] Python3: fix robotparser --- linkcheck/robotparser2.py | 6 +++--- tests/checker/__init__.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/linkcheck/robotparser2.py b/linkcheck/robotparser2.py index 38487e8a..cdc0f445 100644 --- a/linkcheck/robotparser2.py +++ b/linkcheck/robotparser2.py @@ -32,7 +32,7 @@ import time import requests -from . import log, LOG_CHECK, configuration +from . import log, LOG_CHECK, configuration, url as urlutil __all__ = ["RobotFileParser"] @@ -104,7 +104,7 @@ class RobotFileParser (object): response.raise_for_status() content_type = response.headers.get('content-type') if content_type and content_type.lower().startswith('text/plain'): - self.parse(response.iter_lines()) + self.parse(response.iter_lines(decode_unicode=True)) else: log.debug(LOG_CHECK, "%r allow all (no text content)", self.url) self.allow_all = True @@ -281,7 +281,7 @@ class RuleLine (object): # an empty value means allow all allowance = True path = '/' - self.path = parse.quote(path) + self.path = urlutil.url_quote_part(path) self.allowance = allowance def applies_to (self, path): diff --git a/tests/checker/__init__.py b/tests/checker/__init__.py index a6aaf45b..6d07c291 100644 --- a/tests/checker/__init__.py +++ b/tests/checker/__init__.py @@ -134,7 +134,7 @@ class TestLogger (linkcheck.logger._Logger): if not isinstance(line, str_text): # The ---, +++ and @@ lines from diff format are ascii encoded. # Make them unicode. - line = unicode(line, "ascii", "replace") + line = str_text(line, "ascii", "replace") self.diff.append(line) @@ -233,7 +233,7 @@ class LinkCheckTest (unittest.TestCase): linkcheck.director.check_urls(aggregate) diff = aggregate.config['logger'].diff if diff: - msg = unicode(os.linesep).join([url] + diff) + msg = str_text(os.linesep).join([url] + diff) self.fail_unicode(msg) def fail_unicode (self, msg): @@ -263,7 +263,7 @@ class LinkCheckTest (unittest.TestCase): if diff: l = [u"Differences found testing %s" % url] l.extend(x.rstrip() for x in diff[2:]) - self.fail_unicode(unicode(os.linesep).join(l)) + self.fail_unicode(str_text(os.linesep).join(l)) class MailTest (LinkCheckTest):