Skip to content

Commit 2c6e303

Browse files
authored
Restore compatibility with Scrapy < 2.11 (#74)
* 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.
1 parent 47a5f1f commit 2c6e303

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

sh_scrapy/extension.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import scrapy
66
from scrapy import signals
7+
from scrapy import version_info as SCRAPY_VERSION_INFO
78
from scrapy.exceptions import ScrapyDeprecationWarning
89
from scrapy.exporters import PythonItemExporter
910
from scrapy.http import Request
@@ -41,7 +42,10 @@ def __init__(self, crawler):
4142
self.crawler = crawler
4243
self.logger = logging.getLogger(__name__)
4344
self._write_item = self.pipe_writer.write_item
44-
self.exporter = PythonItemExporter()
45+
kwargs = {}
46+
if SCRAPY_VERSION_INFO < (2, 11):
47+
kwargs["binary"] = False
48+
self.exporter = PythonItemExporter(**kwargs)
4549

4650
@classmethod
4751
def from_crawler(cls, crawler):

tests/test_extension.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def test_hs_ext_init(hs_ext):
2626
assert hs_ext.crawler
2727
assert hs_ext._write_item == hs_ext.pipe_writer.write_item
2828
assert isinstance(hs_ext.exporter, PythonItemExporter)
29+
assert hs_ext.exporter.export_item({"a": "b"}) == {"a": "b"}
2930

3031

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

0 commit comments

Comments
 (0)