prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  ItemLoader: support non-TextResponse
  At the moment, `ItemLoader(response=response)` fails if `response` is not a `TextResponse` instance.
  
  Passing a binary response can still be useful, though. For example, to allow processors to access the response from their loader context, and hence be able to report the source URL (`response.url`) when reporting input issues.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `scrapy/loader/__init__.py`
  Content:
  ```
  1 """
  2 Item Loader
  3 
  4 See documentation in docs/topics/loaders.rst
  5 """
  6 import itemloaders
  7 
  8 from scrapy.item import Item
  9 from scrapy.selector import Selector
  10 
  11 
  12 class ItemLoader(itemloaders.ItemLoader):
  13     """
  14     A user-friendly abstraction to populate an :ref:`item <topics-items>` with data
  15     by applying :ref:`field processors <topics-loaders-processors>` to scraped data.
  16     When instantiated with a ``selector`` or a ``response`` it supports
  17     data extraction from web pages using :ref:`selectors <topics-selectors>`.
  18 
  19     :param item: The item instance to populate using subsequent calls to
  20         :meth:`~ItemLoader.add_xpath`, :meth:`~ItemLoader.add_css`,
  21         or :meth:`~ItemLoader.add_value`.
  22     :type item: scrapy.item.Item
  23 
  24     :param selector: The selector to extract data from, when using the
  25         :meth:`add_xpath`, :meth:`add_css`, :meth:`replace_xpath`, or
  26         :meth:`replace_css` method.
  27     :type selector: :class:`~scrapy.selector.Selector` object
  28 
  29     :param response: The response used to construct the selector using the
  30         :attr:`default_selector_class`, unless the selector argument is given,
  31         in which case this argument is ignored.
  32     :type response: :class:`~scrapy.http.Response` object
  33 
  34     If no item is given, one is instantiated automatically using the class in
  35     :attr:`default_item_class`.
  36 
  37     The item, selector, response and remaining keyword arguments are
  38     assigned to the Loader context (accessible through the :attr:`context` attribute).
  39 
  40     .. attribute:: item
  41 
  42         The item object being parsed by this Item Loader.
  43         This is mostly used as a property so, when attempting to override this
  44         value, you may want to check out :attr:`default_item_class` first.
  45 
  46     .. attribute:: context
  47 
  48         The currently active :ref:`Context <loaders-context>` of this Item Loader.
  49 
  50     .. attribute:: default_item_class
  51 
  52         An :ref:`item <topics-items>` class (or factory), used to instantiate
  53         items when not given in the ``__init__`` method.
  54 
  55     .. attribute:: default_input_processor
  56 
  57         The default input processor to use for those fields which don't specify
  58         one.
  59 
  60     .. attribute:: default_output_processor
  61 
  62         The default output processor to use for those fields which don't specify
  63         one.
  64 
  65     .. attribute:: default_selector_class
  66 
  67         The class used to construct the :attr:`selector` of this
  68         :class:`ItemLoader`, if only a response is given in the ``__init__`` method.
  69         If a selector is given in the ``__init__`` method this attribute is ignored.
  70         This attribute is sometimes overridden in subclasses.
  71 
  72     .. attribute:: selector
  73 
  74         The :class:`~scrapy.selector.Selector` object to extract data from.
  75         It's either the selector given in the ``__init__`` method or one created from
  76         the response given in the ``__init__`` method using the
  77         :attr:`default_selector_class`. This attribute is meant to be
  78         read-only.
  79     """
  80 
  81     default_item_class = Item
  82     default_selector_class = Selector
  83 
  84     def __init__(self, item=None, selector=None, response=None, parent=None, **context):
  85         if selector is None and response is not None:
  86             selector = self.default_selector_class(response)
  87         context.update(response=response)
  88         super().__init__(item=item, selector=selector, parent=parent, **context)
  89
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/scrapy/loader/__init__.py b/scrapy/loader/__init__.py
  --- a/scrapy/loader/__init__.py
  +++ b/scrapy/loader/__init__.py
  @@ -83,6 +83,9 @@
   
       def __init__(self, item=None, selector=None, response=None, parent=None, **context):
           if selector is None and response is not None:
  -            selector = self.default_selector_class(response)
  +            try:
  +                selector = self.default_selector_class(response)
  +            except AttributeError:
  +                selector = None
           context.update(response=response)
           super().__init__(item=item, selector=selector, parent=parent, **context)
  
verification_info: {"golden_diff": "diff --git a/scrapy/loader/__init__.py b/scrapy/loader/__init__.py\n--- a/scrapy/loader/__init__.py\n+++ b/scrapy/loader/__init__.py\n@@ -83,6 +83,9 @@\n \n     def __init__(self, item=None, selector=None, response=None, parent=None, **context):\n         if selector is None and response is not None:\n-            selector = self.default_selector_class(response)\n+            try:\n+                selector = self.default_selector_class(response)\n+            except AttributeError:\n+                selector = None\n         context.update(response=response)\n         super().__init__(item=item, selector=selector, parent=parent, **context)\n", "issue": "ItemLoader: support non-TextResponse\nAt the moment, `ItemLoader(response=response)` fails if `response` is not a `TextResponse` instance.\r\n\r\nPassing a binary response can still be useful, though. For example, to allow processors to access the response from their loader context, and hence be able to report the source URL (`response.url`) when reporting input issues.\n", "before_files": [{"content": "\"\"\"\nItem Loader\n\nSee documentation in docs/topics/loaders.rst\n\"\"\"\nimport itemloaders\n\nfrom scrapy.item import Item\nfrom scrapy.selector import Selector\n\n\nclass ItemLoader(itemloaders.ItemLoader):\n    \"\"\"\n    A user-friendly abstraction to populate an :ref:`item <topics-items>` with data\n    by applying :ref:`field processors <topics-loaders-processors>` to scraped data.\n    When instantiated with a ``selector`` or a ``response`` it supports\n    data extraction from web pages using :ref:`selectors <topics-selectors>`.\n\n    :param item: The item instance to populate using subsequent calls to\n        :meth:`~ItemLoader.add_xpath`, :meth:`~ItemLoader.add_css`,\n        or :meth:`~ItemLoader.add_value`.\n    :type item: scrapy.item.Item\n\n    :param selector: The selector to extract data from, when using the\n        :meth:`add_xpath`, :meth:`add_css`, :meth:`replace_xpath`, or\n        :meth:`replace_css` method.\n    :type selector: :class:`~scrapy.selector.Selector` object\n\n    :param response: The response used to construct the selector using the\n        :attr:`default_selector_class`, unless the selector argument is given,\n        in which case this argument is ignored.\n    :type response: :class:`~scrapy.http.Response` object\n\n    If no item is given, one is instantiated automatically using the class in\n    :attr:`default_item_class`.\n\n    The item, selector, response and remaining keyword arguments are\n    assigned to the Loader context (accessible through the :attr:`context` attribute).\n\n    .. attribute:: item\n\n        The item object being parsed by this Item Loader.\n        This is mostly used as a property so, when attempting to override this\n        value, you may want to check out :attr:`default_item_class` first.\n\n    .. attribute:: context\n\n        The currently active :ref:`Context <loaders-context>` of this Item Loader.\n\n    .. attribute:: default_item_class\n\n        An :ref:`item <topics-items>` class (or factory), used to instantiate\n        items when not given in the ``__init__`` method.\n\n    .. attribute:: default_input_processor\n\n        The default input processor to use for those fields which don't specify\n        one.\n\n    .. attribute:: default_output_processor\n\n        The default output processor to use for those fields which don't specify\n        one.\n\n    .. attribute:: default_selector_class\n\n        The class used to construct the :attr:`selector` of this\n        :class:`ItemLoader`, if only a response is given in the ``__init__`` method.\n        If a selector is given in the ``__init__`` method this attribute is ignored.\n        This attribute is sometimes overridden in subclasses.\n\n    .. attribute:: selector\n\n        The :class:`~scrapy.selector.Selector` object to extract data from.\n        It's either the selector given in the ``__init__`` method or one created from\n        the response given in the ``__init__`` method using the\n        :attr:`default_selector_class`. This attribute is meant to be\n        read-only.\n    \"\"\"\n\n    default_item_class = Item\n    default_selector_class = Selector\n\n    def __init__(self, item=None, selector=None, response=None, parent=None, **context):\n        if selector is None and response is not None:\n            selector = self.default_selector_class(response)\n        context.update(response=response)\n        super().__init__(item=item, selector=selector, parent=parent, **context)\n", "path": "scrapy/loader/__init__.py"}], "after_files": [{"content": "\"\"\"\nItem Loader\n\nSee documentation in docs/topics/loaders.rst\n\"\"\"\nimport itemloaders\n\nfrom scrapy.item import Item\nfrom scrapy.selector import Selector\n\n\nclass ItemLoader(itemloaders.ItemLoader):\n    \"\"\"\n    A user-friendly abstraction to populate an :ref:`item <topics-items>` with data\n    by applying :ref:`field processors <topics-loaders-processors>` to scraped data.\n    When instantiated with a ``selector`` or a ``response`` it supports\n    data extraction from web pages using :ref:`selectors <topics-selectors>`.\n\n    :param item: The item instance to populate using subsequent calls to\n        :meth:`~ItemLoader.add_xpath`, :meth:`~ItemLoader.add_css`,\n        or :meth:`~ItemLoader.add_value`.\n    :type item: scrapy.item.Item\n\n    :param selector: The selector to extract data from, when using the\n        :meth:`add_xpath`, :meth:`add_css`, :meth:`replace_xpath`, or\n        :meth:`replace_css` method.\n    :type selector: :class:`~scrapy.selector.Selector` object\n\n    :param response: The response used to construct the selector using the\n        :attr:`default_selector_class`, unless the selector argument is given,\n        in which case this argument is ignored.\n    :type response: :class:`~scrapy.http.Response` object\n\n    If no item is given, one is instantiated automatically using the class in\n    :attr:`default_item_class`.\n\n    The item, selector, response and remaining keyword arguments are\n    assigned to the Loader context (accessible through the :attr:`context` attribute).\n\n    .. attribute:: item\n\n        The item object being parsed by this Item Loader.\n        This is mostly used as a property so, when attempting to override this\n        value, you may want to check out :attr:`default_item_class` first.\n\n    .. attribute:: context\n\n        The currently active :ref:`Context <loaders-context>` of this Item Loader.\n\n    .. attribute:: default_item_class\n\n        An :ref:`item <topics-items>` class (or factory), used to instantiate\n        items when not given in the ``__init__`` method.\n\n    .. attribute:: default_input_processor\n\n        The default input processor to use for those fields which don't specify\n        one.\n\n    .. attribute:: default_output_processor\n\n        The default output processor to use for those fields which don't specify\n        one.\n\n    .. attribute:: default_selector_class\n\n        The class used to construct the :attr:`selector` of this\n        :class:`ItemLoader`, if only a response is given in the ``__init__`` method.\n        If a selector is given in the ``__init__`` method this attribute is ignored.\n        This attribute is sometimes overridden in subclasses.\n\n    .. attribute:: selector\n\n        The :class:`~scrapy.selector.Selector` object to extract data from.\n        It's either the selector given in the ``__init__`` method or one created from\n        the response given in the ``__init__`` method using the\n        :attr:`default_selector_class`. This attribute is meant to be\n        read-only.\n    \"\"\"\n\n    default_item_class = Item\n    default_selector_class = Selector\n\n    def __init__(self, item=None, selector=None, response=None, parent=None, **context):\n        if selector is None and response is not None:\n            try:\n                selector = self.default_selector_class(response)\n            except AttributeError:\n                selector = None\n        context.update(response=response)\n        super().__init__(item=item, selector=selector, parent=parent, **context)\n", "path": "scrapy/loader/__init__.py"}]}