We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
non-integer page params should result in a 4xx not a 500
https://github.com/pypa/warehouse/blob/master/warehouse/views.py#L195

Right now if you pass anything that's not an int, you get a 500.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `warehouse/views.py`
Content:
```
1 # Licensed under the Apache License, Version 2.0 (the "License");
2 # you may not use this file except in compliance with the License.
3 # You may obtain a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS,
9 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 # See the License for the specific language governing permissions and
11 # limitations under the License.
12 
13 import collections
14 
15 from pyramid.httpexceptions import (
16     HTTPException, HTTPSeeOther, HTTPMovedPermanently, HTTPNotFound,
17 )
18 from pyramid.view import (
19     notfound_view_config, forbidden_view_config, view_config,
20 )
21 from elasticsearch_dsl import Q
22 from sqlalchemy import func
23 from sqlalchemy.orm import aliased, joinedload
24 
25 from warehouse.accounts import REDIRECT_FIELD_NAME
26 from warehouse.accounts.models import User
27 from warehouse.cache.origin import origin_cache
28 from warehouse.cache.http import cache_control
29 from warehouse.classifiers.models import Classifier
30 from warehouse.packaging.models import Project, Release, File
31 from warehouse.utils.row_counter import RowCount
32 from warehouse.utils.paginate import ElasticsearchPage, paginate_url_factory
33 
34 
35 SEARCH_FIELDS = [
36     "author", "author_email", "description", "download_url", "home_page",
37     "keywords", "license", "maintainer", "maintainer_email", "normalized_name",
38     "platform", "summary",
39 ]
40 SEARCH_BOOSTS = {
41     "normalized_name": 10,
42     "description": 5,
43     "keywords": 5,
44     "summary": 5,
45 }
46 
47 
48 @view_config(context=HTTPException)
49 @notfound_view_config(append_slash=HTTPMovedPermanently)
50 def httpexception_view(exc, request):
51     return exc
52 
53 
54 @forbidden_view_config()
55 def forbidden(exc, request):
56     # If the forbidden error is because the user isn't logged in, then we'll
57     # redirect them to the log in page.
58     if request.authenticated_userid is None:
59         url = request.route_url(
60             "accounts.login",
61             _query={REDIRECT_FIELD_NAME: request.path_qs},
62         )
63         return HTTPSeeOther(url)
64 
65     # If we've reached here, then the user is logged in and they are genuinely
66     # not allowed to access this page.
67     # TODO: Style the forbidden page.
68     return exc
69 
70 
71 @view_config(
72     route_name="robots.txt",
73     renderer="robots.txt",
74     decorator=[
75         cache_control(1 * 24 * 60 * 60),         # 1 day
76         origin_cache(
77             1 * 24 * 60 * 60,                    # 1 day
78             stale_while_revalidate=6 * 60 * 60,  # 6 hours
79             stale_if_error=1 * 24 * 60 * 60,     # 1 day
80         ),
81     ],
82 )
83 def robotstxt(request):
84     request.response.content_type = "text/plain"
85     return {}
86 
87 
88 @view_config(
89     route_name="index",
90     renderer="index.html",
91     decorator=[
92         origin_cache(
93             1 * 60 * 60,                      # 1 hour
94             stale_while_revalidate=10 * 60,   # 10 minutes
95             stale_if_error=1 * 24 * 60 * 60,  # 1 day
96             keys=["all-projects"],
97         ),
98     ]
99 )
100 def index(request):
101     project_names = [
102         r[0] for r in (
103             request.db.query(File.name)
104                    .group_by(File.name)
105                    .order_by(func.sum(File.downloads).desc())
106                    .limit(5)
107                    .all())
108     ]
109     release_a = aliased(
110         Release,
111         request.db.query(Release)
112                   .distinct(Release.name)
113                   .filter(Release.name.in_(project_names))
114                   .order_by(Release.name, Release._pypi_ordering.desc())
115                   .subquery(),
116     )
117     top_projects = (
118         request.db.query(release_a)
119                .options(joinedload(release_a.project),
120                         joinedload(release_a.uploader))
121                .order_by(func.array_idx(project_names, release_a.name))
122                .all()
123     )
124 
125     latest_releases = (
126         request.db.query(Release)
127                   .options(joinedload(Release.project),
128                            joinedload(Release.uploader))
129                   .order_by(Release.created.desc())
130                   .limit(5)
131                   .all()
132     )
133 
134     counts = dict(
135         request.db.query(RowCount.table_name, RowCount.count)
136                   .filter(
137                       RowCount.table_name.in_([
138                           Project.__tablename__,
139                           Release.__tablename__,
140                           File.__tablename__,
141                           User.__tablename__,
142                       ]))
143                   .all()
144     )
145 
146     return {
147         "latest_releases": latest_releases,
148         "top_projects": top_projects,
149         "num_projects": counts.get(Project.__tablename__, 0),
150         "num_releases": counts.get(Release.__tablename__, 0),
151         "num_files": counts.get(File.__tablename__, 0),
152         "num_users": counts.get(User.__tablename__, 0),
153     }
154 
155 
156 @view_config(
157     route_name="search",
158     renderer="search/results.html",
159     decorator=[
160         origin_cache(
161             1 * 60 * 60,                      # 1 hour
162             stale_while_revalidate=10 * 60,   # 10 minutes
163             stale_if_error=1 * 24 * 60 * 60,  # 1 day
164             keys=["all-projects"],
165         )
166     ],
167 )
168 def search(request):
169 
170     q = request.params.get("q", '')
171 
172     if q:
173         should = []
174         for field in SEARCH_FIELDS:
175             kw = {"query": q}
176             if field in SEARCH_BOOSTS:
177                 kw["boost"] = SEARCH_BOOSTS[field]
178             should.append(Q("match", **{field: kw}))
179 
180         # Add a prefix query if ``q`` is longer than one character.
181         if len(q) > 1:
182             should.append(Q('prefix', normalized_name=q))
183 
184         query = request.es.query("dis_max", queries=should)
185         query = query.suggest("name_suggestion", q, term={"field": "name"})
186     else:
187         query = request.es.query()
188 
189     if request.params.get("o"):
190         query = query.sort(request.params["o"])
191 
192     if request.params.getall("c"):
193         query = query.filter("terms", classifiers=request.params.getall("c"))
194 
195     page_num = int(request.params.get("page", 1))
196     page = ElasticsearchPage(
197         query,
198         page=page_num,
199         url_maker=paginate_url_factory(request),
200     )
201 
202     if page.page_count and page_num > page.page_count:
203         raise HTTPNotFound
204 
205     available_filters = collections.defaultdict(list)
206 
207     for cls in request.db.query(Classifier).order_by(Classifier.classifier):
208         first, *_ = cls.classifier.split(' :: ')
209         available_filters[first].append(cls.classifier)
210 
211     return {
212         "page": page,
213         "term": q,
214         "order": request.params.get("o", ''),
215         "available_filters": sorted(available_filters.items()),
216         "applied_filters": request.params.getall("c"),
217     }
218 
219 
220 @view_config(
221     route_name="includes.current-user-indicator",
222     renderer="includes/current-user-indicator.html",
223     uses_session=True,
224 )
225 def current_user_indicator(request):
226     return {}
227 
228 
229 @view_config(route_name="health", renderer="string")
230 def health(request):
231     # This will ensure that we can access the database and run queries against
232     # it without doing anything that will take a lock or block other queries.
233     request.db.execute("SELECT 1")
234 
235     # Nothing will actually check this, but it's a little nicer to have
236     # something to return besides an empty body.
237     return "OK"
238
```
--- 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()

```

diff --git a/warehouse/views.py b/warehouse/views.py
--- a/warehouse/views.py
+++ b/warehouse/views.py
@@ -14,6 +14,7 @@
 
 from pyramid.httpexceptions import (
     HTTPException, HTTPSeeOther, HTTPMovedPermanently, HTTPNotFound,
+    HTTPBadRequest,
 )
 from pyramid.view import (
     notfound_view_config, forbidden_view_config, view_config,
@@ -192,7 +193,11 @@
     if request.params.getall("c"):
         query = query.filter("terms", classifiers=request.params.getall("c"))
 
-    page_num = int(request.params.get("page", 1))
+    try:
+        page_num = int(request.params.get("page", 1))
+    except ValueError:
+        raise HTTPBadRequest("'page' must be an integer.")
+
     page = ElasticsearchPage(
         query,
         page=page_num,

{"golden_diff": "diff --git a/warehouse/views.py b/warehouse/views.py\n--- a/warehouse/views.py\n+++ b/warehouse/views.py\n@@ -14,6 +14,7 @@\n \n from pyramid.httpexceptions import (\n     HTTPException, HTTPSeeOther, HTTPMovedPermanently, HTTPNotFound,\n+    HTTPBadRequest,\n )\n from pyramid.view import (\n     notfound_view_config, forbidden_view_config, view_config,\n@@ -192,7 +193,11 @@\n     if request.params.getall(\"c\"):\n         query = query.filter(\"terms\", classifiers=request.params.getall(\"c\"))\n \n-    page_num = int(request.params.get(\"page\", 1))\n+    try:\n+        page_num = int(request.params.get(\"page\", 1))\n+    except ValueError:\n+        raise HTTPBadRequest(\"'page' must be an integer.\")\n+\n     page = ElasticsearchPage(\n         query,\n         page=page_num,\n", "issue": "non-integer page params should result in a 4xx not a 500\nhttps://github.com/pypa/warehouse/blob/master/warehouse/views.py#L195\n\nRight now if you pass anything that's not an int, you get a 500.\n\n", "before_files": [{"content": "# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport collections\n\nfrom pyramid.httpexceptions import (\n    HTTPException, HTTPSeeOther, HTTPMovedPermanently, HTTPNotFound,\n)\nfrom pyramid.view import (\n    notfound_view_config, forbidden_view_config, view_config,\n)\nfrom elasticsearch_dsl import Q\nfrom sqlalchemy import func\nfrom sqlalchemy.orm import aliased, joinedload\n\nfrom warehouse.accounts import REDIRECT_FIELD_NAME\nfrom warehouse.accounts.models import User\nfrom warehouse.cache.origin import origin_cache\nfrom warehouse.cache.http import cache_control\nfrom warehouse.classifiers.models import Classifier\nfrom warehouse.packaging.models import Project, Release, File\nfrom warehouse.utils.row_counter import RowCount\nfrom warehouse.utils.paginate import ElasticsearchPage, paginate_url_factory\n\n\nSEARCH_FIELDS = [\n    \"author\", \"author_email\", \"description\", \"download_url\", \"home_page\",\n    \"keywords\", \"license\", \"maintainer\", \"maintainer_email\", \"normalized_name\",\n    \"platform\", \"summary\",\n]\nSEARCH_BOOSTS = {\n    \"normalized_name\": 10,\n    \"description\": 5,\n    \"keywords\": 5,\n    \"summary\": 5,\n}\n\n\n@view_config(context=HTTPException)\n@notfound_view_config(append_slash=HTTPMovedPermanently)\ndef httpexception_view(exc, request):\n    return exc\n\n\n@forbidden_view_config()\ndef forbidden(exc, request):\n    # If the forbidden error is because the user isn't logged in, then we'll\n    # redirect them to the log in page.\n    if request.authenticated_userid is None:\n        url = request.route_url(\n            \"accounts.login\",\n            _query={REDIRECT_FIELD_NAME: request.path_qs},\n        )\n        return HTTPSeeOther(url)\n\n    # If we've reached here, then the user is logged in and they are genuinely\n    # not allowed to access this page.\n    # TODO: Style the forbidden page.\n    return exc\n\n\n@view_config(\n    route_name=\"robots.txt\",\n    renderer=\"robots.txt\",\n    decorator=[\n        cache_control(1 * 24 * 60 * 60),         # 1 day\n        origin_cache(\n            1 * 24 * 60 * 60,                    # 1 day\n            stale_while_revalidate=6 * 60 * 60,  # 6 hours\n            stale_if_error=1 * 24 * 60 * 60,     # 1 day\n        ),\n    ],\n)\ndef robotstxt(request):\n    request.response.content_type = \"text/plain\"\n    return {}\n\n\n@view_config(\n    route_name=\"index\",\n    renderer=\"index.html\",\n    decorator=[\n        origin_cache(\n            1 * 60 * 60,                      # 1 hour\n            stale_while_revalidate=10 * 60,   # 10 minutes\n            stale_if_error=1 * 24 * 60 * 60,  # 1 day\n            keys=[\"all-projects\"],\n        ),\n    ]\n)\ndef index(request):\n    project_names = [\n        r[0] for r in (\n            request.db.query(File.name)\n                   .group_by(File.name)\n                   .order_by(func.sum(File.downloads).desc())\n                   .limit(5)\n                   .all())\n    ]\n    release_a = aliased(\n        Release,\n        request.db.query(Release)\n                  .distinct(Release.name)\n                  .filter(Release.name.in_(project_names))\n                  .order_by(Release.name, Release._pypi_ordering.desc())\n                  .subquery(),\n    )\n    top_projects = (\n        request.db.query(release_a)\n               .options(joinedload(release_a.project),\n                        joinedload(release_a.uploader))\n               .order_by(func.array_idx(project_names, release_a.name))\n               .all()\n    )\n\n    latest_releases = (\n        request.db.query(Release)\n                  .options(joinedload(Release.project),\n                           joinedload(Release.uploader))\n                  .order_by(Release.created.desc())\n                  .limit(5)\n                  .all()\n    )\n\n    counts = dict(\n        request.db.query(RowCount.table_name, RowCount.count)\n                  .filter(\n                      RowCount.table_name.in_([\n                          Project.__tablename__,\n                          Release.__tablename__,\n                          File.__tablename__,\n                          User.__tablename__,\n                      ]))\n                  .all()\n    )\n\n    return {\n        \"latest_releases\": latest_releases,\n        \"top_projects\": top_projects,\n        \"num_projects\": counts.get(Project.__tablename__, 0),\n        \"num_releases\": counts.get(Release.__tablename__, 0),\n        \"num_files\": counts.get(File.__tablename__, 0),\n        \"num_users\": counts.get(User.__tablename__, 0),\n    }\n\n\n@view_config(\n    route_name=\"search\",\n    renderer=\"search/results.html\",\n    decorator=[\n        origin_cache(\n            1 * 60 * 60,                      # 1 hour\n            stale_while_revalidate=10 * 60,   # 10 minutes\n            stale_if_error=1 * 24 * 60 * 60,  # 1 day\n            keys=[\"all-projects\"],\n        )\n    ],\n)\ndef search(request):\n\n    q = request.params.get(\"q\", '')\n\n    if q:\n        should = []\n        for field in SEARCH_FIELDS:\n            kw = {\"query\": q}\n            if field in SEARCH_BOOSTS:\n                kw[\"boost\"] = SEARCH_BOOSTS[field]\n            should.append(Q(\"match\", **{field: kw}))\n\n        # Add a prefix query if ``q`` is longer than one character.\n        if len(q) > 1:\n            should.append(Q('prefix', normalized_name=q))\n\n        query = request.es.query(\"dis_max\", queries=should)\n        query = query.suggest(\"name_suggestion\", q, term={\"field\": \"name\"})\n    else:\n        query = request.es.query()\n\n    if request.params.get(\"o\"):\n        query = query.sort(request.params[\"o\"])\n\n    if request.params.getall(\"c\"):\n        query = query.filter(\"terms\", classifiers=request.params.getall(\"c\"))\n\n    page_num = int(request.params.get(\"page\", 1))\n    page = ElasticsearchPage(\n        query,\n        page=page_num,\n        url_maker=paginate_url_factory(request),\n    )\n\n    if page.page_count and page_num > page.page_count:\n        raise HTTPNotFound\n\n    available_filters = collections.defaultdict(list)\n\n    for cls in request.db.query(Classifier).order_by(Classifier.classifier):\n        first, *_ = cls.classifier.split(' :: ')\n        available_filters[first].append(cls.classifier)\n\n    return {\n        \"page\": page,\n        \"term\": q,\n        \"order\": request.params.get(\"o\", ''),\n        \"available_filters\": sorted(available_filters.items()),\n        \"applied_filters\": request.params.getall(\"c\"),\n    }\n\n\n@view_config(\n    route_name=\"includes.current-user-indicator\",\n    renderer=\"includes/current-user-indicator.html\",\n    uses_session=True,\n)\ndef current_user_indicator(request):\n    return {}\n\n\n@view_config(route_name=\"health\", renderer=\"string\")\ndef health(request):\n    # This will ensure that we can access the database and run queries against\n    # it without doing anything that will take a lock or block other queries.\n    request.db.execute(\"SELECT 1\")\n\n    # Nothing will actually check this, but it's a little nicer to have\n    # something to return besides an empty body.\n    return \"OK\"\n", "path": "warehouse/views.py"}], "after_files": [{"content": "# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport collections\n\nfrom pyramid.httpexceptions import (\n    HTTPException, HTTPSeeOther, HTTPMovedPermanently, HTTPNotFound,\n    HTTPBadRequest,\n)\nfrom pyramid.view import (\n    notfound_view_config, forbidden_view_config, view_config,\n)\nfrom elasticsearch_dsl import Q\nfrom sqlalchemy import func\nfrom sqlalchemy.orm import aliased, joinedload\n\nfrom warehouse.accounts import REDIRECT_FIELD_NAME\nfrom warehouse.accounts.models import User\nfrom warehouse.cache.origin import origin_cache\nfrom warehouse.cache.http import cache_control\nfrom warehouse.classifiers.models import Classifier\nfrom warehouse.packaging.models import Project, Release, File\nfrom warehouse.utils.row_counter import RowCount\nfrom warehouse.utils.paginate import ElasticsearchPage, paginate_url_factory\n\n\nSEARCH_FIELDS = [\n    \"author\", \"author_email\", \"description\", \"download_url\", \"home_page\",\n    \"keywords\", \"license\", \"maintainer\", \"maintainer_email\", \"normalized_name\",\n    \"platform\", \"summary\",\n]\nSEARCH_BOOSTS = {\n    \"normalized_name\": 10,\n    \"description\": 5,\n    \"keywords\": 5,\n    \"summary\": 5,\n}\n\n\n@view_config(context=HTTPException)\n@notfound_view_config(append_slash=HTTPMovedPermanently)\ndef httpexception_view(exc, request):\n    return exc\n\n\n@forbidden_view_config()\ndef forbidden(exc, request):\n    # If the forbidden error is because the user isn't logged in, then we'll\n    # redirect them to the log in page.\n    if request.authenticated_userid is None:\n        url = request.route_url(\n            \"accounts.login\",\n            _query={REDIRECT_FIELD_NAME: request.path_qs},\n        )\n        return HTTPSeeOther(url)\n\n    # If we've reached here, then the user is logged in and they are genuinely\n    # not allowed to access this page.\n    # TODO: Style the forbidden page.\n    return exc\n\n\n@view_config(\n    route_name=\"robots.txt\",\n    renderer=\"robots.txt\",\n    decorator=[\n        cache_control(1 * 24 * 60 * 60),         # 1 day\n        origin_cache(\n            1 * 24 * 60 * 60,                    # 1 day\n            stale_while_revalidate=6 * 60 * 60,  # 6 hours\n            stale_if_error=1 * 24 * 60 * 60,     # 1 day\n        ),\n    ],\n)\ndef robotstxt(request):\n    request.response.content_type = \"text/plain\"\n    return {}\n\n\n@view_config(\n    route_name=\"index\",\n    renderer=\"index.html\",\n    decorator=[\n        origin_cache(\n            1 * 60 * 60,                      # 1 hour\n            stale_while_revalidate=10 * 60,   # 10 minutes\n            stale_if_error=1 * 24 * 60 * 60,  # 1 day\n            keys=[\"all-projects\"],\n        ),\n    ]\n)\ndef index(request):\n    project_names = [\n        r[0] for r in (\n            request.db.query(File.name)\n                   .group_by(File.name)\n                   .order_by(func.sum(File.downloads).desc())\n                   .limit(5)\n                   .all())\n    ]\n    release_a = aliased(\n        Release,\n        request.db.query(Release)\n                  .distinct(Release.name)\n                  .filter(Release.name.in_(project_names))\n                  .order_by(Release.name, Release._pypi_ordering.desc())\n                  .subquery(),\n    )\n    top_projects = (\n        request.db.query(release_a)\n               .options(joinedload(release_a.project),\n                        joinedload(release_a.uploader))\n               .order_by(func.array_idx(project_names, release_a.name))\n               .all()\n    )\n\n    latest_releases = (\n        request.db.query(Release)\n                  .options(joinedload(Release.project),\n                           joinedload(Release.uploader))\n                  .order_by(Release.created.desc())\n                  .limit(5)\n                  .all()\n    )\n\n    counts = dict(\n        request.db.query(RowCount.table_name, RowCount.count)\n                  .filter(\n                      RowCount.table_name.in_([\n                          Project.__tablename__,\n                          Release.__tablename__,\n                          File.__tablename__,\n                          User.__tablename__,\n                      ]))\n                  .all()\n    )\n\n    return {\n        \"latest_releases\": latest_releases,\n        \"top_projects\": top_projects,\n        \"num_projects\": counts.get(Project.__tablename__, 0),\n        \"num_releases\": counts.get(Release.__tablename__, 0),\n        \"num_files\": counts.get(File.__tablename__, 0),\n        \"num_users\": counts.get(User.__tablename__, 0),\n    }\n\n\n@view_config(\n    route_name=\"search\",\n    renderer=\"search/results.html\",\n    decorator=[\n        origin_cache(\n            1 * 60 * 60,                      # 1 hour\n            stale_while_revalidate=10 * 60,   # 10 minutes\n            stale_if_error=1 * 24 * 60 * 60,  # 1 day\n            keys=[\"all-projects\"],\n        )\n    ],\n)\ndef search(request):\n\n    q = request.params.get(\"q\", '')\n\n    if q:\n        should = []\n        for field in SEARCH_FIELDS:\n            kw = {\"query\": q}\n            if field in SEARCH_BOOSTS:\n                kw[\"boost\"] = SEARCH_BOOSTS[field]\n            should.append(Q(\"match\", **{field: kw}))\n\n        # Add a prefix query if ``q`` is longer than one character.\n        if len(q) > 1:\n            should.append(Q('prefix', normalized_name=q))\n\n        query = request.es.query(\"dis_max\", queries=should)\n        query = query.suggest(\"name_suggestion\", q, term={\"field\": \"name\"})\n    else:\n        query = request.es.query()\n\n    if request.params.get(\"o\"):\n        query = query.sort(request.params[\"o\"])\n\n    if request.params.getall(\"c\"):\n        query = query.filter(\"terms\", classifiers=request.params.getall(\"c\"))\n\n    try:\n        page_num = int(request.params.get(\"page\", 1))\n    except ValueError:\n        raise HTTPBadRequest(\"'page' must be an integer.\")\n\n    page = ElasticsearchPage(\n        query,\n        page=page_num,\n        url_maker=paginate_url_factory(request),\n    )\n\n    if page.page_count and page_num > page.page_count:\n        raise HTTPNotFound\n\n    available_filters = collections.defaultdict(list)\n\n    for cls in request.db.query(Classifier).order_by(Classifier.classifier):\n        first, *_ = cls.classifier.split(' :: ')\n        available_filters[first].append(cls.classifier)\n\n    return {\n        \"page\": page,\n        \"term\": q,\n        \"order\": request.params.get(\"o\", ''),\n        \"available_filters\": sorted(available_filters.items()),\n        \"applied_filters\": request.params.getall(\"c\"),\n    }\n\n\n@view_config(\n    route_name=\"includes.current-user-indicator\",\n    renderer=\"includes/current-user-indicator.html\",\n    uses_session=True,\n)\ndef current_user_indicator(request):\n    return {}\n\n\n@view_config(route_name=\"health\", renderer=\"string\")\ndef health(request):\n    # This will ensure that we can access the database and run queries against\n    # it without doing anything that will take a lock or block other queries.\n    request.db.execute(\"SELECT 1\")\n\n    # Nothing will actually check this, but it's a little nicer to have\n    # something to return besides an empty body.\n    return \"OK\"\n", "path": "warehouse/views.py"}]}