Skip to content

Commit

Permalink
Merge pull request #6113 from Laerte/master
Browse files Browse the repository at this point in the history
Remove some deprecated code
  • Loading branch information
Gallaecio committed Oct 18, 2023
2 parents 39ee8d1 + 38dbd43 commit 9b06f6b
Show file tree
Hide file tree
Showing 19 changed files with 15 additions and 751 deletions.
15 changes: 1 addition & 14 deletions scrapy/crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
inlineCallbacks,
maybeDeferred,
)
from zope.interface.exceptions import DoesNotImplement

try:
# zope >= 5.0 only supports MultipleInvalid
Expand Down Expand Up @@ -205,19 +204,7 @@ def _get_spider_loader(settings: BaseSettings):
"""Get SpiderLoader instance from settings"""
cls_path = settings.get("SPIDER_LOADER_CLASS")
loader_cls = load_object(cls_path)
excs = (
(DoesNotImplement, MultipleInvalid) if MultipleInvalid else DoesNotImplement
)
try:
verifyClass(ISpiderLoader, loader_cls)
except excs:
warnings.warn(
"SPIDER_LOADER_CLASS (previously named SPIDER_MANAGER_CLASS) does "
"not fully implement scrapy.interfaces.ISpiderLoader interface. "
"Please add all missing methods to avoid unexpected runtime errors.",
category=ScrapyDeprecationWarning,
stacklevel=2,
)
verifyClass(ISpiderLoader, loader_cls)
return loader_cls.from_settings(settings.frozencopy())

def __init__(self, settings: Union[Dict[str, Any], Settings, None] = None):
Expand Down
94 changes: 0 additions & 94 deletions scrapy/downloadermiddlewares/decompression.py

This file was deleted.

20 changes: 1 addition & 19 deletions scrapy/downloadermiddlewares/httpauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
See documentation in docs/topics/downloader-middleware.rst
"""
import warnings

from w3lib.http import basic_auth_header

from scrapy import signals
from scrapy.exceptions import ScrapyDeprecationWarning
from scrapy.utils.httpobj import urlparse_cached
from scrapy.utils.url import url_is_from_any_domain


Expand All @@ -28,25 +25,10 @@ def spider_opened(self, spider):
pwd = getattr(spider, "http_pass", "")
if usr or pwd:
self.auth = basic_auth_header(usr, pwd)
if not hasattr(spider, "http_auth_domain"):
warnings.warn(
"Using HttpAuthMiddleware without http_auth_domain is deprecated and can cause security "
"problems if the spider makes requests to several different domains. http_auth_domain "
"will be set to the domain of the first request, please set it to the correct value "
"explicitly.",
category=ScrapyDeprecationWarning,
)
self.domain_unset = True
else:
self.domain = spider.http_auth_domain
self.domain_unset = False
self.domain = spider.http_auth_domain

def process_request(self, request, spider):
auth = getattr(self, "auth", None)
if auth and b"Authorization" not in request.headers:
domain = urlparse_cached(request).hostname
if self.domain_unset:
self.domain = domain
self.domain_unset = False
if not self.domain or url_is_from_any_domain(request.url, [self.domain]):
request.headers[b"Authorization"] = auth
15 changes: 1 addition & 14 deletions scrapy/downloadermiddlewares/httpcompression.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import io
import warnings
import zlib

from scrapy.exceptions import NotConfigured
from scrapy.http import Response, TextResponse
from scrapy.responsetypes import responsetypes
from scrapy.utils.deprecate import ScrapyDeprecationWarning
from scrapy.utils.gz import gunzip

ACCEPTED_ENCODINGS = [b"gzip", b"deflate"]
Expand Down Expand Up @@ -36,18 +34,7 @@ def __init__(self, stats=None):
def from_crawler(cls, crawler):
if not crawler.settings.getbool("COMPRESSION_ENABLED"):
raise NotConfigured
try:
return cls(stats=crawler.stats)
except TypeError:
warnings.warn(
"HttpCompressionMiddleware subclasses must either modify "
"their '__init__' method to support a 'stats' parameter or "
"reimplement the 'from_crawler' method.",
ScrapyDeprecationWarning,
)
result = cls()
result.stats = crawler.stats
return result
return cls(stats=crawler.stats)

def process_request(self, request, spider):
request.headers.setdefault("Accept-Encoding", b", ".join(ACCEPTED_ENCODINGS))
Expand Down
35 changes: 5 additions & 30 deletions scrapy/dupefilters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import logging
from pathlib import Path
from typing import TYPE_CHECKING, Optional, Set
from warnings import warn

from twisted.internet.defer import Deferred

from scrapy.http.request import Request
from scrapy.settings import BaseSettings
from scrapy.spiders import Spider
from scrapy.utils.deprecate import ScrapyDeprecationWarning
from scrapy.utils.job import job_dir
from scrapy.utils.request import (
RequestFingerprinter,
Expand Down Expand Up @@ -75,38 +73,15 @@ def from_settings(
fingerprinter: Optional[RequestFingerprinterProtocol] = None,
) -> Self:
debug = settings.getbool("DUPEFILTER_DEBUG")
try:
return cls(job_dir(settings), debug, fingerprinter=fingerprinter)
except TypeError:
warn(
"RFPDupeFilter subclasses must either modify their '__init__' "
"method to support a 'fingerprinter' parameter or reimplement "
"the 'from_settings' class method.",
ScrapyDeprecationWarning,
)
result = cls(job_dir(settings), debug)
result.fingerprinter = fingerprinter or RequestFingerprinter()
return result
return cls(job_dir(settings), debug, fingerprinter=fingerprinter)

@classmethod
def from_crawler(cls, crawler: Crawler) -> Self:
assert crawler.request_fingerprinter
try:
return cls.from_settings(
crawler.settings,
fingerprinter=crawler.request_fingerprinter,
)
except TypeError:
warn(
"RFPDupeFilter subclasses must either modify their overridden "
"'__init__' method and 'from_settings' class method to "
"support a 'fingerprinter' parameter, or reimplement the "
"'from_crawler' class method.",
ScrapyDeprecationWarning,
)
result = cls.from_settings(crawler.settings)
result.fingerprinter = crawler.request_fingerprinter
return result
return cls.from_settings(
crawler.settings,
fingerprinter=crawler.request_fingerprinter,
)

def request_seen(self, request: Request) -> bool:
fp = self.request_fingerprint(request)
Expand Down
14 changes: 2 additions & 12 deletions scrapy/extensions/feedexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from scrapy.utils.ftp import ftp_store_file
from scrapy.utils.log import failure_to_exc_info
from scrapy.utils.misc import create_instance, load_object
from scrapy.utils.python import get_func_args, without_none_values
from scrapy.utils.python import without_none_values

logger = logging.getLogger(__name__)

Expand All @@ -42,17 +42,7 @@


def build_storage(builder, uri, *args, feed_options=None, preargs=(), **kwargs):
argument_names = get_func_args(builder)
if "feed_options" in argument_names:
kwargs["feed_options"] = feed_options
else:
warnings.warn(
f"{builder.__qualname__} does not support the 'feed_options' keyword argument. Add a "
"'feed_options' parameter to its signature to remove this "
"warning. This parameter will become mandatory in a future "
"version of Scrapy.",
category=ScrapyDeprecationWarning,
)
kwargs["feed_options"] = feed_options
return builder(*preargs, uri, *args, **kwargs)


Expand Down
2 changes: 1 addition & 1 deletion scrapy/http/request/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def from_curl(
``ignore_unknown_options=False``.
.. caution:: Using :meth:`from_curl` from :class:`~scrapy.http.Request`
subclasses, such as :class:`~scrapy.http.JSONRequest`, or
subclasses, such as :class:`~scrapy.http.JsonRequest`, or
:class:`~scrapy.http.XmlRpcRequest`, as well as having
:ref:`downloader middlewares <topics-downloader-middleware>`
and
Expand Down
4 changes: 0 additions & 4 deletions scrapy/http/request/json_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from typing import Optional, Tuple

from scrapy.http.request import Request
from scrapy.utils.deprecate import create_deprecated_class


class JsonRequest(Request):
Expand Down Expand Up @@ -58,6 +57,3 @@ def replace(self, *args, **kwargs) -> Request:
def _dumps(self, data: dict) -> str:
"""Convert to JSON"""
return json.dumps(data, **self._dumps_kwargs)


JSONRequest = create_deprecated_class("JSONRequest", JsonRequest)
21 changes: 0 additions & 21 deletions scrapy/loader/common.py

This file was deleted.

20 changes: 0 additions & 20 deletions scrapy/loader/processors.py

This file was deleted.

0 comments on commit 9b06f6b

Please sign in to comment.