Skip to content

Commit

Permalink
Restore compatibility with Scrapy < 2.11 (#74)
Browse files Browse the repository at this point in the history
* Restore compatibility with Scrapy < 2.11

* Silence the warning when passing binary=False to PythonItemExporter

* Revert "Silence the warning when passing binary=False to PythonItemExporter"

This reverts commit ffe408f.
  • Loading branch information
Gallaecio authored Sep 21, 2023
1 parent 47a5f1f commit 2c6e303
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sh_scrapy/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import scrapy
from scrapy import signals
from scrapy import version_info as SCRAPY_VERSION_INFO
from scrapy.exceptions import ScrapyDeprecationWarning
from scrapy.exporters import PythonItemExporter
from scrapy.http import Request
Expand Down Expand Up @@ -41,7 +42,10 @@ def __init__(self, crawler):
self.crawler = crawler
self.logger = logging.getLogger(__name__)
self._write_item = self.pipe_writer.write_item
self.exporter = PythonItemExporter()
kwargs = {}
if SCRAPY_VERSION_INFO < (2, 11):
kwargs["binary"] = False
self.exporter = PythonItemExporter(**kwargs)

@classmethod
def from_crawler(cls, crawler):
Expand Down
1 change: 1 addition & 0 deletions tests/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def test_hs_ext_init(hs_ext):
assert hs_ext.crawler
assert hs_ext._write_item == hs_ext.pipe_writer.write_item
assert isinstance(hs_ext.exporter, PythonItemExporter)
assert hs_ext.exporter.export_item({"a": "b"}) == {"a": "b"}


@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7")
Expand Down

0 comments on commit 2c6e303

Please sign in to comment.