prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Is there a way to limit the page-size of search API requests?
  ### Question
  Is there a way to limit the page-size of search API requests?
  
  The default Search-API page-size is 100 items: http://openlibrary.org/search.json?q=the+lord+of+the+rings
  
  I would like to reduce the page-size (limit) for Search API calls, since the user can just 'page' through the results if he/she wants. Fetching more results also requires more processing on the client-side.
  
  Side notes:
  - The number is 20 for the search-inside API: http://openlibrary.org/search/inside.json?q=thanks%20for%20all%20the%20fish
  - I think both default page-sizes should probably be the same (20 seems like a reasonable number to me).
  - The Archive.org API has the "limit" parameter to do this.
  
  Thanks!
  
  
  
  </issue>
  <code>
  [start of openlibrary/plugins/inside/code.py]
  1 from time import time
  2 
  3 import json
  4 import web
  5 
  6 from infogami.utils import delegate
  7 from infogami.utils.view import render_template
  8 
  9 from openlibrary.core.fulltext import fulltext_search
  10 
  11 RESULTS_PER_PAGE = 20
  12 
  13 
  14 class search_inside(delegate.page):
  15 
  16     path = '/search/inside'
  17 
  18     def GET(self):
  19         search_start = time()  # should probably use a @timeit decorator
  20         i = web.input(q='', page=1)
  21         query = i.q
  22         page = int(i.page)
  23         results = fulltext_search(query, page=page, limit=RESULTS_PER_PAGE)
  24         search_time = time() - search_start
  25 
  26         return render_template('search/inside.tmpl', query, results, search_time,
  27                                page=page, results_per_page=RESULTS_PER_PAGE)
  28         page.v2 = True  # page is mobile-first
  29         return page
  30 
  31 
  32 class search_inside_json(delegate.page):
  33     path = "/search/inside"
  34     encoding = "json"
  35 
  36     def GET(self):
  37         i = web.input(q='', page=1, limit=RESULTS_PER_PAGE)
  38         limit = min(i.limit, RESULTS_PER_PAGE) if i.limit else RESULTS_PER_PAGE
  39         query = i.q
  40         page = int(i.page)
  41         results = fulltext_search(query, page=page, limit=limit, js=True)
  42         web.header('Content-Type', 'application/json')
  43         return delegate.RawText(json.dumps(results, indent=4))
  44
  [end of openlibrary/plugins/inside/code.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/openlibrary/plugins/inside/code.py b/openlibrary/plugins/inside/code.py
  --- a/openlibrary/plugins/inside/code.py
  +++ b/openlibrary/plugins/inside/code.py
  @@ -4,7 +4,7 @@
   import web
   
   from infogami.utils import delegate
  -from infogami.utils.view import render_template
  +from infogami.utils.view import render_template, safeint
   
   from openlibrary.core.fulltext import fulltext_search
   
  @@ -12,7 +12,6 @@
   
   
   class search_inside(delegate.page):
  -
       path = '/search/inside'
   
       def GET(self):
  @@ -25,8 +24,6 @@
   
           return render_template('search/inside.tmpl', query, results, search_time,
                                  page=page, results_per_page=RESULTS_PER_PAGE)
  -        page.v2 = True  # page is mobile-first
  -        return page
   
   
   class search_inside_json(delegate.page):
  @@ -35,7 +32,7 @@
   
       def GET(self):
           i = web.input(q='', page=1, limit=RESULTS_PER_PAGE)
  -        limit = min(i.limit, RESULTS_PER_PAGE) if i.limit else RESULTS_PER_PAGE
  +        limit = min(safeint(i.limit, RESULTS_PER_PAGE), RESULTS_PER_PAGE)
           query = i.q
           page = int(i.page)
           results = fulltext_search(query, page=page, limit=limit, js=True)
  
verification_info: {"golden_diff": "diff --git a/openlibrary/plugins/inside/code.py b/openlibrary/plugins/inside/code.py\n--- a/openlibrary/plugins/inside/code.py\n+++ b/openlibrary/plugins/inside/code.py\n@@ -4,7 +4,7 @@\n import web\n \n from infogami.utils import delegate\n-from infogami.utils.view import render_template\n+from infogami.utils.view import render_template, safeint\n \n from openlibrary.core.fulltext import fulltext_search\n \n@@ -12,7 +12,6 @@\n \n \n class search_inside(delegate.page):\n-\n     path = '/search/inside'\n \n     def GET(self):\n@@ -25,8 +24,6 @@\n \n         return render_template('search/inside.tmpl', query, results, search_time,\n                                page=page, results_per_page=RESULTS_PER_PAGE)\n-        page.v2 = True  # page is mobile-first\n-        return page\n \n \n class search_inside_json(delegate.page):\n@@ -35,7 +32,7 @@\n \n     def GET(self):\n         i = web.input(q='', page=1, limit=RESULTS_PER_PAGE)\n-        limit = min(i.limit, RESULTS_PER_PAGE) if i.limit else RESULTS_PER_PAGE\n+        limit = min(safeint(i.limit, RESULTS_PER_PAGE), RESULTS_PER_PAGE)\n         query = i.q\n         page = int(i.page)\n         results = fulltext_search(query, page=page, limit=limit, js=True)\n", "issue": "Is there a way to limit the page-size of search API requests?\n### Question\r\nIs there a way to limit the page-size of search API requests?\r\n\r\nThe default Search-API page-size is 100 items: http://openlibrary.org/search.json?q=the+lord+of+the+rings\r\n\r\nI would like to reduce the page-size (limit) for Search API calls, since the user can just 'page' through the results if he/she wants. Fetching more results also requires more processing on the client-side.\r\n\r\nSide notes:\r\n- The number is 20 for the search-inside API: http://openlibrary.org/search/inside.json?q=thanks%20for%20all%20the%20fish\r\n- I think both default page-sizes should probably be the same (20 seems like a reasonable number to me).\r\n- The Archive.org API has the \"limit\" parameter to do this.\r\n\r\nThanks!\r\n\r\n\n", "before_files": [{"content": "from time import time\n\nimport json\nimport web\n\nfrom infogami.utils import delegate\nfrom infogami.utils.view import render_template\n\nfrom openlibrary.core.fulltext import fulltext_search\n\nRESULTS_PER_PAGE = 20\n\n\nclass search_inside(delegate.page):\n\n    path = '/search/inside'\n\n    def GET(self):\n        search_start = time()  # should probably use a @timeit decorator\n        i = web.input(q='', page=1)\n        query = i.q\n        page = int(i.page)\n        results = fulltext_search(query, page=page, limit=RESULTS_PER_PAGE)\n        search_time = time() - search_start\n\n        return render_template('search/inside.tmpl', query, results, search_time,\n                               page=page, results_per_page=RESULTS_PER_PAGE)\n        page.v2 = True  # page is mobile-first\n        return page\n\n\nclass search_inside_json(delegate.page):\n    path = \"/search/inside\"\n    encoding = \"json\"\n\n    def GET(self):\n        i = web.input(q='', page=1, limit=RESULTS_PER_PAGE)\n        limit = min(i.limit, RESULTS_PER_PAGE) if i.limit else RESULTS_PER_PAGE\n        query = i.q\n        page = int(i.page)\n        results = fulltext_search(query, page=page, limit=limit, js=True)\n        web.header('Content-Type', 'application/json')\n        return delegate.RawText(json.dumps(results, indent=4))\n", "path": "openlibrary/plugins/inside/code.py"}]}