prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  base_url is used twice in redirects
  For  jupyterhub running at _http://address/prefix/_ almost every redirect has `base_url` twice. It was caused by PR #276. Reverting changes to jupyterhub/handlers/pages.py:27 [1] fixes the issue.
  
  [1] https://github.com/Crunch-io/jupyterhub/commit/05e4ab41fe6691dd697eecc27d9abee2ac4e23b6
  
  
  </issue>
  <code>
  [start of jupyterhub/handlers/pages.py]
  1 """Basic html-rendering handlers."""
  2 
  3 # Copyright (c) Jupyter Development Team.
  4 # Distributed under the terms of the Modified BSD License.
  5 
  6 from tornado import web
  7 
  8 from .. import orm
  9 from ..utils import admin_only, url_path_join
  10 from .base import BaseHandler
  11 
  12 
  13 class RootHandler(BaseHandler):
  14     """Render the Hub root page.
  15     
  16     If logged in, redirects to:
  17     
  18     - single-user server if running
  19     - hub home, otherwise
  20     
  21     Otherwise, renders login page.
  22     """
  23     def get(self):
  24         user = self.get_current_user()
  25         if user:
  26             if user.running:
  27                 url = url_path_join(self.hub.server.base_url, user.server.base_url)
  28                 self.log.debug("User is running: %s", url)
  29             else:
  30                 url = url_path_join(self.hub.server.base_url, 'home')
  31                 self.log.debug("User is not running: %s", url)
  32             self.redirect(url, permanent=False)
  33             return
  34         # Redirect to the authenticator login page instead of rendering the
  35         # login html page
  36         url = self.authenticator.login_url(self.hub.server.base_url)
  37         self.log.debug("No user logged in: %s", url)
  38         self.redirect(url, permanent=False)
  39 
  40 class HomeHandler(BaseHandler):
  41     """Render the user's home page."""
  42 
  43     @web.authenticated
  44     def get(self):
  45         html = self.render_template('home.html',
  46             user=self.get_current_user(),
  47         )
  48         self.finish(html)
  49 
  50 
  51 class AdminHandler(BaseHandler):
  52     """Render the admin page."""
  53 
  54     @admin_only
  55     def get(self):
  56         available = {'name', 'admin', 'running', 'last_activity'}
  57         default_sort = ['admin', 'name']
  58         mapping = {
  59             'running': '_server_id'
  60         }
  61         default_order = {
  62             'name': 'asc',
  63             'last_activity': 'desc',
  64             'admin': 'desc',
  65             'running': 'desc',
  66         }
  67         sorts = self.get_arguments('sort') or default_sort
  68         orders = self.get_arguments('order')
  69         
  70         for bad in set(sorts).difference(available):
  71             self.log.warn("ignoring invalid sort: %r", bad)
  72             sorts.remove(bad)
  73         for bad in set(orders).difference({'asc', 'desc'}):
  74             self.log.warn("ignoring invalid order: %r", bad)
  75             orders.remove(bad)
  76         
  77         # add default sort as secondary
  78         for s in default_sort:
  79             if s not in sorts:
  80                 sorts.append(s)
  81         if len(orders) < len(sorts):
  82             for col in sorts[len(orders):]:
  83                 orders.append(default_order[col])
  84         else:
  85             orders = orders[:len(sorts)]
  86         
  87         # this could be one incomprehensible nested list comprehension
  88         # get User columns
  89         cols = [ getattr(orm.User, mapping.get(c, c)) for c in sorts ]
  90         # get User.col.desc() order objects
  91         ordered = [ getattr(c, o)() for c, o in zip(cols, orders) ]
  92         
  93         users = self.db.query(orm.User).order_by(*ordered)
  94         running = users.filter(orm.User.server != None)
  95         
  96         html = self.render_template('admin.html',
  97             user=self.get_current_user(),
  98             admin_access=self.settings.get('admin_access', False),
  99             users=users,
  100             running=running,
  101             sort={s:o for s,o in zip(sorts, orders)},
  102         )
  103         self.finish(html)
  104 
  105 
  106 default_handlers = [
  107     (r'/', RootHandler),
  108     (r'/home', HomeHandler),
  109     (r'/admin', AdminHandler),
  110 ]
  111
  [end of jupyterhub/handlers/pages.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/jupyterhub/handlers/pages.py b/jupyterhub/handlers/pages.py
  --- a/jupyterhub/handlers/pages.py
  +++ b/jupyterhub/handlers/pages.py
  @@ -24,7 +24,7 @@
           user = self.get_current_user()
           if user:
               if user.running:
  -                url = url_path_join(self.hub.server.base_url, user.server.base_url)
  +                url = user.server.base_url
                   self.log.debug("User is running: %s", url)
               else:
                   url = url_path_join(self.hub.server.base_url, 'home')
  
verification_info: {"golden_diff": "diff --git a/jupyterhub/handlers/pages.py b/jupyterhub/handlers/pages.py\n--- a/jupyterhub/handlers/pages.py\n+++ b/jupyterhub/handlers/pages.py\n@@ -24,7 +24,7 @@\n         user = self.get_current_user()\n         if user:\n             if user.running:\n-                url = url_path_join(self.hub.server.base_url, user.server.base_url)\n+                url = user.server.base_url\n                 self.log.debug(\"User is running: %s\", url)\n             else:\n                 url = url_path_join(self.hub.server.base_url, 'home')\n", "issue": "base_url is used twice in redirects\nFor  jupyterhub running at _http://address/prefix/_ almost every redirect has `base_url` twice. It was caused by PR #276. Reverting changes to jupyterhub/handlers/pages.py:27 [1] fixes the issue.\n\n[1] https://github.com/Crunch-io/jupyterhub/commit/05e4ab41fe6691dd697eecc27d9abee2ac4e23b6\n\n", "before_files": [{"content": "\"\"\"Basic html-rendering handlers.\"\"\"\n\n# Copyright (c) Jupyter Development Team.\n# Distributed under the terms of the Modified BSD License.\n\nfrom tornado import web\n\nfrom .. import orm\nfrom ..utils import admin_only, url_path_join\nfrom .base import BaseHandler\n\n\nclass RootHandler(BaseHandler):\n    \"\"\"Render the Hub root page.\n    \n    If logged in, redirects to:\n    \n    - single-user server if running\n    - hub home, otherwise\n    \n    Otherwise, renders login page.\n    \"\"\"\n    def get(self):\n        user = self.get_current_user()\n        if user:\n            if user.running:\n                url = url_path_join(self.hub.server.base_url, user.server.base_url)\n                self.log.debug(\"User is running: %s\", url)\n            else:\n                url = url_path_join(self.hub.server.base_url, 'home')\n                self.log.debug(\"User is not running: %s\", url)\n            self.redirect(url, permanent=False)\n            return\n        # Redirect to the authenticator login page instead of rendering the\n        # login html page\n        url = self.authenticator.login_url(self.hub.server.base_url)\n        self.log.debug(\"No user logged in: %s\", url)\n        self.redirect(url, permanent=False)\n\nclass HomeHandler(BaseHandler):\n    \"\"\"Render the user's home page.\"\"\"\n\n    @web.authenticated\n    def get(self):\n        html = self.render_template('home.html',\n            user=self.get_current_user(),\n        )\n        self.finish(html)\n\n\nclass AdminHandler(BaseHandler):\n    \"\"\"Render the admin page.\"\"\"\n\n    @admin_only\n    def get(self):\n        available = {'name', 'admin', 'running', 'last_activity'}\n        default_sort = ['admin', 'name']\n        mapping = {\n            'running': '_server_id'\n        }\n        default_order = {\n            'name': 'asc',\n            'last_activity': 'desc',\n            'admin': 'desc',\n            'running': 'desc',\n        }\n        sorts = self.get_arguments('sort') or default_sort\n        orders = self.get_arguments('order')\n        \n        for bad in set(sorts).difference(available):\n            self.log.warn(\"ignoring invalid sort: %r\", bad)\n            sorts.remove(bad)\n        for bad in set(orders).difference({'asc', 'desc'}):\n            self.log.warn(\"ignoring invalid order: %r\", bad)\n            orders.remove(bad)\n        \n        # add default sort as secondary\n        for s in default_sort:\n            if s not in sorts:\n                sorts.append(s)\n        if len(orders) < len(sorts):\n            for col in sorts[len(orders):]:\n                orders.append(default_order[col])\n        else:\n            orders = orders[:len(sorts)]\n        \n        # this could be one incomprehensible nested list comprehension\n        # get User columns\n        cols = [ getattr(orm.User, mapping.get(c, c)) for c in sorts ]\n        # get User.col.desc() order objects\n        ordered = [ getattr(c, o)() for c, o in zip(cols, orders) ]\n        \n        users = self.db.query(orm.User).order_by(*ordered)\n        running = users.filter(orm.User.server != None)\n        \n        html = self.render_template('admin.html',\n            user=self.get_current_user(),\n            admin_access=self.settings.get('admin_access', False),\n            users=users,\n            running=running,\n            sort={s:o for s,o in zip(sorts, orders)},\n        )\n        self.finish(html)\n\n\ndefault_handlers = [\n    (r'/', RootHandler),\n    (r'/home', HomeHandler),\n    (r'/admin', AdminHandler),\n]\n", "path": "jupyterhub/handlers/pages.py"}]}