Scrapy, a fast high-level web crawling & scraping framework for Python.
Use super().__init__ in BaseItemExporter subclasses
Adrián Chavesed1e577610b7
diff --git a/scrapy/exporters.py b/scrapy/exporters.pyindex 3defafd60..0c28c2d7f 100644--- a/scrapy/exporters.py+++ b/scrapy/exporters.py@@ -24,8 +24,9 @@ __all__ = ['BaseItemExporter', 'PprintItemExporter', 'PickleItemExporter',class BaseItemExporter(object):- def __init__(self, **kwargs):- self._configure(kwargs)+ def __init__(self, dont_fail=False, **kwargs):+ self._kwargs = kwargs+ self._configure(kwargs, dont_fail=dont_fail)def _configure(self, options, dont_fail=False):"""Configure the exporter by poping options from the ``options`` dict.@@ -82,10 +83,10 @@ class BaseItemExporter(object):class JsonLinesItemExporter(BaseItemExporter):def __init__(self, file, **kwargs):- self._configure(kwargs, dont_fail=True)+ super().__init__(dont_fail=True, **kwargs)self.file = file- kwargs.setdefault('ensure_ascii', not self.encoding)- self.encoder = ScrapyJSONEncoder(**kwargs)+ self._kwargs.setdefault('ensure_ascii', not self.encoding)+ self.encoder = ScrapyJSONEncoder(**self._kwargs)def export_item(self, item):itemdict = dict(self._get_serialized_fields(item))@@ -96,15 +97,15 @@ class JsonLinesItemExporter(BaseItemExporter):class JsonItemExporter(BaseItemExporter):def __init__(self, file, **kwargs):- self._configure(kwargs, dont_fail=True)+ super().__init__(dont_fail=True, **kwargs)self.file = file# there is a small difference between the behaviour or JsonItemExporter.indent# and ScrapyJSONEncoder.indent. ScrapyJSONEncoder.indent=None is needed to prevent# the addition of newlines everywherejson_indent = self.indent if self.indent is not None and self.indent > 0 else None- kwargs.setdefault('indent', json_indent)- kwargs.setdefault('ensure_ascii', not self.encoding)- self.encoder = ScrapyJSONEncoder(**kwargs)+ self._kwargs.setdefault('indent', json_indent)+ self._kwargs.setdefault('ensure_ascii', not self.encoding)+ self.encoder = ScrapyJSONEncoder(**self._kwargs)self.first_item = Truedef _beautify_newline(self):@@ -135,7 +136,7 @@ class XmlItemExporter(BaseItemExporter):def __init__(self, file, **kwargs):self.item_element = kwargs.pop('item_element', 'item')self.root_element = kwargs.pop('root_element', 'items')- self._configure(kwargs)+ super().__init__(**kwargs)if not self.encoding:self.encoding = 'utf-8'self.xg = XMLGenerator(file, encoding=self.encoding)@@ -191,7 +192,7 @@ class XmlItemExporter(BaseItemExporter):class CsvItemExporter(BaseItemExporter):def __init__(self, file, include_headers_line=True, join_multivalued=',', **kwargs):- self._configure(kwargs, dont_fail=True)+ super().__init__(dont_fail=True, **kwargs)if not self.encoding:self.encoding = 'utf-8'self.include_headers_line = include_headers_line@@ -202,7 +203,7 @@ class CsvItemExporter(BaseItemExporter):encoding=self.encoding,newline='' # Windows needs this https://github.com/scrapy/scrapy/issues/3034)- self.csv_writer = csv.writer(self.stream, **kwargs)+ self.csv_writer = csv.writer(self.stream, **self._kwargs)self._headers_not_written = Trueself._join_multivalued = join_multivalued@@ -251,7 +252,7 @@ class CsvItemExporter(BaseItemExporter):class PickleItemExporter(BaseItemExporter):def __init__(self, file, protocol=2, **kwargs):- self._configure(kwargs)+ super().__init__(**kwargs)self.file = fileself.protocol = protocol@@ -270,7 +271,7 @@ class MarshalItemExporter(BaseItemExporter):"""def __init__(self, file, **kwargs):- self._configure(kwargs)+ super().__init__(**kwargs)self.file = filedef export_item(self, item):@@ -280,7 +281,7 @@ class MarshalItemExporter(BaseItemExporter):class PprintItemExporter(BaseItemExporter):def __init__(self, file, **kwargs):- self._configure(kwargs)+ super().__init__(**kwargs)self.file = filedef export_item(self, item):