prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Improve parsing of result line
  The parsing of the input Python to find the last line which will be evaluated (rather than executed) to provide the result is probably a little brittle in certain corner cases.  We should look at what IPython does here and copy that.
  
  </issue>
  <code>
  [start of src/pyodide.py]
  1 """
  2 A library of helper utilities for connecting Python to the browser environment.
  3 """
  4 
  5 from js import XMLHttpRequest
  6 
  7 import io
  8 
  9 
  10 def open_url(url):
  11     """
  12     Fetches a given *url* and returns a io.StringIO to access its contents.
  13     """
  14     req = XMLHttpRequest.new()
  15     req.open('GET', url, False)
  16     req.send(None)
  17     return io.StringIO(req.response)
  18 
  19 
  20 __all__ = ['open_url']
  21
  [end of src/pyodide.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/src/pyodide.py b/src/pyodide.py
  --- a/src/pyodide.py
  +++ b/src/pyodide.py
  @@ -4,6 +4,7 @@
   
   from js import XMLHttpRequest
   
  +import ast
   import io
   
   
  @@ -17,4 +18,23 @@
       return io.StringIO(req.response)
   
   
  -__all__ = ['open_url']
  +def eval_code(code, ns):
  +    """
  +    Runs a string of code, the last part of which may be an expression.
  +    """
  +    mod = ast.parse(code)
  +    if isinstance(mod.body[-1], ast.Expr):
  +        expr = ast.Expression(mod.body[-1].value)
  +        del mod.body[-1]
  +    else:
  +        expr = None
  +
  +    if len(mod.body):
  +        exec(compile(mod, '<exec>', mode='exec'), ns, ns)
  +    if expr is not None:
  +        return eval(compile(expr, '<eval>', mode='eval'), ns, ns)
  +    else:
  +        return None
  +
  +
  +__all__ = ['open_url', 'eval_code']
  
verification_info: {"golden_diff": "diff --git a/src/pyodide.py b/src/pyodide.py\n--- a/src/pyodide.py\n+++ b/src/pyodide.py\n@@ -4,6 +4,7 @@\n \n from js import XMLHttpRequest\n \n+import ast\n import io\n \n \n@@ -17,4 +18,23 @@\n     return io.StringIO(req.response)\n \n \n-__all__ = ['open_url']\n+def eval_code(code, ns):\n+    \"\"\"\n+    Runs a string of code, the last part of which may be an expression.\n+    \"\"\"\n+    mod = ast.parse(code)\n+    if isinstance(mod.body[-1], ast.Expr):\n+        expr = ast.Expression(mod.body[-1].value)\n+        del mod.body[-1]\n+    else:\n+        expr = None\n+\n+    if len(mod.body):\n+        exec(compile(mod, '<exec>', mode='exec'), ns, ns)\n+    if expr is not None:\n+        return eval(compile(expr, '<eval>', mode='eval'), ns, ns)\n+    else:\n+        return None\n+\n+\n+__all__ = ['open_url', 'eval_code']\n", "issue": "Improve parsing of result line\nThe parsing of the input Python to find the last line which will be evaluated (rather than executed) to provide the result is probably a little brittle in certain corner cases.  We should look at what IPython does here and copy that.\n", "before_files": [{"content": "\"\"\"\nA library of helper utilities for connecting Python to the browser environment.\n\"\"\"\n\nfrom js import XMLHttpRequest\n\nimport io\n\n\ndef open_url(url):\n    \"\"\"\n    Fetches a given *url* and returns a io.StringIO to access its contents.\n    \"\"\"\n    req = XMLHttpRequest.new()\n    req.open('GET', url, False)\n    req.send(None)\n    return io.StringIO(req.response)\n\n\n__all__ = ['open_url']\n", "path": "src/pyodide.py"}]}