Scrapy, a fast high-level web crawling & scraping framework for Python.
makes suggested changes
Anubhav Patel2994b624e03e
diff --git a/scrapy/pipelines/images.py b/scrapy/pipelines/images.pyindex b95383b3b..fd34c9df6 100644--- a/scrapy/pipelines/images.py+++ b/scrapy/pipelines/images.py@@ -15,7 +15,7 @@ except ImportError:from PIL import Imagefrom scrapy.utils.misc import md5sum-from scrapy.utils.python import to_bytes+from scrapy.utils.python import to_bytes, get_func_argsfrom scrapy.http import Requestfrom scrapy.settings import Settingsfrom scrapy.exceptions import DropItem@@ -127,25 +127,14 @@ class ImagesPipeline(FilesPipeline):raise ImageException("Image too small (%dx%d < %dx%d)" %(width, height, self.min_width, self.min_height))- def _is_convert_image_overriden():- import inspect- if six.PY2:- convert_image_signature = inspect.getargspec(self.convert_image)- elif six.PY3:- convert_image_signature = inspect.getfullargspec(self.convert_image)- if 'response_body' not in convert_image_signature.args:- return True- return False-def _warn():from scrapy.exceptions import ScrapyDeprecationWarningimport warnings- warnings.warn('ImagesPipeline.convert_image() method overriden in a incompatible way, '+ warnings.warn('ImagesPipeline.convert_image() method overriden in a deprecated way, ''overriden method does not accept response_body argument.',category=ScrapyDeprecationWarning, stacklevel=1)- convert_image_overriden = _is_convert_image_overriden()- if convert_image_overriden:+ if 'response_body' not in get_func_args(self.convert_image):_warn()image, buf = self.convert_image(orig_image)else:@@ -154,7 +143,7 @@ class ImagesPipeline(FilesPipeline):for thumb_id, size in six.iteritems(self.thumbs):thumb_path = self.thumb_path(request, thumb_id, response=response, info=info)- if convert_image_overriden:+ if 'response_body' not in get_func_args(self.convert_image):thumb_image, thumb_buf = self.convert_image(image, size)else:thumb_image, thumb_buf = self.convert_image(image, size, buf)@@ -164,7 +153,7 @@ class ImagesPipeline(FilesPipeline):if not response_body:from scrapy.exceptions import ScrapyDeprecationWarningimport warnings- warnings.warn('ImagesPipeline.convert_image() method called in a incompatible way, '+ warnings.warn('ImagesPipeline.convert_image() method called in a deprecated way, ''method called without response_body argument.',category=ScrapyDeprecationWarning, stacklevel=1)diff --git a/tests/test_pipeline_images.py b/tests/test_pipeline_images.pyindex ba79dd6bd..ec0c87264 100644--- a/tests/test_pipeline_images.py+++ b/tests/test_pipeline_images.py@@ -108,7 +108,7 @@ class ImagesPipelineTestCase(unittest.TestCase):self.assertEqual(converted.getcolors(), [(10000, (205, 230, 255))])# ensure that we recieved deprecation warnings- self.assertTrue(len([warning for warning in w if 'ImagesPipeline.convert_image() method called in a incompatible way' in str(warning.message)]) == 4)+ self.assertTrue(len([warning for warning in w if 'ImagesPipeline.convert_image() method called in a deprecated way' in str(warning.message)]) == 4)# tests for new APISIZE = (100, 100)