Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

PY3 fix tests pipelines files

nyov991197003bdf
diff --git a/scrapy/pipelines/files.py b/scrapy/pipelines/files.py
index 308d2f3c1..a85aad4e7 100644
--- a/scrapy/pipelines/files.py
+++ b/scrapy/pipelines/files.py
@@ -26,6 +26,7 @@ from scrapy.exceptions import NotConfigured, IgnoreRequest
from scrapy.http import Request
from scrapy.utils.misc import md5sum
from scrapy.utils.log import failure_to_exc_info
+from scrapy.utils.python import to_bytes
logger = logging.getLogger(__name__)
@@ -330,7 +331,7 @@ class FilesPipeline(MediaPipeline):
return self.file_key(url)
## end of deprecation warning block
- media_guid = hashlib.sha1(url).hexdigest() # change to request.url after deprecation
+ media_guid = hashlib.sha1(to_bytes(url)).hexdigest() # change to request.url after deprecation
media_ext = os.path.splitext(url)[1] # change to request.url after deprecation
return 'full/%s%s' % (media_guid, media_ext)
diff --git a/tests/test_pipeline_files.py b/tests/test_pipeline_files.py
index ac0438eba..c9977f5ca 100644
--- a/tests/test_pipeline_files.py
+++ b/tests/test_pipeline_files.py
@@ -12,6 +12,7 @@ from scrapy.pipelines.files import FilesPipeline, FSFilesStore
from scrapy.item import Item, Field
from scrapy.http import Request, Response
from scrapy.settings import Settings
+from scrapy.utils.python import to_bytes
from tests import mock
@@ -103,7 +104,7 @@ class FilesPipelineTestCase(unittest.TestCase):
class DeprecatedFilesPipeline(FilesPipeline):
def file_key(self, url):
- media_guid = hashlib.sha1(url).hexdigest()
+ media_guid = hashlib.sha1(to_bytes(url)).hexdigest()
media_ext = os.path.splitext(url)[1]
return 'empty/%s%s' % (media_guid, media_ext)