Skip to content

Commit

Permalink
Remove uses of the deprecated scrapy.utils.reqser module (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
Laerte authored Jun 3, 2022
1 parent 53e5b92 commit 0aaa262
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ TBR
``OverridesRegistry`` which provides a wide variety of features
for better URL matching.
* This resuls in a newer format in the ``SCRAPY_POET_OVERRIDES`` setting.
* Removal of this deprecated module: ``scrapy.utils.reqser``


0.3.0 (2022-01-28)
Expand Down
3 changes: 1 addition & 2 deletions scrapy_poet/page_input_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from scrapy import Request
from scrapy.http import Response
from scrapy.crawler import Crawler
from scrapy.utils.reqser import request_to_dict
from scrapy.utils.request import request_fingerprint

from scrapy_poet.injection_errors import MalformedProvidedClassesError
Expand Down Expand Up @@ -175,7 +174,7 @@ def fingerprint(self, to_provide: Set[Callable], request: Request) -> str:
request_keys = {"url", "method", "body"}
request_data = {
k: str(v)
for k, v in request_to_dict(request).items()
for k, v in request.to_dict().items()
if k in request_keys
}
fp_data = {
Expand Down
9 changes: 4 additions & 5 deletions tests/test_callback_for.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import scrapy
import pytest
from scrapy.utils.reqser import request_to_dict

from web_poet.pages import ItemPage, ItemWebPage
from scrapy_poet import (
Expand Down Expand Up @@ -59,7 +58,7 @@ def test_default_callback():
"""Sample request not specifying callback."""
spider = MySpider()
request = scrapy.Request('http://example.com/')
request_dict = request_to_dict(request, spider)
request_dict = request.to_dict(spider=spider)
assert isinstance(request_dict, dict)
assert request_dict['url'] == 'http://example.com/'
assert request_dict['callback'] is None
Expand All @@ -69,13 +68,13 @@ def test_instance_method_callback():
"""Sample request specifying spider's instance method callback."""
spider = MySpider()
request = scrapy.Request('http://example.com/', callback=spider.parse_item)
request_dict = request_to_dict(request, spider)
request_dict = request.to_dict(spider=spider)
assert isinstance(request_dict, dict)
assert request_dict['url'] == 'http://example.com/'
assert request_dict['callback'] == 'parse_item'

request = scrapy.Request('http://example.com/', callback=spider.parse_web)
request_dict = request_to_dict(request, spider)
request_dict = request.to_dict(spider=spider)
assert isinstance(request_dict, dict)
assert request_dict['url'] == 'http://example.com/'
assert request_dict['callback'] == 'parse_web'
Expand All @@ -87,7 +86,7 @@ def test_inline_callback():
cb = callback_for(FakeItemPage)
request = scrapy.Request('http://example.com/', callback=cb)
with pytest.raises(ValueError) as exc:
request_to_dict(request, spider)
request.to_dict(spider=spider)

msg = f'Function {cb} is not an instance method in: {spider}'
assert str(exc.value) == msg
Expand Down

0 comments on commit 0aaa262

Please sign in to comment.