prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  inspect_response(response) yields incorrect response in IPython shell
  Example case (requires registration at example site, and even then would be hard to use as a use-case; modify to suit your needs): http://pastebin.com/GT8N893q
  
  In the above example, the response.meta printout in after_submit callback does not match that within the inspect_response shell on the second iteration (the first is correct).  It appears that inspect_response has a stale response the second time.
  
  
  </issue>
  <code>
  [start of scrapy/utils/console.py]
  1 from functools import wraps
  2 from collections import OrderedDict
  3 
  4 def _embed_ipython_shell(namespace={}, banner=''):
  5     """Start an IPython Shell"""
  6     try:
  7         from IPython.terminal.embed import InteractiveShellEmbed
  8         from IPython.terminal.ipapp import load_default_config
  9     except ImportError:
  10         from IPython.frontend.terminal.embed import InteractiveShellEmbed
  11         from IPython.frontend.terminal.ipapp import load_default_config
  12 
  13     @wraps(_embed_ipython_shell)
  14     def wrapper(namespace=namespace, banner=''):
  15         config = load_default_config()
  16         # Always use .instace() to ensure _instance propagation to all parents
  17         # this is needed for <TAB> completion works well for new imports
  18         shell = InteractiveShellEmbed.instance(
  19             banner1=banner, user_ns=namespace, config=config)
  20         shell()
  21     return wrapper
  22 
  23 def _embed_bpython_shell(namespace={}, banner=''):
  24     """Start a bpython shell"""
  25     import bpython
  26     @wraps(_embed_bpython_shell)
  27     def wrapper(namespace=namespace, banner=''):
  28         bpython.embed(locals_=namespace, banner=banner)
  29     return wrapper
  30 
  31 def _embed_standard_shell(namespace={}, banner=''):
  32     """Start a standard python shell"""
  33     import code
  34     try: # readline module is only available on unix systems
  35         import readline
  36     except ImportError:
  37         pass
  38     else:
  39         import rlcompleter
  40         readline.parse_and_bind("tab:complete")
  41     @wraps(_embed_standard_shell)
  42     def wrapper(namespace=namespace, banner=''):
  43         code.interact(banner=banner, local=namespace)
  44     return wrapper
  45 
  46 DEFAULT_PYTHON_SHELLS = OrderedDict([
  47     ('ipython', _embed_ipython_shell),
  48     ('bpython', _embed_bpython_shell),
  49     ( 'python', _embed_standard_shell),
  50 ])
  51 
  52 def get_shell_embed_func(shells=None, known_shells=None):
  53     """Return the first acceptable shell-embed function
  54     from a given list of shell names.
  55     """
  56     if shells is None: # list, preference order of shells
  57         shells = DEFAULT_PYTHON_SHELLS.keys()
  58     if known_shells is None: # available embeddable shells
  59         known_shells = DEFAULT_PYTHON_SHELLS.copy()
  60     for shell in shells:
  61         if shell in known_shells:
  62             try:
  63                 # function test: run all setup code (imports),
  64                 # but dont fall into the shell
  65                 return known_shells[shell]()
  66             except ImportError:
  67                 continue
  68 
  69 def start_python_console(namespace=None, banner='', shells=None):
  70     """Start Python console bound to the given namespace.
  71     Readline support and tab completion will be used on Unix, if available.
  72     """
  73     if namespace is None:
  74         namespace = {}
  75 
  76     try:
  77         shell = get_shell_embed_func(shells)
  78         if shell is not None:
  79             shell(namespace=namespace, banner=banner)
  80     except SystemExit: # raised when using exit() in python code.interact
  81         pass
  82
  [end of scrapy/utils/console.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/scrapy/utils/console.py b/scrapy/utils/console.py
  --- a/scrapy/utils/console.py
  +++ b/scrapy/utils/console.py
  @@ -15,6 +15,9 @@
           config = load_default_config()
           # Always use .instace() to ensure _instance propagation to all parents
           # this is needed for <TAB> completion works well for new imports
  +        # and clear the instance to always have the fresh env
  +        # on repeated breaks like with inspect_response()
  +        InteractiveShellEmbed.clear_instance()
           shell = InteractiveShellEmbed.instance(
               banner1=banner, user_ns=namespace, config=config)
           shell()
  
verification_info: {"golden_diff": "diff --git a/scrapy/utils/console.py b/scrapy/utils/console.py\n--- a/scrapy/utils/console.py\n+++ b/scrapy/utils/console.py\n@@ -15,6 +15,9 @@\n         config = load_default_config()\n         # Always use .instace() to ensure _instance propagation to all parents\n         # this is needed for <TAB> completion works well for new imports\n+        # and clear the instance to always have the fresh env\n+        # on repeated breaks like with inspect_response()\n+        InteractiveShellEmbed.clear_instance()\n         shell = InteractiveShellEmbed.instance(\n             banner1=banner, user_ns=namespace, config=config)\n         shell()\n", "issue": "inspect_response(response) yields incorrect response in IPython shell\nExample case (requires registration at example site, and even then would be hard to use as a use-case; modify to suit your needs): http://pastebin.com/GT8N893q\n\nIn the above example, the response.meta printout in after_submit callback does not match that within the inspect_response shell on the second iteration (the first is correct).  It appears that inspect_response has a stale response the second time.\n\n", "before_files": [{"content": "from functools import wraps\nfrom collections import OrderedDict\n\ndef _embed_ipython_shell(namespace={}, banner=''):\n    \"\"\"Start an IPython Shell\"\"\"\n    try:\n        from IPython.terminal.embed import InteractiveShellEmbed\n        from IPython.terminal.ipapp import load_default_config\n    except ImportError:\n        from IPython.frontend.terminal.embed import InteractiveShellEmbed\n        from IPython.frontend.terminal.ipapp import load_default_config\n\n    @wraps(_embed_ipython_shell)\n    def wrapper(namespace=namespace, banner=''):\n        config = load_default_config()\n        # Always use .instace() to ensure _instance propagation to all parents\n        # this is needed for <TAB> completion works well for new imports\n        shell = InteractiveShellEmbed.instance(\n            banner1=banner, user_ns=namespace, config=config)\n        shell()\n    return wrapper\n\ndef _embed_bpython_shell(namespace={}, banner=''):\n    \"\"\"Start a bpython shell\"\"\"\n    import bpython\n    @wraps(_embed_bpython_shell)\n    def wrapper(namespace=namespace, banner=''):\n        bpython.embed(locals_=namespace, banner=banner)\n    return wrapper\n\ndef _embed_standard_shell(namespace={}, banner=''):\n    \"\"\"Start a standard python shell\"\"\"\n    import code\n    try: # readline module is only available on unix systems\n        import readline\n    except ImportError:\n        pass\n    else:\n        import rlcompleter\n        readline.parse_and_bind(\"tab:complete\")\n    @wraps(_embed_standard_shell)\n    def wrapper(namespace=namespace, banner=''):\n        code.interact(banner=banner, local=namespace)\n    return wrapper\n\nDEFAULT_PYTHON_SHELLS = OrderedDict([\n    ('ipython', _embed_ipython_shell),\n    ('bpython', _embed_bpython_shell),\n    ( 'python', _embed_standard_shell),\n])\n\ndef get_shell_embed_func(shells=None, known_shells=None):\n    \"\"\"Return the first acceptable shell-embed function\n    from a given list of shell names.\n    \"\"\"\n    if shells is None: # list, preference order of shells\n        shells = DEFAULT_PYTHON_SHELLS.keys()\n    if known_shells is None: # available embeddable shells\n        known_shells = DEFAULT_PYTHON_SHELLS.copy()\n    for shell in shells:\n        if shell in known_shells:\n            try:\n                # function test: run all setup code (imports),\n                # but dont fall into the shell\n                return known_shells[shell]()\n            except ImportError:\n                continue\n\ndef start_python_console(namespace=None, banner='', shells=None):\n    \"\"\"Start Python console bound to the given namespace.\n    Readline support and tab completion will be used on Unix, if available.\n    \"\"\"\n    if namespace is None:\n        namespace = {}\n\n    try:\n        shell = get_shell_embed_func(shells)\n        if shell is not None:\n            shell(namespace=namespace, banner=banner)\n    except SystemExit: # raised when using exit() in python code.interact\n        pass\n", "path": "scrapy/utils/console.py"}]}