mirror of https://github.com/scrapy/scrapy.git
Do not close the underlying file from compression plugins (#6239)
This commit is contained in:
parent
3562618f67
commit
82981fb8a2
|
|
@ -390,7 +390,13 @@ Each plugin is a class that must implement the following methods:
|
|||
|
||||
.. method:: close(self)
|
||||
|
||||
Close the target file object.
|
||||
Clean up the plugin.
|
||||
|
||||
For example, you might want to close a file wrapper that you might have
|
||||
used to compress data written into the file received in the ``__init__``
|
||||
method.
|
||||
|
||||
.. warning:: Do not close the file from the ``__init__`` method.
|
||||
|
||||
To pass a parameter to your plugin, use :ref:`feed options <feed-options>`. You
|
||||
can then access those parameters from the ``__init__`` method of your plugin.
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@ class GzipPlugin:
|
|||
|
||||
def close(self) -> None:
|
||||
self.gzipfile.close()
|
||||
self.file.close()
|
||||
|
||||
|
||||
class Bz2Plugin:
|
||||
|
|
@ -69,7 +68,6 @@ class Bz2Plugin:
|
|||
|
||||
def close(self) -> None:
|
||||
self.bz2file.close()
|
||||
self.file.close()
|
||||
|
||||
|
||||
class LZMAPlugin:
|
||||
|
|
@ -111,7 +109,6 @@ class LZMAPlugin:
|
|||
|
||||
def close(self) -> None:
|
||||
self.lzmafile.close()
|
||||
self.file.close()
|
||||
|
||||
|
||||
# io.IOBase is subclassed here, so that exporters can use the PostProcessingManager
|
||||
|
|
|
|||
|
|
@ -1732,6 +1732,7 @@ class FeedExportTest(FeedExportTestBase):
|
|||
|
||||
def store(self, file):
|
||||
Storage.store_file = file
|
||||
Storage.file_was_closed = file.closed
|
||||
file.close()
|
||||
|
||||
settings = {
|
||||
|
|
@ -1747,6 +1748,7 @@ class FeedExportTest(FeedExportTestBase):
|
|||
}
|
||||
yield self.exported_no_data(settings)
|
||||
self.assertIs(Storage.open_file, Storage.store_file)
|
||||
self.assertFalse(Storage.file_was_closed)
|
||||
|
||||
|
||||
class FeedPostProcessedExportsTest(FeedExportTestBase):
|
||||
|
|
|
|||
Loading…
Reference in New Issue