We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Link to GitHub from the homepage
It'd be nice to have a link to the GitHub repo in the header/footer. It makes it easier for users to file bugs, and avoids users getting confused between this repo and https://github.com/crateio/warehouse .


--- 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/__init__.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 from warehouse.__about__ import (
14     __author__, __copyright__, __email__, __license__, __summary__, __title__,
15     __uri__, __version__,
16 )
17 
18 
19 __all__ = [
20     "__author__", "__copyright__", "__email__", "__license__", "__summary__",
21     "__title__", "__uri__", "__version__",
22 ]
23
```

Path: `warehouse/config.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 enum
14 import os
15 import shlex
16 
17 import fs.opener
18 import transaction
19 
20 from pyramid import renderers
21 from pyramid.config import Configurator
22 from pyramid.httpexceptions import HTTPMovedPermanently
23 from pyramid.response import Response
24 
25 from warehouse.utils.static import WarehouseCacheBuster
26 
27 
28 class Environment(enum.Enum):
29     production = "production"
30     development = "development"
31 
32 
33 def content_security_policy_tween_factory(handler, registry):
34     policy = registry.settings.get("csp", {})
35     policy = "; ".join([" ".join([k] + v) for k, v in sorted(policy.items())])
36 
37     def content_security_policy_tween(request):
38         resp = handler(request)
39 
40         # We don't want to apply our Content Security Policy to the debug
41         # toolbar, that's not part of our application and it doesn't work with
42         # our restrictive CSP.
43         if not request.path.startswith("/_debug_toolbar/"):
44             resp.headers["Content-Security-Policy"] = \
45                 policy.format(request=request)
46 
47         return resp
48 
49     return content_security_policy_tween
50 
51 
52 def require_https_tween_factory(handler, registry):
53 
54     if not registry.settings.get("enforce_https", True):
55         return handler
56 
57     def require_https_tween(request):
58         # If we have an :action URL and we're not using HTTPS, then we want to
59         # return a 403 error.
60         if request.params.get(":action", None) and request.scheme != "https":
61             resp = Response(
62                 "SSL is required.",
63                 status=403,
64                 content_type="text/plain",
65             )
66             resp.status = "403 SSL is required"
67             resp.headers["X-Fastly-Error"] = "803"
68             return resp
69 
70         return handler(request)
71 
72     return require_https_tween
73 
74 
75 def activate_hook(request):
76     if request.path.startswith(("/_debug_toolbar/", "/static/")):
77         return False
78     return True
79 
80 
81 def maybe_set(settings, name, envvar, coercer=None, default=None):
82     if envvar in os.environ:
83         value = os.environ[envvar]
84         if coercer is not None:
85             value = coercer(value)
86         settings.setdefault(name, value)
87     elif default is not None:
88         settings.setdefault(name, default)
89 
90 
91 def maybe_set_compound(settings, base, name, envvar):
92     if envvar in os.environ:
93         value = shlex.split(os.environ[envvar])
94         kwargs = {k: v for k, v in (i.split("=") for i in value[1:])}
95         settings[".".join([base, name])] = value[0]
96         for key, value in kwargs.items():
97             settings[".".join([base, key])] = value
98 
99 
100 def configure(settings=None):
101     if settings is None:
102         settings = {}
103 
104     # Set the environment from an environment variable, if one hasn't already
105     # been set.
106     maybe_set(
107         settings, "warehouse.env", "WAREHOUSE_ENV", Environment,
108         default=Environment.production,
109     )
110 
111     # Pull in default configuration from the environment.
112     maybe_set(settings, "site.name", "SITE_NAME", default="Warehouse")
113     maybe_set(settings, "aws.key_id", "AWS_ACCESS_KEY_ID")
114     maybe_set(settings, "aws.secret_key", "AWS_SECRET_ACCESS_KEY")
115     maybe_set(settings, "aws.region", "AWS_REGION")
116     maybe_set(settings, "database.url", "DATABASE_URL")
117     maybe_set(settings, "sessions.url", "REDIS_URL")
118     maybe_set(settings, "download_stats.url", "REDIS_URL")
119     maybe_set(settings, "sessions.secret", "SESSION_SECRET")
120     maybe_set(settings, "camo.url", "CAMO_URL")
121     maybe_set(settings, "camo.key", "CAMO_KEY")
122     maybe_set(settings, "docs.url", "DOCS_URL")
123     maybe_set(settings, "dirs.documentation", "DOCS_DIR")
124     maybe_set_compound(settings, "files", "backend", "FILES_BACKEND")
125 
126     # Add the settings we use when the environment is set to development.
127     if settings["warehouse.env"] == Environment.development:
128         settings.setdefault("pyramid.reload_assets", True)
129         settings.setdefault("pyramid.reload_templates", True)
130         settings.setdefault("pyramid.prevent_http_cache", True)
131         settings.setdefault("debugtoolbar.hosts", ["0.0.0.0/0"])
132         settings.setdefault(
133             "debugtoolbar.panels",
134             [
135                 ".".join(["pyramid_debugtoolbar.panels", panel])
136                 for panel in [
137                     "versions.VersionDebugPanel",
138                     "settings.SettingsDebugPanel",
139                     "headers.HeaderDebugPanel",
140                     "request_vars.RequestVarsDebugPanel",
141                     "renderings.RenderingsDebugPanel",
142                     "logger.LoggingPanel",
143                     "performance.PerformanceDebugPanel",
144                     "routes.RoutesDebugPanel",
145                     "sqla.SQLADebugPanel",
146                     "tweens.TweensDebugPanel",
147                     "introspection.IntrospectionDebugPanel",
148                 ]
149             ],
150         )
151 
152     # Actually setup our Pyramid Configurator with the values pulled in from
153     # the environment as well as the ones passed in to the configure function.
154     config = Configurator(settings=settings)
155 
156     # Include anything needed by the development environment.
157     if config.registry.settings["warehouse.env"] == Environment.development:
158         config.include("pyramid_debugtoolbar")
159 
160     # Register our logging support
161     config.include(".logging")
162 
163     # We'll want to use Jinja2 as our template system.
164     config.include("pyramid_jinja2")
165 
166     # We want to use newstyle gettext
167     config.add_settings({"jinja2.newstyle": True})
168 
169     # We also want to use Jinja2 for .html templates as well, because we just
170     # assume that all templates will be using Jinja.
171     config.add_jinja2_renderer(".html")
172 
173     # We'll want to configure some filters for Jinja2 as well.
174     filters = config.get_settings().setdefault("jinja2.filters", {})
175     filters.setdefault("readme", "warehouse.filters:readme_renderer")
176     filters.setdefault("shorten_number", "warehouse.filters:shorten_number")
177 
178     # We also want to register some global functions for Jinja
179     jglobals = config.get_settings().setdefault("jinja2.globals", {})
180     jglobals.setdefault("gravatar", "warehouse.utils.gravatar:gravatar")
181 
182     # We'll store all of our templates in one location, warehouse/templates
183     # so we'll go ahead and add that to the Jinja2 search path.
184     config.add_jinja2_search_path("warehouse:templates", name=".html")
185 
186     # We want to configure our JSON renderer to sort the keys, and also to use
187     # an ultra compact serialization format.
188     config.add_renderer(
189         "json",
190         renderers.JSON(sort_keys=True, separators=(",", ":")),
191     )
192 
193     # Configure our transaction handling so that each request gets it's own
194     # transaction handler and the lifetime of the transaction is tied to the
195     # lifetime of the request.
196     config.add_settings({
197         "tm.attempts": 3,
198         "tm.manager_hook": lambda request: transaction.TransactionManager(),
199         "tm.activate_hook": activate_hook,
200         "tm.annotate_user": False,
201     })
202     config.include("pyramid_tm")
203 
204     # Register support for services
205     config.include("pyramid_services")
206 
207     # Register support for our legacy action URLs
208     config.include(".legacy.action_routing")
209 
210     # Register support for internationalization and localization
211     config.include(".i18n")
212 
213     # Register the configuration for the PostgreSQL database.
214     config.include(".db")
215 
216     # Register the support for AWS
217     config.include(".aws")
218 
219     # Register our session support
220     config.include(".sessions")
221 
222     # Register our support for http and origin caching
223     config.include(".cache.http")
224     config.include(".cache.origin")
225 
226     # Register our CSRF support
227     config.include(".csrf")
228 
229     # Register our authentication support.
230     config.include(".accounts")
231 
232     # Allow the packaging app to register any services it has.
233     config.include(".packaging")
234 
235     # Configure redirection support
236     config.include(".redirects")
237 
238     # Register all our URL routes for Warehouse.
239     config.include(".routes")
240 
241     # Enable a Content Security Policy
242     config.add_settings({
243         "csp": {
244             "default-src": ["'none'"],
245             "frame-ancestors": ["'none'"],
246             "img-src": [
247                 "'self'",
248                 config.registry.settings["camo.url"],
249                 "https://secure.gravatar.com",
250             ],
251             "referrer": ["cross-origin"],
252             "reflected-xss": ["block"],
253             "script-src": ["'self'"],
254             "style-src": ["'self'"],
255         },
256     })
257     config.add_tween("warehouse.config.content_security_policy_tween_factory")
258 
259     # Block non HTTPS requests for the legacy ?:action= routes when they are
260     # sent via POST.
261     config.add_tween("warehouse.config.require_https_tween_factory")
262 
263     # If a route matches with a slash appended to it, redirect to that route
264     # instead of returning a HTTPNotFound.
265     config.add_notfound_view(append_slash=HTTPMovedPermanently)
266 
267     # Configure the filesystems we use.
268     config.registry["filesystems"] = {}
269     for key, path in {
270             k[5:]: v
271             for k, v in config.registry.settings.items()
272             if k.startswith("dirs.")}.items():
273         config.registry["filesystems"][key] = \
274             fs.opener.fsopendir(path, create_dir=True)
275 
276     # Enable Warehouse to service our static files
277     config.add_static_view(
278         name="static",
279         path="warehouse:static",
280         cachebust=WarehouseCacheBuster(
281             "warehouse:static/manifest.json",
282             cache=not config.registry.settings["pyramid.reload_assets"],
283         ),
284     )
285 
286     # Scan everything for configuration
287     config.scan(ignore=["warehouse.migrations.env"])
288 
289     return config
290
```

Path: `warehouse/__about__.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 __all__ = [
14     "__title__", "__summary__", "__uri__", "__version__", "__author__",
15     "__email__", "__license__", "__copyright__",
16 ]
17 
18 __title__ = "warehouse"
19 __summary__ = "Next Generation Python Package Repository"
20 __uri__ = "https://warehouse.python.org/"
21 
22 __version__ = "15.0.dev0"
23 
24 __author__ = "The Python Packaging Authority"
25 __email__ = "donald@stufft.io"
26 
27 __license__ = "Apache License, Version 2.0"
28 __copyright__ = "2015 %s" % __author__
29
```
--- 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/__about__.py b/warehouse/__about__.py
--- a/warehouse/__about__.py
+++ b/warehouse/__about__.py
@@ -10,17 +10,32 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import os.path
+
 __all__ = [
-    "__title__", "__summary__", "__uri__", "__version__", "__author__",
-    "__email__", "__license__", "__copyright__",
+    "__title__", "__summary__", "__uri__", "__version__", "__commit__",
+    "__author__", "__email__", "__license__", "__copyright__",
 ]
 
+
+try:
+    base_dir = os.path.dirname(os.path.abspath(__file__))
+except NameError:
+    base_dir = None
+
+
 __title__ = "warehouse"
 __summary__ = "Next Generation Python Package Repository"
 __uri__ = "https://warehouse.python.org/"
 
 __version__ = "15.0.dev0"
 
+if base_dir is not None and os.path.exists(os.path.join(base_dir, ".commit")):
+    with open(os.path.join(base_dir, ".commit")) as fp:
+        __commit__ = fp.read().strip()
+else:
+    __commit__ = None
+
 __author__ = "The Python Packaging Authority"
 __email__ = "donald@stufft.io"
 
diff --git a/warehouse/__init__.py b/warehouse/__init__.py
--- a/warehouse/__init__.py
+++ b/warehouse/__init__.py
@@ -11,12 +11,12 @@
 # limitations under the License.
 
 from warehouse.__about__ import (
-    __author__, __copyright__, __email__, __license__, __summary__, __title__,
-    __uri__, __version__,
+    __author__, __commit__, __copyright__, __email__, __license__, __summary__,
+    __title__, __uri__, __version__,
 )
 
 
 __all__ = [
-    "__author__", "__copyright__", "__email__", "__license__", "__summary__",
-    "__title__", "__uri__", "__version__",
+    "__author__", "__commit__", "__copyright__", "__email__", "__license__",
+    "__summary__", "__title__", "__uri__", "__version__",
 ]
diff --git a/warehouse/config.py b/warehouse/config.py
--- a/warehouse/config.py
+++ b/warehouse/config.py
@@ -22,6 +22,7 @@
 from pyramid.httpexceptions import HTTPMovedPermanently
 from pyramid.response import Response
 
+from warehouse import __commit__
 from warehouse.utils.static import WarehouseCacheBuster
 
 
@@ -101,6 +102,9 @@
     if settings is None:
         settings = {}
 
+    # Add information about the current copy of the code.
+    settings.setdefault("warehouse.commit", __commit__)
+
     # Set the environment from an environment variable, if one hasn't already
     # been set.
     maybe_set(

{"golden_diff": "diff --git a/warehouse/__about__.py b/warehouse/__about__.py\n--- a/warehouse/__about__.py\n+++ b/warehouse/__about__.py\n@@ -10,17 +10,32 @@\n # See the License for the specific language governing permissions and\n # limitations under the License.\n \n+import os.path\n+\n __all__ = [\n-    \"__title__\", \"__summary__\", \"__uri__\", \"__version__\", \"__author__\",\n-    \"__email__\", \"__license__\", \"__copyright__\",\n+    \"__title__\", \"__summary__\", \"__uri__\", \"__version__\", \"__commit__\",\n+    \"__author__\", \"__email__\", \"__license__\", \"__copyright__\",\n ]\n \n+\n+try:\n+    base_dir = os.path.dirname(os.path.abspath(__file__))\n+except NameError:\n+    base_dir = None\n+\n+\n __title__ = \"warehouse\"\n __summary__ = \"Next Generation Python Package Repository\"\n __uri__ = \"https://warehouse.python.org/\"\n \n __version__ = \"15.0.dev0\"\n \n+if base_dir is not None and os.path.exists(os.path.join(base_dir, \".commit\")):\n+    with open(os.path.join(base_dir, \".commit\")) as fp:\n+        __commit__ = fp.read().strip()\n+else:\n+    __commit__ = None\n+\n __author__ = \"The Python Packaging Authority\"\n __email__ = \"donald@stufft.io\"\n \ndiff --git a/warehouse/__init__.py b/warehouse/__init__.py\n--- a/warehouse/__init__.py\n+++ b/warehouse/__init__.py\n@@ -11,12 +11,12 @@\n # limitations under the License.\n \n from warehouse.__about__ import (\n-    __author__, __copyright__, __email__, __license__, __summary__, __title__,\n-    __uri__, __version__,\n+    __author__, __commit__, __copyright__, __email__, __license__, __summary__,\n+    __title__, __uri__, __version__,\n )\n \n \n __all__ = [\n-    \"__author__\", \"__copyright__\", \"__email__\", \"__license__\", \"__summary__\",\n-    \"__title__\", \"__uri__\", \"__version__\",\n+    \"__author__\", \"__commit__\", \"__copyright__\", \"__email__\", \"__license__\",\n+    \"__summary__\", \"__title__\", \"__uri__\", \"__version__\",\n ]\ndiff --git a/warehouse/config.py b/warehouse/config.py\n--- a/warehouse/config.py\n+++ b/warehouse/config.py\n@@ -22,6 +22,7 @@\n from pyramid.httpexceptions import HTTPMovedPermanently\n from pyramid.response import Response\n \n+from warehouse import __commit__\n from warehouse.utils.static import WarehouseCacheBuster\n \n \n@@ -101,6 +102,9 @@\n     if settings is None:\n         settings = {}\n \n+    # Add information about the current copy of the code.\n+    settings.setdefault(\"warehouse.commit\", __commit__)\n+\n     # Set the environment from an environment variable, if one hasn't already\n     # been set.\n     maybe_set(\n", "issue": "Link to GitHub from the homepage\nIt'd be nice to have a link to the GitHub repo in the header/footer. It makes it easier for users to file bugs, and avoids users getting confused between this repo and https://github.com/crateio/warehouse .\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\nfrom warehouse.__about__ import (\n    __author__, __copyright__, __email__, __license__, __summary__, __title__,\n    __uri__, __version__,\n)\n\n\n__all__ = [\n    \"__author__\", \"__copyright__\", \"__email__\", \"__license__\", \"__summary__\",\n    \"__title__\", \"__uri__\", \"__version__\",\n]\n", "path": "warehouse/__init__.py"}, {"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 enum\nimport os\nimport shlex\n\nimport fs.opener\nimport transaction\n\nfrom pyramid import renderers\nfrom pyramid.config import Configurator\nfrom pyramid.httpexceptions import HTTPMovedPermanently\nfrom pyramid.response import Response\n\nfrom warehouse.utils.static import WarehouseCacheBuster\n\n\nclass Environment(enum.Enum):\n    production = \"production\"\n    development = \"development\"\n\n\ndef content_security_policy_tween_factory(handler, registry):\n    policy = registry.settings.get(\"csp\", {})\n    policy = \"; \".join([\" \".join([k] + v) for k, v in sorted(policy.items())])\n\n    def content_security_policy_tween(request):\n        resp = handler(request)\n\n        # We don't want to apply our Content Security Policy to the debug\n        # toolbar, that's not part of our application and it doesn't work with\n        # our restrictive CSP.\n        if not request.path.startswith(\"/_debug_toolbar/\"):\n            resp.headers[\"Content-Security-Policy\"] = \\\n                policy.format(request=request)\n\n        return resp\n\n    return content_security_policy_tween\n\n\ndef require_https_tween_factory(handler, registry):\n\n    if not registry.settings.get(\"enforce_https\", True):\n        return handler\n\n    def require_https_tween(request):\n        # If we have an :action URL and we're not using HTTPS, then we want to\n        # return a 403 error.\n        if request.params.get(\":action\", None) and request.scheme != \"https\":\n            resp = Response(\n                \"SSL is required.\",\n                status=403,\n                content_type=\"text/plain\",\n            )\n            resp.status = \"403 SSL is required\"\n            resp.headers[\"X-Fastly-Error\"] = \"803\"\n            return resp\n\n        return handler(request)\n\n    return require_https_tween\n\n\ndef activate_hook(request):\n    if request.path.startswith((\"/_debug_toolbar/\", \"/static/\")):\n        return False\n    return True\n\n\ndef maybe_set(settings, name, envvar, coercer=None, default=None):\n    if envvar in os.environ:\n        value = os.environ[envvar]\n        if coercer is not None:\n            value = coercer(value)\n        settings.setdefault(name, value)\n    elif default is not None:\n        settings.setdefault(name, default)\n\n\ndef maybe_set_compound(settings, base, name, envvar):\n    if envvar in os.environ:\n        value = shlex.split(os.environ[envvar])\n        kwargs = {k: v for k, v in (i.split(\"=\") for i in value[1:])}\n        settings[\".\".join([base, name])] = value[0]\n        for key, value in kwargs.items():\n            settings[\".\".join([base, key])] = value\n\n\ndef configure(settings=None):\n    if settings is None:\n        settings = {}\n\n    # Set the environment from an environment variable, if one hasn't already\n    # been set.\n    maybe_set(\n        settings, \"warehouse.env\", \"WAREHOUSE_ENV\", Environment,\n        default=Environment.production,\n    )\n\n    # Pull in default configuration from the environment.\n    maybe_set(settings, \"site.name\", \"SITE_NAME\", default=\"Warehouse\")\n    maybe_set(settings, \"aws.key_id\", \"AWS_ACCESS_KEY_ID\")\n    maybe_set(settings, \"aws.secret_key\", \"AWS_SECRET_ACCESS_KEY\")\n    maybe_set(settings, \"aws.region\", \"AWS_REGION\")\n    maybe_set(settings, \"database.url\", \"DATABASE_URL\")\n    maybe_set(settings, \"sessions.url\", \"REDIS_URL\")\n    maybe_set(settings, \"download_stats.url\", \"REDIS_URL\")\n    maybe_set(settings, \"sessions.secret\", \"SESSION_SECRET\")\n    maybe_set(settings, \"camo.url\", \"CAMO_URL\")\n    maybe_set(settings, \"camo.key\", \"CAMO_KEY\")\n    maybe_set(settings, \"docs.url\", \"DOCS_URL\")\n    maybe_set(settings, \"dirs.documentation\", \"DOCS_DIR\")\n    maybe_set_compound(settings, \"files\", \"backend\", \"FILES_BACKEND\")\n\n    # Add the settings we use when the environment is set to development.\n    if settings[\"warehouse.env\"] == Environment.development:\n        settings.setdefault(\"pyramid.reload_assets\", True)\n        settings.setdefault(\"pyramid.reload_templates\", True)\n        settings.setdefault(\"pyramid.prevent_http_cache\", True)\n        settings.setdefault(\"debugtoolbar.hosts\", [\"0.0.0.0/0\"])\n        settings.setdefault(\n            \"debugtoolbar.panels\",\n            [\n                \".\".join([\"pyramid_debugtoolbar.panels\", panel])\n                for panel in [\n                    \"versions.VersionDebugPanel\",\n                    \"settings.SettingsDebugPanel\",\n                    \"headers.HeaderDebugPanel\",\n                    \"request_vars.RequestVarsDebugPanel\",\n                    \"renderings.RenderingsDebugPanel\",\n                    \"logger.LoggingPanel\",\n                    \"performance.PerformanceDebugPanel\",\n                    \"routes.RoutesDebugPanel\",\n                    \"sqla.SQLADebugPanel\",\n                    \"tweens.TweensDebugPanel\",\n                    \"introspection.IntrospectionDebugPanel\",\n                ]\n            ],\n        )\n\n    # Actually setup our Pyramid Configurator with the values pulled in from\n    # the environment as well as the ones passed in to the configure function.\n    config = Configurator(settings=settings)\n\n    # Include anything needed by the development environment.\n    if config.registry.settings[\"warehouse.env\"] == Environment.development:\n        config.include(\"pyramid_debugtoolbar\")\n\n    # Register our logging support\n    config.include(\".logging\")\n\n    # We'll want to use Jinja2 as our template system.\n    config.include(\"pyramid_jinja2\")\n\n    # We want to use newstyle gettext\n    config.add_settings({\"jinja2.newstyle\": True})\n\n    # We also want to use Jinja2 for .html templates as well, because we just\n    # assume that all templates will be using Jinja.\n    config.add_jinja2_renderer(\".html\")\n\n    # We'll want to configure some filters for Jinja2 as well.\n    filters = config.get_settings().setdefault(\"jinja2.filters\", {})\n    filters.setdefault(\"readme\", \"warehouse.filters:readme_renderer\")\n    filters.setdefault(\"shorten_number\", \"warehouse.filters:shorten_number\")\n\n    # We also want to register some global functions for Jinja\n    jglobals = config.get_settings().setdefault(\"jinja2.globals\", {})\n    jglobals.setdefault(\"gravatar\", \"warehouse.utils.gravatar:gravatar\")\n\n    # We'll store all of our templates in one location, warehouse/templates\n    # so we'll go ahead and add that to the Jinja2 search path.\n    config.add_jinja2_search_path(\"warehouse:templates\", name=\".html\")\n\n    # We want to configure our JSON renderer to sort the keys, and also to use\n    # an ultra compact serialization format.\n    config.add_renderer(\n        \"json\",\n        renderers.JSON(sort_keys=True, separators=(\",\", \":\")),\n    )\n\n    # Configure our transaction handling so that each request gets it's own\n    # transaction handler and the lifetime of the transaction is tied to the\n    # lifetime of the request.\n    config.add_settings({\n        \"tm.attempts\": 3,\n        \"tm.manager_hook\": lambda request: transaction.TransactionManager(),\n        \"tm.activate_hook\": activate_hook,\n        \"tm.annotate_user\": False,\n    })\n    config.include(\"pyramid_tm\")\n\n    # Register support for services\n    config.include(\"pyramid_services\")\n\n    # Register support for our legacy action URLs\n    config.include(\".legacy.action_routing\")\n\n    # Register support for internationalization and localization\n    config.include(\".i18n\")\n\n    # Register the configuration for the PostgreSQL database.\n    config.include(\".db\")\n\n    # Register the support for AWS\n    config.include(\".aws\")\n\n    # Register our session support\n    config.include(\".sessions\")\n\n    # Register our support for http and origin caching\n    config.include(\".cache.http\")\n    config.include(\".cache.origin\")\n\n    # Register our CSRF support\n    config.include(\".csrf\")\n\n    # Register our authentication support.\n    config.include(\".accounts\")\n\n    # Allow the packaging app to register any services it has.\n    config.include(\".packaging\")\n\n    # Configure redirection support\n    config.include(\".redirects\")\n\n    # Register all our URL routes for Warehouse.\n    config.include(\".routes\")\n\n    # Enable a Content Security Policy\n    config.add_settings({\n        \"csp\": {\n            \"default-src\": [\"'none'\"],\n            \"frame-ancestors\": [\"'none'\"],\n            \"img-src\": [\n                \"'self'\",\n                config.registry.settings[\"camo.url\"],\n                \"https://secure.gravatar.com\",\n            ],\n            \"referrer\": [\"cross-origin\"],\n            \"reflected-xss\": [\"block\"],\n            \"script-src\": [\"'self'\"],\n            \"style-src\": [\"'self'\"],\n        },\n    })\n    config.add_tween(\"warehouse.config.content_security_policy_tween_factory\")\n\n    # Block non HTTPS requests for the legacy ?:action= routes when they are\n    # sent via POST.\n    config.add_tween(\"warehouse.config.require_https_tween_factory\")\n\n    # If a route matches with a slash appended to it, redirect to that route\n    # instead of returning a HTTPNotFound.\n    config.add_notfound_view(append_slash=HTTPMovedPermanently)\n\n    # Configure the filesystems we use.\n    config.registry[\"filesystems\"] = {}\n    for key, path in {\n            k[5:]: v\n            for k, v in config.registry.settings.items()\n            if k.startswith(\"dirs.\")}.items():\n        config.registry[\"filesystems\"][key] = \\\n            fs.opener.fsopendir(path, create_dir=True)\n\n    # Enable Warehouse to service our static files\n    config.add_static_view(\n        name=\"static\",\n        path=\"warehouse:static\",\n        cachebust=WarehouseCacheBuster(\n            \"warehouse:static/manifest.json\",\n            cache=not config.registry.settings[\"pyramid.reload_assets\"],\n        ),\n    )\n\n    # Scan everything for configuration\n    config.scan(ignore=[\"warehouse.migrations.env\"])\n\n    return config\n", "path": "warehouse/config.py"}, {"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\n__all__ = [\n    \"__title__\", \"__summary__\", \"__uri__\", \"__version__\", \"__author__\",\n    \"__email__\", \"__license__\", \"__copyright__\",\n]\n\n__title__ = \"warehouse\"\n__summary__ = \"Next Generation Python Package Repository\"\n__uri__ = \"https://warehouse.python.org/\"\n\n__version__ = \"15.0.dev0\"\n\n__author__ = \"The Python Packaging Authority\"\n__email__ = \"donald@stufft.io\"\n\n__license__ = \"Apache License, Version 2.0\"\n__copyright__ = \"2015 %s\" % __author__\n", "path": "warehouse/__about__.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\nfrom warehouse.__about__ import (\n    __author__, __commit__, __copyright__, __email__, __license__, __summary__,\n    __title__, __uri__, __version__,\n)\n\n\n__all__ = [\n    \"__author__\", \"__commit__\", \"__copyright__\", \"__email__\", \"__license__\",\n    \"__summary__\", \"__title__\", \"__uri__\", \"__version__\",\n]\n", "path": "warehouse/__init__.py"}, {"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 enum\nimport os\nimport shlex\n\nimport fs.opener\nimport transaction\n\nfrom pyramid import renderers\nfrom pyramid.config import Configurator\nfrom pyramid.httpexceptions import HTTPMovedPermanently\nfrom pyramid.response import Response\n\nfrom warehouse import __commit__\nfrom warehouse.utils.static import WarehouseCacheBuster\n\n\nclass Environment(enum.Enum):\n    production = \"production\"\n    development = \"development\"\n\n\ndef content_security_policy_tween_factory(handler, registry):\n    policy = registry.settings.get(\"csp\", {})\n    policy = \"; \".join([\" \".join([k] + v) for k, v in sorted(policy.items())])\n\n    def content_security_policy_tween(request):\n        resp = handler(request)\n\n        # We don't want to apply our Content Security Policy to the debug\n        # toolbar, that's not part of our application and it doesn't work with\n        # our restrictive CSP.\n        if not request.path.startswith(\"/_debug_toolbar/\"):\n            resp.headers[\"Content-Security-Policy\"] = \\\n                policy.format(request=request)\n\n        return resp\n\n    return content_security_policy_tween\n\n\ndef require_https_tween_factory(handler, registry):\n\n    if not registry.settings.get(\"enforce_https\", True):\n        return handler\n\n    def require_https_tween(request):\n        # If we have an :action URL and we're not using HTTPS, then we want to\n        # return a 403 error.\n        if request.params.get(\":action\", None) and request.scheme != \"https\":\n            resp = Response(\n                \"SSL is required.\",\n                status=403,\n                content_type=\"text/plain\",\n            )\n            resp.status = \"403 SSL is required\"\n            resp.headers[\"X-Fastly-Error\"] = \"803\"\n            return resp\n\n        return handler(request)\n\n    return require_https_tween\n\n\ndef activate_hook(request):\n    if request.path.startswith((\"/_debug_toolbar/\", \"/static/\")):\n        return False\n    return True\n\n\ndef maybe_set(settings, name, envvar, coercer=None, default=None):\n    if envvar in os.environ:\n        value = os.environ[envvar]\n        if coercer is not None:\n            value = coercer(value)\n        settings.setdefault(name, value)\n    elif default is not None:\n        settings.setdefault(name, default)\n\n\ndef maybe_set_compound(settings, base, name, envvar):\n    if envvar in os.environ:\n        value = shlex.split(os.environ[envvar])\n        kwargs = {k: v for k, v in (i.split(\"=\") for i in value[1:])}\n        settings[\".\".join([base, name])] = value[0]\n        for key, value in kwargs.items():\n            settings[\".\".join([base, key])] = value\n\n\ndef configure(settings=None):\n    if settings is None:\n        settings = {}\n\n    # Add information about the current copy of the code.\n    settings.setdefault(\"warehouse.commit\", __commit__)\n\n    # Set the environment from an environment variable, if one hasn't already\n    # been set.\n    maybe_set(\n        settings, \"warehouse.env\", \"WAREHOUSE_ENV\", Environment,\n        default=Environment.production,\n    )\n\n    # Pull in default configuration from the environment.\n    maybe_set(settings, \"site.name\", \"SITE_NAME\", default=\"Warehouse\")\n    maybe_set(settings, \"aws.key_id\", \"AWS_ACCESS_KEY_ID\")\n    maybe_set(settings, \"aws.secret_key\", \"AWS_SECRET_ACCESS_KEY\")\n    maybe_set(settings, \"aws.region\", \"AWS_REGION\")\n    maybe_set(settings, \"database.url\", \"DATABASE_URL\")\n    maybe_set(settings, \"sessions.url\", \"REDIS_URL\")\n    maybe_set(settings, \"download_stats.url\", \"REDIS_URL\")\n    maybe_set(settings, \"sessions.secret\", \"SESSION_SECRET\")\n    maybe_set(settings, \"camo.url\", \"CAMO_URL\")\n    maybe_set(settings, \"camo.key\", \"CAMO_KEY\")\n    maybe_set(settings, \"docs.url\", \"DOCS_URL\")\n    maybe_set(settings, \"dirs.documentation\", \"DOCS_DIR\")\n    maybe_set_compound(settings, \"files\", \"backend\", \"FILES_BACKEND\")\n\n    # Add the settings we use when the environment is set to development.\n    if settings[\"warehouse.env\"] == Environment.development:\n        settings.setdefault(\"pyramid.reload_assets\", True)\n        settings.setdefault(\"pyramid.reload_templates\", True)\n        settings.setdefault(\"pyramid.prevent_http_cache\", True)\n        settings.setdefault(\"debugtoolbar.hosts\", [\"0.0.0.0/0\"])\n        settings.setdefault(\n            \"debugtoolbar.panels\",\n            [\n                \".\".join([\"pyramid_debugtoolbar.panels\", panel])\n                for panel in [\n                    \"versions.VersionDebugPanel\",\n                    \"settings.SettingsDebugPanel\",\n                    \"headers.HeaderDebugPanel\",\n                    \"request_vars.RequestVarsDebugPanel\",\n                    \"renderings.RenderingsDebugPanel\",\n                    \"logger.LoggingPanel\",\n                    \"performance.PerformanceDebugPanel\",\n                    \"routes.RoutesDebugPanel\",\n                    \"sqla.SQLADebugPanel\",\n                    \"tweens.TweensDebugPanel\",\n                    \"introspection.IntrospectionDebugPanel\",\n                ]\n            ],\n        )\n\n    # Actually setup our Pyramid Configurator with the values pulled in from\n    # the environment as well as the ones passed in to the configure function.\n    config = Configurator(settings=settings)\n\n    # Include anything needed by the development environment.\n    if config.registry.settings[\"warehouse.env\"] == Environment.development:\n        config.include(\"pyramid_debugtoolbar\")\n\n    # Register our logging support\n    config.include(\".logging\")\n\n    # We'll want to use Jinja2 as our template system.\n    config.include(\"pyramid_jinja2\")\n\n    # We want to use newstyle gettext\n    config.add_settings({\"jinja2.newstyle\": True})\n\n    # We also want to use Jinja2 for .html templates as well, because we just\n    # assume that all templates will be using Jinja.\n    config.add_jinja2_renderer(\".html\")\n\n    # We'll want to configure some filters for Jinja2 as well.\n    filters = config.get_settings().setdefault(\"jinja2.filters\", {})\n    filters.setdefault(\"readme\", \"warehouse.filters:readme_renderer\")\n    filters.setdefault(\"shorten_number\", \"warehouse.filters:shorten_number\")\n\n    # We also want to register some global functions for Jinja\n    jglobals = config.get_settings().setdefault(\"jinja2.globals\", {})\n    jglobals.setdefault(\"gravatar\", \"warehouse.utils.gravatar:gravatar\")\n\n    # We'll store all of our templates in one location, warehouse/templates\n    # so we'll go ahead and add that to the Jinja2 search path.\n    config.add_jinja2_search_path(\"warehouse:templates\", name=\".html\")\n\n    # We want to configure our JSON renderer to sort the keys, and also to use\n    # an ultra compact serialization format.\n    config.add_renderer(\n        \"json\",\n        renderers.JSON(sort_keys=True, separators=(\",\", \":\")),\n    )\n\n    # Configure our transaction handling so that each request gets it's own\n    # transaction handler and the lifetime of the transaction is tied to the\n    # lifetime of the request.\n    config.add_settings({\n        \"tm.attempts\": 3,\n        \"tm.manager_hook\": lambda request: transaction.TransactionManager(),\n        \"tm.activate_hook\": activate_hook,\n        \"tm.annotate_user\": False,\n    })\n    config.include(\"pyramid_tm\")\n\n    # Register support for services\n    config.include(\"pyramid_services\")\n\n    # Register support for our legacy action URLs\n    config.include(\".legacy.action_routing\")\n\n    # Register support for internationalization and localization\n    config.include(\".i18n\")\n\n    # Register the configuration for the PostgreSQL database.\n    config.include(\".db\")\n\n    # Register the support for AWS\n    config.include(\".aws\")\n\n    # Register our session support\n    config.include(\".sessions\")\n\n    # Register our support for http and origin caching\n    config.include(\".cache.http\")\n    config.include(\".cache.origin\")\n\n    # Register our CSRF support\n    config.include(\".csrf\")\n\n    # Register our authentication support.\n    config.include(\".accounts\")\n\n    # Allow the packaging app to register any services it has.\n    config.include(\".packaging\")\n\n    # Configure redirection support\n    config.include(\".redirects\")\n\n    # Register all our URL routes for Warehouse.\n    config.include(\".routes\")\n\n    # Enable a Content Security Policy\n    config.add_settings({\n        \"csp\": {\n            \"default-src\": [\"'none'\"],\n            \"frame-ancestors\": [\"'none'\"],\n            \"img-src\": [\n                \"'self'\",\n                config.registry.settings[\"camo.url\"],\n                \"https://secure.gravatar.com\",\n            ],\n            \"referrer\": [\"cross-origin\"],\n            \"reflected-xss\": [\"block\"],\n            \"script-src\": [\"'self'\"],\n            \"style-src\": [\"'self'\"],\n        },\n    })\n    config.add_tween(\"warehouse.config.content_security_policy_tween_factory\")\n\n    # Block non HTTPS requests for the legacy ?:action= routes when they are\n    # sent via POST.\n    config.add_tween(\"warehouse.config.require_https_tween_factory\")\n\n    # If a route matches with a slash appended to it, redirect to that route\n    # instead of returning a HTTPNotFound.\n    config.add_notfound_view(append_slash=HTTPMovedPermanently)\n\n    # Configure the filesystems we use.\n    config.registry[\"filesystems\"] = {}\n    for key, path in {\n            k[5:]: v\n            for k, v in config.registry.settings.items()\n            if k.startswith(\"dirs.\")}.items():\n        config.registry[\"filesystems\"][key] = \\\n            fs.opener.fsopendir(path, create_dir=True)\n\n    # Enable Warehouse to service our static files\n    config.add_static_view(\n        name=\"static\",\n        path=\"warehouse:static\",\n        cachebust=WarehouseCacheBuster(\n            \"warehouse:static/manifest.json\",\n            cache=not config.registry.settings[\"pyramid.reload_assets\"],\n        ),\n    )\n\n    # Scan everything for configuration\n    config.scan(ignore=[\"warehouse.migrations.env\"])\n\n    return config\n", "path": "warehouse/config.py"}, {"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 os.path\n\n__all__ = [\n    \"__title__\", \"__summary__\", \"__uri__\", \"__version__\", \"__commit__\",\n    \"__author__\", \"__email__\", \"__license__\", \"__copyright__\",\n]\n\n\ntry:\n    base_dir = os.path.dirname(os.path.abspath(__file__))\nexcept NameError:\n    base_dir = None\n\n\n__title__ = \"warehouse\"\n__summary__ = \"Next Generation Python Package Repository\"\n__uri__ = \"https://warehouse.python.org/\"\n\n__version__ = \"15.0.dev0\"\n\nif base_dir is not None and os.path.exists(os.path.join(base_dir, \".commit\")):\n    with open(os.path.join(base_dir, \".commit\")) as fp:\n        __commit__ = fp.read().strip()\nelse:\n    __commit__ = None\n\n__author__ = \"The Python Packaging Authority\"\n__email__ = \"donald@stufft.io\"\n\n__license__ = \"Apache License, Version 2.0\"\n__copyright__ = \"2015 %s\" % __author__\n", "path": "warehouse/__about__.py"}]}