Fixed bug in file:// downloader handler with uris containing percent-escaped chars

This commit is contained in:
Pablo Hoffman 2009-12-12 10:57:17 -02:00
parent cca4be4d64
commit 3012030b2f
2 changed files with 6 additions and 3 deletions

View File

@ -1,6 +1,8 @@
"""Download handler for file:// scheme"""
from __future__ import with_statement
from urllib import url2pathname
from twisted.internet import defer
from scrapy.core.downloader.responsetypes import responsetypes
@ -10,7 +12,7 @@ def download_file(request, spider):
return defer.maybeDeferred(_all_in_one_read_download_file, request, spider)
def _all_in_one_read_download_file(request, spider):
filepath = request.url.split("file://")[1]
filepath = url2pathname(request.url.split("file://")[1])
with open(filepath) as f:
body = f.read()
respcls = responsetypes.from_args(filename=filepath, body=body)

View File

@ -20,7 +20,7 @@ class FileTestCase(unittest.TestCase):
def setUp(self):
self.tmpname = self.mktemp()
fd = open(self.tmpname, 'w')
fd = open(self.tmpname + '<', 'w')
fd.write('0123456789')
fd.close()
@ -30,7 +30,8 @@ class FileTestCase(unittest.TestCase):
self.assertEquals(response.status, 200)
self.assertEquals(response.body, '0123456789')
request = Request('file://%s' % self.tmpname)
request = Request('file://%s' % self.tmpname + '<')
assert request.url.upper().endswith('%3C')
return download_file(request, BaseSpider()).addCallback(_test)
def test_non_existent(self):