Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

move restrict_css argument to end of argument list in link extractors for backwards compatibility, use keyword arguments in link extractor super().__init__() calls

Artur Gaspar22247cf79152
diff --git a/scrapy/contrib/linkextractors/lxmlhtml.py b/scrapy/contrib/linkextractors/lxmlhtml.py
index f747fa99b..1ff8e4d36 100644
--- a/scrapy/contrib/linkextractors/lxmlhtml.py
+++ b/scrapy/contrib/linkextractors/lxmlhtml.py
@@ -81,17 +81,18 @@ class LxmlParserLinkExtractor(object):
class LxmlLinkExtractor(FilteringLinkExtractor):
def __init__(self, allow=(), deny=(), allow_domains=(), deny_domains=(), restrict_xpaths=(),
- restrict_css=(), tags=('a', 'area'), attrs=('href',), canonicalize=True,
- unique=True, process_value=None, deny_extensions=None):
+ tags=('a', 'area'), attrs=('href',), canonicalize=True,
+ unique=True, process_value=None, deny_extensions=None, restrict_css=()):
tags, attrs = set(arg_to_iter(tags)), set(arg_to_iter(attrs))
tag_func = lambda x: x in tags
attr_func = lambda x: x in attrs
lx = LxmlParserLinkExtractor(tag=tag_func, attr=attr_func,
unique=unique, process=process_value)
- super(LxmlLinkExtractor, self).__init__(lx, allow, deny,
- allow_domains, deny_domains, restrict_xpaths, restrict_css,
- canonicalize, deny_extensions)
+ super(LxmlLinkExtractor, self).__init__(lx, allow=allow, deny=deny,
+ allow_domains=allow_domains, deny_domains=deny_domains,
+ restrict_xpaths=restrict_xpaths, restrict_css=restrict_css,
+ canonicalize=canonicalize, deny_extensions=deny_extensions)
def extract_links(self, response):
html = Selector(response)
diff --git a/scrapy/contrib/linkextractors/sgml.py b/scrapy/contrib/linkextractors/sgml.py
index 3a8fdbb69..335773db1 100644
--- a/scrapy/contrib/linkextractors/sgml.py
+++ b/scrapy/contrib/linkextractors/sgml.py
@@ -98,8 +98,8 @@ class BaseSgmlLinkExtractor(SGMLParser):
class SgmlLinkExtractor(FilteringLinkExtractor):
def __init__(self, allow=(), deny=(), allow_domains=(), deny_domains=(), restrict_xpaths=(),
- restrict_css=(), tags=('a', 'area'), attrs=('href',), canonicalize=True, unique=True,
- process_value=None, deny_extensions=None):
+ tags=('a', 'area'), attrs=('href',), canonicalize=True, unique=True,
+ process_value=None, deny_extensions=None, restrict_css=()):
warnings.warn(
"SgmlLinkExtractor is deprecated and will be removed in future releases. "
@@ -115,9 +115,10 @@ class SgmlLinkExtractor(FilteringLinkExtractor):
lx = BaseSgmlLinkExtractor(tag=tag_func, attr=attr_func,
unique=unique, process_value=process_value)
- super(SgmlLinkExtractor, self).__init__(lx, allow, deny,
- allow_domains, deny_domains, restrict_xpaths, restrict_css,
- canonicalize, deny_extensions)
+ super(SgmlLinkExtractor, self).__init__(lx, allow=allow, deny=deny,
+ allow_domains=allow_domains, deny_domains=deny_domains,
+ restrict_xpaths=restrict_xpaths, restrict_css=restrict_css,
+ canonicalize=canonicalize, deny_extensions=deny_extensions)
# FIXME: was added to fix a RegexLinkExtractor testcase
self.base_url = None
diff --git a/scrapy/linkextractor.py b/scrapy/linkextractor.py
index 52271959f..227d79b46 100644
--- a/scrapy/linkextractor.py
+++ b/scrapy/linkextractor.py
@@ -42,7 +42,7 @@ class FilteringLinkExtractor(object):
_csstranslator = ScrapyHTMLTranslator()
def __init__(self, link_extractor, allow, deny, allow_domains, deny_domains,
- restrict_xpaths, restrict_css, canonicalize, deny_extensions):
+ restrict_xpaths, canonicalize, deny_extensions, restrict_css):
self.link_extractor = link_extractor