prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  use CSP: sandbox on /simple/ pages
  https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/sandbox + https://www.youtube.com/watch?v=fbhW37JZtSA&feature=youtu.be
  
  I believe this is a great fit for /simple/, which don't need any ability to do anthing but have a simple HTML structure.
  
  I _think_ we can replace the whole current header with `Content-Security-Policy: sandbox allow-top-navigations`.
  
  </issue>
  <code>
  [start of warehouse/csp.py]
  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 import copy
  15 
  16 
  17 SELF = "'self'"
  18 NONE = "'none'"
  19 
  20 
  21 def _serialize(policy):
  22     return "; ".join([
  23         " ".join([k] + [v2 for v2 in v if v2 is not None])
  24         for k, v in sorted(policy.items())
  25     ])
  26 
  27 
  28 def content_security_policy_tween_factory(handler, registry):
  29     def content_security_policy_tween(request):
  30         resp = handler(request)
  31 
  32         try:
  33             policy = request.find_service(name="csp")
  34         except ValueError:
  35             policy = collections.defaultdict(list)
  36 
  37         # We don't want to apply our Content Security Policy to the debug
  38         # toolbar, that's not part of our application and it doesn't work with
  39         # our restrictive CSP.
  40         policy = _serialize(policy).format(request=request)
  41         if not request.path.startswith("/_debug_toolbar/") and policy:
  42             resp.headers["Content-Security-Policy"] = policy
  43 
  44         return resp
  45 
  46     return content_security_policy_tween
  47 
  48 
  49 class CSPPolicy(collections.defaultdict):
  50     def __init__(self, policy=None):
  51         super().__init__(list, policy or {})
  52 
  53     def merge(self, policy):
  54         for key, attrs in policy.items():
  55             self[key].extend(attrs)
  56 
  57 
  58 def csp_factory(_, request):
  59     try:
  60         return CSPPolicy(copy.deepcopy(request.registry.settings["csp"]))
  61     except KeyError:
  62         return CSPPolicy({})
  63 
  64 
  65 def includeme(config):
  66     config.register_service_factory(csp_factory, name="csp")
  67     # Enable a Content Security Policy
  68     config.add_settings({
  69         "csp": {
  70             "base-uri": [SELF],
  71             "block-all-mixed-content": [],
  72             "connect-src": [
  73                 item for item in [
  74                     SELF,
  75                     config.registry.settings.get("statuspage.url"),
  76                     "https://api.github.com/repos/",
  77                 ]
  78                 if item
  79             ],
  80             "default-src": [NONE],
  81             "font-src": [SELF, "fonts.gstatic.com"],
  82             "form-action": [SELF],
  83             "frame-ancestors": [NONE],
  84             "frame-src": [NONE],
  85             "img-src": [
  86                 SELF,
  87                 config.registry.settings["camo.url"],
  88                 "www.google-analytics.com",
  89             ],
  90             "script-src": [
  91                 SELF,
  92                 "www.googletagmanager.com",
  93                 "www.google-analytics.com",
  94             ],
  95             "style-src": [SELF, "fonts.googleapis.com"],
  96         },
  97     })
  98     config.add_tween("warehouse.csp.content_security_policy_tween_factory")
  99
  [end of warehouse/csp.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/warehouse/csp.py b/warehouse/csp.py
  --- a/warehouse/csp.py
  +++ b/warehouse/csp.py
  @@ -34,6 +34,12 @@
           except ValueError:
               policy = collections.defaultdict(list)
   
  +        # Replace CSP headers on /simple/ pages.
  +        if request.path.startswith("/simple/"):
  +            policy = collections.defaultdict(list)
  +            policy["sandbox"] = ["allow-top-navigation"]
  +            policy["default-src"] = [NONE]
  +
           # We don't want to apply our Content Security Policy to the debug
           # toolbar, that's not part of our application and it doesn't work with
           # our restrictive CSP.
  
verification_info: {"golden_diff": "diff --git a/warehouse/csp.py b/warehouse/csp.py\n--- a/warehouse/csp.py\n+++ b/warehouse/csp.py\n@@ -34,6 +34,12 @@\n         except ValueError:\n             policy = collections.defaultdict(list)\n \n+        # Replace CSP headers on /simple/ pages.\n+        if request.path.startswith(\"/simple/\"):\n+            policy = collections.defaultdict(list)\n+            policy[\"sandbox\"] = [\"allow-top-navigation\"]\n+            policy[\"default-src\"] = [NONE]\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", "issue": "use CSP: sandbox on /simple/ pages\nhttps://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/sandbox + https://www.youtube.com/watch?v=fbhW37JZtSA&feature=youtu.be\r\n\r\nI believe this is a great fit for /simple/, which don't need any ability to do anthing but have a simple HTML structure.\r\n\r\nI _think_ we can replace the whole current header with `Content-Security-Policy: sandbox allow-top-navigations`.\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\nimport copy\n\n\nSELF = \"'self'\"\nNONE = \"'none'\"\n\n\ndef _serialize(policy):\n    return \"; \".join([\n        \" \".join([k] + [v2 for v2 in v if v2 is not None])\n        for k, v in sorted(policy.items())\n    ])\n\n\ndef content_security_policy_tween_factory(handler, registry):\n    def content_security_policy_tween(request):\n        resp = handler(request)\n\n        try:\n            policy = request.find_service(name=\"csp\")\n        except ValueError:\n            policy = collections.defaultdict(list)\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        policy = _serialize(policy).format(request=request)\n        if not request.path.startswith(\"/_debug_toolbar/\") and policy:\n            resp.headers[\"Content-Security-Policy\"] = policy\n\n        return resp\n\n    return content_security_policy_tween\n\n\nclass CSPPolicy(collections.defaultdict):\n    def __init__(self, policy=None):\n        super().__init__(list, policy or {})\n\n    def merge(self, policy):\n        for key, attrs in policy.items():\n            self[key].extend(attrs)\n\n\ndef csp_factory(_, request):\n    try:\n        return CSPPolicy(copy.deepcopy(request.registry.settings[\"csp\"]))\n    except KeyError:\n        return CSPPolicy({})\n\n\ndef includeme(config):\n    config.register_service_factory(csp_factory, name=\"csp\")\n    # Enable a Content Security Policy\n    config.add_settings({\n        \"csp\": {\n            \"base-uri\": [SELF],\n            \"block-all-mixed-content\": [],\n            \"connect-src\": [\n                item for item in [\n                    SELF,\n                    config.registry.settings.get(\"statuspage.url\"),\n                    \"https://api.github.com/repos/\",\n                ]\n                if item\n            ],\n            \"default-src\": [NONE],\n            \"font-src\": [SELF, \"fonts.gstatic.com\"],\n            \"form-action\": [SELF],\n            \"frame-ancestors\": [NONE],\n            \"frame-src\": [NONE],\n            \"img-src\": [\n                SELF,\n                config.registry.settings[\"camo.url\"],\n                \"www.google-analytics.com\",\n            ],\n            \"script-src\": [\n                SELF,\n                \"www.googletagmanager.com\",\n                \"www.google-analytics.com\",\n            ],\n            \"style-src\": [SELF, \"fonts.googleapis.com\"],\n        },\n    })\n    config.add_tween(\"warehouse.csp.content_security_policy_tween_factory\")\n", "path": "warehouse/csp.py"}]}