PY3 fix tests pipelines images

This commit is contained in:
nyov 2015-07-29 17:48:27 +00:00 committed by Mikhail Korobov
parent 991197003b
commit 34eced0ee8
2 changed files with 6 additions and 4 deletions

View File

@ -15,6 +15,7 @@ except ImportError:
from PIL import Image
from scrapy.utils.misc import md5sum
from scrapy.utils.python import to_bytes
from scrapy.http import Request
from scrapy.exceptions import DropItem
#TODO: from scrapy.pipelines.media import MediaPipeline
@ -138,7 +139,7 @@ class ImagesPipeline(FilesPipeline):
return self.image_key(url)
## end of deprecation warning block
image_guid = hashlib.sha1(url).hexdigest() # change to request.url after deprecation
image_guid = hashlib.sha1(to_bytes(url)).hexdigest() # change to request.url after deprecation
return 'full/%s.jpg' % (image_guid)
def thumb_path(self, request, thumb_id, response=None, info=None):
@ -163,7 +164,7 @@ class ImagesPipeline(FilesPipeline):
return self.thumb_key(url, thumb_id)
## end of deprecation warning block
thumb_guid = hashlib.sha1(url).hexdigest() # change to request.url after deprecation
thumb_guid = hashlib.sha1(to_bytes(url)).hexdigest() # change to request.url after deprecation
return 'thumbs/%s/%s.jpg' % (thumb_id, thumb_guid)
# deprecated

View File

@ -10,6 +10,7 @@ from scrapy.item import Item, Field
from scrapy.http import Request, Response
from scrapy.settings import Settings
from scrapy.pipelines.images import ImagesPipeline
from scrapy.utils.python import to_bytes
skip = False
try:
@ -100,11 +101,11 @@ class DeprecatedImagesPipeline(ImagesPipeline):
return self.image_key(url)
def image_key(self, url):
image_guid = hashlib.sha1(url).hexdigest()
image_guid = hashlib.sha1(to_bytes(url)).hexdigest()
return 'empty/%s.jpg' % (image_guid)
def thumb_key(self, url, thumb_id):
thumb_guid = hashlib.sha1(url).hexdigest()
thumb_guid = hashlib.sha1(to_bytes(url)).hexdigest()
return 'thumbsup/%s/%s.jpg' % (thumb_id, thumb_guid)