Scrapy, a fast high-level web crawling & scraping framework for Python.
Remove backslash
Eugenio Lacuesta9e99be982a29
diff --git a/scrapy/cmdline.py b/scrapy/cmdline.pyindex b189e016b..3e88536e4 100644--- a/scrapy/cmdline.py+++ b/scrapy/cmdline.py@@ -19,10 +19,12 @@ def _iter_command_classes(module_name):# scrapy.utils.spider.iter_spider_classesfor module in walk_modules(module_name):for obj in vars(module).values():- if inspect.isclass(obj) and \- issubclass(obj, ScrapyCommand) and \- obj.__module__ == module.__name__ and \- not obj == ScrapyCommand:+ if (+ inspect.isclass(obj)+ and issubclass(obj, ScrapyCommand)+ and obj.__module__ == module.__name__+ and not obj == ScrapyCommand+ ):yield objdiff --git a/scrapy/commands/crawl.py b/scrapy/commands/crawl.pyindex e1724c1e6..f205c40b0 100644--- a/scrapy/commands/crawl.py+++ b/scrapy/commands/crawl.py@@ -26,6 +26,8 @@ class Command(BaseRunSpiderCommand):else:self.crawler_process.start()- if self.crawler_process.bootstrap_failed or \- (hasattr(self.crawler_process, 'has_exception') and self.crawler_process.has_exception):+ if (+ self.crawler_process.bootstrap_failed+ or hasattr(self.crawler_process, 'has_exception') and self.crawler_process.has_exception+ ):self.exitcode = 1diff --git a/scrapy/commands/fetch.py b/scrapy/commands/fetch.pyindex 063195f50..95f87e8c3 100644--- a/scrapy/commands/fetch.py+++ b/scrapy/commands/fetch.py@@ -19,8 +19,10 @@ class Command(ScrapyCommand):return "Fetch a URL using the Scrapy downloader"def long_desc(self):- return "Fetch a URL using the Scrapy downloader and print its content " \- "to stdout. You may want to use --nolog to disable logging"+ return (+ "Fetch a URL using the Scrapy downloader and print its content"+ " to stdout. You may want to use --nolog to disable logging"+ )def add_options(self, parser):ScrapyCommand.add_options(self, parser)diff --git a/scrapy/commands/genspider.py b/scrapy/commands/genspider.pyindex abf3b7a5c..4c7548e9c 100644--- a/scrapy/commands/genspider.py+++ b/scrapy/commands/genspider.py@@ -121,6 +121,7 @@ class Command(ScrapyCommand):@propertydef templates_dir(self):- _templates_base_dir = self.settings['TEMPLATES_DIR'] or \- join(scrapy.__path__[0], 'templates')- return join(_templates_base_dir, 'spiders')+ return join(+ self.settings['TEMPLATES_DIR'] or join(scrapy.__path__[0], 'templates'),+ 'spiders'+ )diff --git a/scrapy/commands/startproject.py b/scrapy/commands/startproject.pyindex 852281959..ae4a15b0f 100644--- a/scrapy/commands/startproject.py+++ b/scrapy/commands/startproject.py@@ -137,6 +137,7 @@ class Command(ScrapyCommand):@propertydef templates_dir(self):- _templates_base_dir = self.settings['TEMPLATES_DIR'] or \- join(scrapy.__path__[0], 'templates')- return join(_templates_base_dir, 'project')+ return join(+ self.settings['TEMPLATES_DIR'] or join(scrapy.__path__[0], 'templates'),+ 'project'+ )diff --git a/scrapy/commands/view.py b/scrapy/commands/view.pyindex 41e77ba3b..908bee966 100644--- a/scrapy/commands/view.py+++ b/scrapy/commands/view.py@@ -8,8 +8,7 @@ class Command(fetch.Command):return "Open URL in browser, as seen by Scrapy"def long_desc(self):- return "Fetch a URL using the Scrapy downloader and show its " \- "contents in a browser"+ return "Fetch a URL using the Scrapy downloader and show its contents in a browser"def add_options(self, parser):super(Command, self).add_options(parser)diff --git a/scrapy/core/engine.py b/scrapy/core/engine.pyindex de0da4b70..86a6abb23 100644--- a/scrapy/core/engine.py+++ b/scrapy/core/engine.py@@ -141,10 +141,12 @@ class ExecutionEngine:def _needs_backout(self, spider):slot = self.slot- return not self.running \- or slot.closing \- or self.downloader.needs_backout() \+ return (+ not self.running+ or slot.closing+ or self.downloader.needs_backout()or self.scraper.slot.needs_backout()+ )def _next_request_from_scheduler(self, spider):slot = self.slotdiff --git a/scrapy/downloadermiddlewares/redirect.py b/scrapy/downloadermiddlewares/redirect.pyindex b32afb8e4..366d60dcb 100644--- a/scrapy/downloadermiddlewares/redirect.py+++ b/scrapy/downloadermiddlewares/redirect.py@@ -33,10 +33,8 @@ class BaseRedirectMiddleware:if ttl and redirects <= self.max_redirect_times:redirected.meta['redirect_times'] = redirectsredirected.meta['redirect_ttl'] = ttl - 1- redirected.meta['redirect_urls'] = request.meta.get('redirect_urls', []) + \- [request.url]- redirected.meta['redirect_reasons'] = request.meta.get('redirect_reasons', []) + \- [reason]+ redirected.meta['redirect_urls'] = request.meta.get('redirect_urls', []) + [request.url]+ redirected.meta['redirect_reasons'] = request.meta.get('redirect_reasons', []) + [reason]redirected.dont_filter = request.dont_filterredirected.priority = request.priority + self.priority_adjustlogger.debug("Redirecting (%(reason)s) to %(redirected)s from %(request)s",@@ -99,8 +97,11 @@ class MetaRefreshMiddleware(BaseRedirectMiddleware):self._maxdelay = settings.getint('METAREFRESH_MAXDELAY')def process_response(self, request, response, spider):- if request.meta.get('dont_redirect', False) or request.method == 'HEAD' or \- not isinstance(response, HtmlResponse):+ if (+ request.meta.get('dont_redirect', False)+ or request.method == 'HEAD'+ or not isinstance(response, HtmlResponse)+ ):return responseinterval, url = get_meta_refresh(response,diff --git a/scrapy/downloadermiddlewares/retry.py b/scrapy/downloadermiddlewares/retry.pyindex 6d11af5b2..67be8c282 100644--- a/scrapy/downloadermiddlewares/retry.py+++ b/scrapy/downloadermiddlewares/retry.py@@ -60,8 +60,10 @@ class RetryMiddleware:return responsedef process_exception(self, request, exception, spider):- if isinstance(exception, self.EXCEPTIONS_TO_RETRY) \- and not request.meta.get('dont_retry', False):+ if (+ isinstance(exception, self.EXCEPTIONS_TO_RETRY)+ and not request.meta.get('dont_retry', False)+ ):return self._retry(request, exception, spider)def _retry(self, request, reason, spider):diff --git a/scrapy/extensions/memusage.py b/scrapy/extensions/memusage.pyindex a0540bf8f..ab2e43e8c 100644--- a/scrapy/extensions/memusage.py+++ b/scrapy/extensions/memusage.py@@ -81,8 +81,10 @@ class MemoryUsage:logger.error("Memory usage exceeded %(memusage)dM. Shutting down Scrapy...",{'memusage': mem}, extra={'crawler': self.crawler})if self.notify_mails:- subj = "%s terminated: memory usage exceeded %dM at %s" % \- (self.crawler.settings['BOT_NAME'], mem, socket.gethostname())+ subj = (+ "%s terminated: memory usage exceeded %dM at %s"+ % (self.crawler.settings['BOT_NAME'], mem, socket.gethostname())+ )self._send_report(self.notify_mails, subj)self.crawler.stats.set_value('memusage/limit_notified', 1)@@ -102,8 +104,10 @@ class MemoryUsage:logger.warning("Memory usage reached %(memusage)dM",{'memusage': mem}, extra={'crawler': self.crawler})if self.notify_mails:- subj = "%s warning: memory usage reached %dM at %s" % \- (self.crawler.settings['BOT_NAME'], mem, socket.gethostname())+ subj = (+ "%s warning: memory usage reached %dM at %s"+ % (self.crawler.settings['BOT_NAME'], mem, socket.gethostname())+ )self._send_report(self.notify_mails, subj)self.crawler.stats.set_value('memusage/warning_notified', 1)self.warned = Truediff --git a/scrapy/http/request/form.py b/scrapy/http/request/form.pyindex cd4e3373f..0e6ceef0b 100644--- a/scrapy/http/request/form.py+++ b/scrapy/http/request/form.py@@ -205,8 +205,7 @@ def _get_clickable(clickdata, form):# We didn't find it, so now we build an XPath expression out of the other# arguments, because they can be used as such- xpath = u'.//*' + \- u''.join(u'[@%s="%s"]' % c for c in clickdata.items())+ xpath = u'.//*' + u''.join(u'[@%s="%s"]' % c for c in clickdata.items())el = form.xpath(xpath)if len(el) == 1:return (el[0].get('name'), el[0].get('value') or '')diff --git a/scrapy/http/response/text.py b/scrapy/http/response/text.pyindex b43fe5c19..0f300c8da 100644--- a/scrapy/http/response/text.py+++ b/scrapy/http/response/text.py@@ -62,8 +62,11 @@ class TextResponse(Response):return self._declared_encoding() or self._body_inferred_encoding()def _declared_encoding(self):- return self._encoding or self._headers_encoding() \+ return (+ self._encoding+ or self._headers_encoding()or self._body_declared_encoding()+ )def body_as_unicode(self):"""Return body as unicode"""diff --git a/scrapy/link.py b/scrapy/link.pyindex 7cb0765cc..1ef50b113 100644--- a/scrapy/link.py+++ b/scrapy/link.py@@ -21,12 +21,18 @@ class Link:self.nofollow = nofollowdef __eq__(self, other):- return self.url == other.url and self.text == other.text and \- self.fragment == other.fragment and self.nofollow == other.nofollow+ return (+ self.url == other.url+ and self.text == other.text+ and self.fragment == other.fragment+ and self.nofollow == other.nofollow+ )def __hash__(self):return hash(self.url) ^ hash(self.text) ^ hash(self.fragment) ^ hash(self.nofollow)def __repr__(self):- return 'Link(url=%r, text=%r, fragment=%r, nofollow=%r)' % \- (self.url, self.text, self.fragment, self.nofollow)+ return (+ 'Link(url=%r, text=%r, fragment=%r, nofollow=%r)'+ % (self.url, self.text, self.fragment, self.nofollow)+ )diff --git a/scrapy/settings/__init__.py b/scrapy/settings/__init__.pyindex b9a13c018..ff8317cd1 100644--- a/scrapy/settings/__init__.py+++ b/scrapy/settings/__init__.py@@ -52,8 +52,7 @@ class SettingsAttribute:self.priority = prioritydef __str__(self):- return "<SettingsAttribute value={self.value!r} " \- "priority={self.priority}>".format(self=self)+ return "<SettingsAttribute value={self.value!r} priority={self.priority}>".format(self=self)__repr__ = __str__diff --git a/scrapy/utils/benchserver.py b/scrapy/utils/benchserver.pyindex 9d8d64612..f595a1acb 100644--- a/scrapy/utils/benchserver.py+++ b/scrapy/utils/benchserver.py@@ -28,8 +28,7 @@ class Root(Resource):def _getarg(request, name, default=None, type=str):- return type(request.args[name][0]) \- if name in request.args else default+ return type(request.args[name][0]) if name in request.args else defaultif __name__ == '__main__':diff --git a/scrapy/utils/conf.py b/scrapy/utils/conf.pyindex 5921f82bf..728bb5f1b 100644--- a/scrapy/utils/conf.py+++ b/scrapy/utils/conf.py@@ -101,11 +101,13 @@ def get_config(use_closest=True):def get_sources(use_closest=True):- xdg_config_home = os.environ.get('XDG_CONFIG_HOME') or \- os.path.expanduser('~/.config')- sources = ['/etc/scrapy.cfg', r'c:\scrapy\scrapy.cfg',- xdg_config_home + '/scrapy.cfg',- os.path.expanduser('~/.scrapy.cfg')]+ xdg_config_home = os.environ.get('XDG_CONFIG_HOME') or os.path.expanduser('~/.config')+ sources = [+ '/etc/scrapy.cfg',+ r'c:\scrapy\scrapy.cfg',+ xdg_config_home + '/scrapy.cfg',+ os.path.expanduser('~/.scrapy.cfg'),+ ]if use_closest:sources.append(closest_scrapy_cfg())return sourcesdiff --git a/scrapy/utils/curl.py b/scrapy/utils/curl.pyindex 67b22dbc5..aa681522f 100644--- a/scrapy/utils/curl.py+++ b/scrapy/utils/curl.py@@ -9,8 +9,7 @@ from w3lib.http import basic_auth_headerclass CurlParser(argparse.ArgumentParser):def error(self, message):- error_msg = \- 'There was an error parsing the curl command: {}'.format(message)+ error_msg = 'There was an error parsing the curl command: {}'.format(message)raise ValueError(error_msg)diff --git a/scrapy/utils/ossignal.py b/scrapy/utils/ossignal.pyindex 45c9cef0c..cf867f3f8 100644--- a/scrapy/utils/ossignal.py+++ b/scrapy/utils/ossignal.py@@ -18,8 +18,7 @@ def install_shutdown_handlers(function, override_sigint=True):from twisted.internet import reactorreactor._handleSignals()signal.signal(signal.SIGTERM, function)- if signal.getsignal(signal.SIGINT) == signal.default_int_handler or \- override_sigint:+ if signal.getsignal(signal.SIGINT) == signal.default_int_handler or override_sigint:signal.signal(signal.SIGINT, function)# Catch Ctrl-Break in windowsif hasattr(signal, 'SIGBREAK'):diff --git a/scrapy/utils/response.py b/scrapy/utils/response.pyindex edbc0db25..c29b619ce 100644--- a/scrapy/utils/response.py+++ b/scrapy/utils/response.py@@ -47,13 +47,17 @@ def response_httprepr(response):is provided only for reference, since it's not the exact stream of bytesthat was received (that's not exposed by Twisted)."""- s = b"HTTP/1.1 " + to_bytes(str(response.status)) + b" " + \- to_bytes(http.RESPONSES.get(response.status, b'')) + b"\r\n"+ values = [+ b"HTTP/1.1 ",+ to_bytes(str(response.status)),+ b" ",+ to_bytes(http.RESPONSES.get(response.status, b'')),+ b"\r\n",+ ]if response.headers:- s += response.headers.to_string() + b"\r\n"- s += b"\r\n"- s += response.body- return s+ values.extend([response.headers.to_string(), b"\r\n"])+ values.extend([b"\r\n", response.body])+ return b"".join(values)def open_in_browser(response, _openfunc=webbrowser.open):diff --git a/scrapy/utils/spider.py b/scrapy/utils/spider.pyindex 7e7a50c88..f3a9a67a3 100644--- a/scrapy/utils/spider.py+++ b/scrapy/utils/spider.py@@ -34,10 +34,12 @@ def iter_spider_classes(module):from scrapy.spiders import Spiderfor obj in vars(module).values():- if inspect.isclass(obj) and \- issubclass(obj, Spider) and \- obj.__module__ == module.__name__ and \- getattr(obj, 'name', None):+ if (+ inspect.isclass(obj)+ and issubclass(obj, Spider)+ and obj.__module__ == module.__name__+ and getattr(obj, 'name', None)+ ):yield obj