scrapy/scrapy — pull request #601 by Blender3D (2014-02-18 08:20:35+00:00)
Title: Shell doesn't handle non-XML/HTML responses

The shell doesn't handle non-XML/HTML responses, as it attempts to create a `Selector` object for *every* response:

Traceback (most recent call last):
File "/home/blender/Projects/python/scrapy/scrapy/tests/test_shell.py", line 52, in test_inspect_response_binary
shell.start(response=response, spider=self.spider)
File "/home/blender/Projects/python/scrapy/scrapy/shell.py", line 50, in start
self.populate_vars(response, request, spider)
File "/home/blender/Projects/python/scrapy/scrapy/shell.py", line 102, in populate_vars
self.vars['sel'] = Selector(response)
File "/home/blender/Projects/python/scrapy/scrapy/selector/unified.py", line 73, in __init__
_root = LxmlDocument(response, self._parser)
File "/home/blender/Projects/python/scrapy/scrapy/selector/lxmldocument.py", line 27, in __new__
cache[parser] = _factory(response, parser)
File "/home/blender/Projects/python/scrapy/scrapy/selector/lxmldocument.py", line 13, in _factory
body = response.body_as_unicode().strip().encode('utf8') or ''
exceptions.AttributeError: 'Response' object has no attribute 'body_as_unicode'

Adding some code to test that the response is actually an `XmlResponse` or a `HtmlResponse` fixes this.