From 40086dabb85a7c463f5a479e0c32d94c0b9463af Mon Sep 17 00:00:00 2001 From: Eugenio Lacuesta Date: Sat, 13 Jul 2019 20:57:24 -0300 Subject: [PATCH] Prevent more DeprecationWarnings --- scrapy/core/downloader/handlers/ftp.py | 2 +- scrapy/core/downloader/handlers/http11.py | 2 +- scrapy/utils/template.py | 2 +- tests/test_downloadermiddleware_cookies.py | 2 +- tests/test_engine.py | 6 +++--- tests/test_linkextractors.py | 2 +- tests/test_loader.py | 2 +- tests/test_utils_url.py | 4 ++-- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/scrapy/core/downloader/handlers/ftp.py b/scrapy/core/downloader/handlers/ftp.py index c342d4ab1..806a537d4 100644 --- a/scrapy/core/downloader/handlers/ftp.py +++ b/scrapy/core/downloader/handlers/ftp.py @@ -59,7 +59,7 @@ class ReceivedDataProtocol(Protocol): def close(self): self.body.close() if self.filename else self.body.seek(0) -_CODE_RE = re.compile("\d+") +_CODE_RE = re.compile(r"\d+") class FTPDownloadHandler(object): diff --git a/scrapy/core/downloader/handlers/http11.py b/scrapy/core/downloader/handlers/http11.py index 74ef82874..cbaa36b2d 100644 --- a/scrapy/core/downloader/handlers/http11.py +++ b/scrapy/core/downloader/handlers/http11.py @@ -101,7 +101,7 @@ class TunnelingTCP4ClientEndpoint(TCP4ClientEndpoint): for it. """ - _responseMatcher = re.compile(b'HTTP/1\.. (?P\d{3})(?P.{,32})') + _responseMatcher = re.compile(br'HTTP/1\.. (?P\d{3})(?P.{,32})') def __init__(self, reactor, host, port, proxyConf, contextFactory, timeout=30, bindAddress=None): diff --git a/scrapy/utils/template.py b/scrapy/utils/template.py index 1d7bd006c..615372fc8 100644 --- a/scrapy/utils/template.py +++ b/scrapy/utils/template.py @@ -18,7 +18,7 @@ def render_templatefile(path, **kwargs): os.remove(path) -CAMELCASE_INVALID_CHARS = re.compile('[^a-zA-Z\d]') +CAMELCASE_INVALID_CHARS = re.compile(r'[^a-zA-Z\d]') def string_camelcase(string): """ Convert a word to its CamelCase version and remove invalid chars diff --git a/tests/test_downloadermiddleware_cookies.py b/tests/test_downloadermiddleware_cookies.py index 17801e502..04884fb78 100644 --- a/tests/test_downloadermiddleware_cookies.py +++ b/tests/test_downloadermiddleware_cookies.py @@ -13,7 +13,7 @@ from scrapy.downloadermiddlewares.cookies import CookiesMiddleware class CookiesMiddlewareTest(TestCase): def assertCookieValEqual(self, first, second, msg=None): - cookievaleq = lambda cv: re.split(';\s*', cv.decode('latin1')) + cookievaleq = lambda cv: re.split(r';\s*', cv.decode('latin1')) return self.assertEqual( sorted(cookievaleq(first)), sorted(cookievaleq(second)), msg) diff --git a/tests/test_engine.py b/tests/test_engine.py index 856465161..30150391a 100644 --- a/tests/test_engine.py +++ b/tests/test_engine.py @@ -40,9 +40,9 @@ class TestSpider(Spider): name = "scrapytest.org" allowed_domains = ["scrapytest.org", "localhost"] - itemurl_re = re.compile("item\d+.html") - name_re = re.compile("

(.*?)

", re.M) - price_re = re.compile(">Price: \$(.*?)<", re.M) + itemurl_re = re.compile(r"item\d+.html") + name_re = re.compile(r"

(.*?)

", re.M) + price_re = re.compile(r">Price: \$(.*?)<", re.M) item_cls = TestItem diff --git a/tests/test_linkextractors.py b/tests/test_linkextractors.py index c9cd629f4..d96e259f6 100644 --- a/tests/test_linkextractors.py +++ b/tests/test_linkextractors.py @@ -288,7 +288,7 @@ class Base: response = HtmlResponse("http://example.org/somepage/index.html", body=html, encoding='windows-1252') def process_value(value): - m = re.search("javascript:goToPage\('(.*?)'", value) + m = re.search(r"javascript:goToPage\('(.*?)'", value) if m: return m.group(1) diff --git a/tests/test_loader.py b/tests/test_loader.py index ce0fa0701..2725b001a 100644 --- a/tests/test_loader.py +++ b/tests/test_loader.py @@ -691,7 +691,7 @@ class SelectortemLoaderTest(unittest.TestCase): self.assertTrue(l.selector) l.add_css('url', 'a::attr(href)') self.assertEqual(l.get_output_value('url'), [u'http://www.scrapy.org']) - l.replace_css('url', 'a::attr(href)', re='http://www\.(.+)') + l.replace_css('url', 'a::attr(href)', re=r'http://www\.(.+)') self.assertEqual(l.get_output_value('url'), [u'scrapy.org']) diff --git a/tests/test_utils_url.py b/tests/test_utils_url.py index c2b9fc176..e6588055c 100644 --- a/tests/test_utils_url.py +++ b/tests/test_utils_url.py @@ -233,8 +233,8 @@ for k, args in enumerate ([ setattr (GuessSchemeTest, t_method.__name__, t_method) # TODO: the following tests do not pass with current implementation -for k, args in enumerate ([ - ('C:\absolute\path\to\a\file.html', 'file://', +for k, args in enumerate([ + (r'C:\absolute\path\to\a\file.html', 'file://', 'Windows filepath are not supported for scrapy shell'), ], start=1): t_method = create_skipped_scheme_t(args)