fixed new_response_from_xpaths function, unicode string was passed as body instead of ResponseBody object

--HG--
extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40365
This commit is contained in:
Damian Canabal 2008-11-04 17:45:26 +00:00
parent a2461fbeea
commit 5e54ac52ff
1 changed files with 3 additions and 2 deletions

View File

@ -4,6 +4,7 @@ scrapy.http.Response objects
"""
from scrapy.xpath import XPathSelector
from scrapy.http.response import ResponseBody
def new_response_from_xpaths(response, xpaths):
"""Return a new response constructed by applying the given xpaths to the
@ -11,5 +12,5 @@ def new_response_from_xpaths(response, xpaths):
"""
xs = XPathSelector(response)
parts = [''.join([n for n in xs.x(x).extract()]) for x in xpaths]
new_body = ''.join(parts)
return response.replace(body=new_body)
new_body_content = ''.join(parts)
return response.replace(body=ResponseBody(content=new_body_content, declared_encoding=response.body.get_declared_encoding()))