prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Weblate instance is down
  I tried accessing the Weblate instance and potentially add another language but it looks down.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `setup/server.py`
  Content:
  ```
  1 import flask
  2 import flask_bootstrap
  3 import redis
  4 import json
  5 import os
  6 import jinja2
  7 import uuid
  8 import string
  9 import random
  10 import ipaddress
  11 import hashlib
  12 import time
  13 
  14 
  15 version = os.getenv("this_version", "master")
  16 static_url_path = "/" + version + "/static"
  17 app = flask.Flask(__name__, static_url_path=static_url_path)
  18 flask_bootstrap.Bootstrap(app)
  19 db = redis.StrictRedis(host='redis', port=6379, db=0)
  20 
  21 
  22 def render_flavor(flavor, template, data):
  23     return flask.render_template(
  24         os.path.join(flavor, template),
  25         **data
  26     )
  27 
  28 
  29 @app.add_template_global
  30 def secret(length=16):
  31     charset = string.ascii_uppercase + string.digits
  32     return ''.join(
  33         random.SystemRandom().choice(charset)
  34         for _ in range(length)
  35     )
  36 
  37 #Original copied from https://github.com/andrewlkho/ulagen
  38 def random_ipv6_subnet():
  39     eui64 = uuid.getnode() >> 24 << 48 | 0xfffe000000 | uuid.getnode() & 0xffffff
  40     eui64_canon = "-".join([format(eui64, "02X")[i:i+2] for i in range(0, 18, 2)])
  41 
  42     h = hashlib.sha1()
  43     h.update((eui64_canon + str(time.time() - time.mktime((1900, 1, 1, 0, 0, 0, 0, 1, -1)))).encode('utf-8'))
  44     globalid = h.hexdigest()[0:10]
  45 
  46     prefix = ":".join(("fd" + globalid[0:2], globalid[2:6], globalid[6:10]))
  47     return prefix
  48 
  49 def build_app(path):
  50 
  51     app.jinja_env.trim_blocks = True
  52     app.jinja_env.lstrip_blocks = True
  53 
  54     @app.context_processor
  55     def app_context():
  56         return dict(
  57             versions=os.getenv("VERSIONS","master").split(','), 
  58             stable_version = os.getenv("stable_version", "master")
  59         )
  60 
  61     prefix_bp = flask.Blueprint(version, __name__)
  62     prefix_bp.jinja_loader = jinja2.ChoiceLoader([
  63         jinja2.FileSystemLoader(os.path.join(path, "templates")),
  64         jinja2.FileSystemLoader(os.path.join(path, "flavors"))
  65     ])
  66 
  67     root_bp = flask.Blueprint("root", __name__)
  68     root_bp.jinja_loader = jinja2.ChoiceLoader([
  69         jinja2.FileSystemLoader(os.path.join(path, "templates")),
  70         jinja2.FileSystemLoader(os.path.join(path, "flavors"))
  71     ])
  72 
  73     @prefix_bp.context_processor
  74     @root_bp.context_processor
  75     def bp_context(version=version):
  76         return dict(version=version)
  77 
  78     @prefix_bp.route("/")
  79     @root_bp.route("/")
  80     def wizard():
  81         return flask.render_template('wizard.html')
  82 
  83     @prefix_bp.route("/submit_flavor", methods=["POST"])
  84     @root_bp.route("/submit_flavor", methods=["POST"])
  85     def submit_flavor():
  86         data = flask.request.form.copy()
  87         subnet6 = random_ipv6_subnet()
  88         steps = sorted(os.listdir(os.path.join(path, "templates", "steps", data["flavor"])))
  89         return flask.render_template('wizard.html', flavor=data["flavor"], steps=steps, subnet6=subnet6)
  90 
  91     @prefix_bp.route("/submit", methods=["POST"])
  92     @root_bp.route("/submit", methods=["POST"])
  93     def submit():
  94         data = flask.request.form.copy()
  95         data['uid'] = str(uuid.uuid4())
  96         try:
  97             data['dns'] = str(ipaddress.IPv4Network(data['subnet'], strict=False)[-2])
  98         except ValueError as err:
  99             return "Error while generating files: " + str(err)
  100         db.set(data['uid'], json.dumps(data))
  101         return flask.redirect(flask.url_for('.setup', uid=data['uid']))
  102 
  103     @prefix_bp.route("/setup/<uid>", methods=["GET"])
  104     @root_bp.route("/setup/<uid>", methods=["GET"])
  105     def setup(uid):
  106         data = json.loads(db.get(uid))
  107         flavor = data.get("flavor", "compose")
  108         rendered = render_flavor(flavor, "setup.html", data)
  109         return flask.render_template("setup.html", contents=rendered)
  110 
  111     @prefix_bp.route("/file/<uid>/<filepath>", methods=["GET"])
  112     @root_bp.route("/file/<uid>/<filepath>", methods=["GET"])
  113     def file(uid, filepath):
  114         data = json.loads(db.get(uid))
  115         flavor = data.get("flavor", "compose")
  116         return flask.Response(
  117             render_flavor(flavor, filepath, data),
  118             mimetype="application/text"
  119         )
  120 
  121     app.register_blueprint(prefix_bp, url_prefix="/{}".format(version))
  122     app.register_blueprint(root_bp)
  123 
  124 
  125 if __name__ == "__main__":
  126     build_app("/tmp/mailutest")
  127     app.run(debug=True)
  128
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/setup/server.py b/setup/server.py
  --- a/setup/server.py
  +++ b/setup/server.py
  @@ -54,11 +54,11 @@
       @app.context_processor
       def app_context():
           return dict(
  -            versions=os.getenv("VERSIONS","master").split(','), 
  +            versions=os.getenv("VERSIONS","master").split(','),
               stable_version = os.getenv("stable_version", "master")
           )
   
  -    prefix_bp = flask.Blueprint(version, __name__)
  +    prefix_bp = flask.Blueprint(version.replace(".", "_"), __name__)
       prefix_bp.jinja_loader = jinja2.ChoiceLoader([
           jinja2.FileSystemLoader(os.path.join(path, "templates")),
           jinja2.FileSystemLoader(os.path.join(path, "flavors"))
  
verification_info: {"golden_diff": "diff --git a/setup/server.py b/setup/server.py\n--- a/setup/server.py\n+++ b/setup/server.py\n@@ -54,11 +54,11 @@\n     @app.context_processor\n     def app_context():\n         return dict(\n-            versions=os.getenv(\"VERSIONS\",\"master\").split(','), \n+            versions=os.getenv(\"VERSIONS\",\"master\").split(','),\n             stable_version = os.getenv(\"stable_version\", \"master\")\n         )\n \n-    prefix_bp = flask.Blueprint(version, __name__)\n+    prefix_bp = flask.Blueprint(version.replace(\".\", \"_\"), __name__)\n     prefix_bp.jinja_loader = jinja2.ChoiceLoader([\n         jinja2.FileSystemLoader(os.path.join(path, \"templates\")),\n         jinja2.FileSystemLoader(os.path.join(path, \"flavors\"))\n", "issue": "Weblate instance is down\nI tried accessing the Weblate instance and potentially add another language but it looks down.\n", "before_files": [{"content": "import flask\nimport flask_bootstrap\nimport redis\nimport json\nimport os\nimport jinja2\nimport uuid\nimport string\nimport random\nimport ipaddress\nimport hashlib\nimport time\n\n\nversion = os.getenv(\"this_version\", \"master\")\nstatic_url_path = \"/\" + version + \"/static\"\napp = flask.Flask(__name__, static_url_path=static_url_path)\nflask_bootstrap.Bootstrap(app)\ndb = redis.StrictRedis(host='redis', port=6379, db=0)\n\n\ndef render_flavor(flavor, template, data):\n    return flask.render_template(\n        os.path.join(flavor, template),\n        **data\n    )\n\n\n@app.add_template_global\ndef secret(length=16):\n    charset = string.ascii_uppercase + string.digits\n    return ''.join(\n        random.SystemRandom().choice(charset)\n        for _ in range(length)\n    )\n\n#Original copied from https://github.com/andrewlkho/ulagen\ndef random_ipv6_subnet():\n    eui64 = uuid.getnode() >> 24 << 48 | 0xfffe000000 | uuid.getnode() & 0xffffff\n    eui64_canon = \"-\".join([format(eui64, \"02X\")[i:i+2] for i in range(0, 18, 2)])\n\n    h = hashlib.sha1()\n    h.update((eui64_canon + str(time.time() - time.mktime((1900, 1, 1, 0, 0, 0, 0, 1, -1)))).encode('utf-8'))\n    globalid = h.hexdigest()[0:10]\n\n    prefix = \":\".join((\"fd\" + globalid[0:2], globalid[2:6], globalid[6:10]))\n    return prefix\n\ndef build_app(path):\n\n    app.jinja_env.trim_blocks = True\n    app.jinja_env.lstrip_blocks = True\n\n    @app.context_processor\n    def app_context():\n        return dict(\n            versions=os.getenv(\"VERSIONS\",\"master\").split(','), \n            stable_version = os.getenv(\"stable_version\", \"master\")\n        )\n\n    prefix_bp = flask.Blueprint(version, __name__)\n    prefix_bp.jinja_loader = jinja2.ChoiceLoader([\n        jinja2.FileSystemLoader(os.path.join(path, \"templates\")),\n        jinja2.FileSystemLoader(os.path.join(path, \"flavors\"))\n    ])\n\n    root_bp = flask.Blueprint(\"root\", __name__)\n    root_bp.jinja_loader = jinja2.ChoiceLoader([\n        jinja2.FileSystemLoader(os.path.join(path, \"templates\")),\n        jinja2.FileSystemLoader(os.path.join(path, \"flavors\"))\n    ])\n\n    @prefix_bp.context_processor\n    @root_bp.context_processor\n    def bp_context(version=version):\n        return dict(version=version)\n\n    @prefix_bp.route(\"/\")\n    @root_bp.route(\"/\")\n    def wizard():\n        return flask.render_template('wizard.html')\n\n    @prefix_bp.route(\"/submit_flavor\", methods=[\"POST\"])\n    @root_bp.route(\"/submit_flavor\", methods=[\"POST\"])\n    def submit_flavor():\n        data = flask.request.form.copy()\n        subnet6 = random_ipv6_subnet()\n        steps = sorted(os.listdir(os.path.join(path, \"templates\", \"steps\", data[\"flavor\"])))\n        return flask.render_template('wizard.html', flavor=data[\"flavor\"], steps=steps, subnet6=subnet6)\n\n    @prefix_bp.route(\"/submit\", methods=[\"POST\"])\n    @root_bp.route(\"/submit\", methods=[\"POST\"])\n    def submit():\n        data = flask.request.form.copy()\n        data['uid'] = str(uuid.uuid4())\n        try:\n            data['dns'] = str(ipaddress.IPv4Network(data['subnet'], strict=False)[-2])\n        except ValueError as err:\n            return \"Error while generating files: \" + str(err)\n        db.set(data['uid'], json.dumps(data))\n        return flask.redirect(flask.url_for('.setup', uid=data['uid']))\n\n    @prefix_bp.route(\"/setup/<uid>\", methods=[\"GET\"])\n    @root_bp.route(\"/setup/<uid>\", methods=[\"GET\"])\n    def setup(uid):\n        data = json.loads(db.get(uid))\n        flavor = data.get(\"flavor\", \"compose\")\n        rendered = render_flavor(flavor, \"setup.html\", data)\n        return flask.render_template(\"setup.html\", contents=rendered)\n\n    @prefix_bp.route(\"/file/<uid>/<filepath>\", methods=[\"GET\"])\n    @root_bp.route(\"/file/<uid>/<filepath>\", methods=[\"GET\"])\n    def file(uid, filepath):\n        data = json.loads(db.get(uid))\n        flavor = data.get(\"flavor\", \"compose\")\n        return flask.Response(\n            render_flavor(flavor, filepath, data),\n            mimetype=\"application/text\"\n        )\n\n    app.register_blueprint(prefix_bp, url_prefix=\"/{}\".format(version))\n    app.register_blueprint(root_bp)\n\n\nif __name__ == \"__main__\":\n    build_app(\"/tmp/mailutest\")\n    app.run(debug=True)\n", "path": "setup/server.py"}], "after_files": [{"content": "import flask\nimport flask_bootstrap\nimport redis\nimport json\nimport os\nimport jinja2\nimport uuid\nimport string\nimport random\nimport ipaddress\nimport hashlib\nimport time\n\n\nversion = os.getenv(\"this_version\", \"master\")\nstatic_url_path = \"/\" + version + \"/static\"\napp = flask.Flask(__name__, static_url_path=static_url_path)\nflask_bootstrap.Bootstrap(app)\ndb = redis.StrictRedis(host='redis', port=6379, db=0)\n\n\ndef render_flavor(flavor, template, data):\n    return flask.render_template(\n        os.path.join(flavor, template),\n        **data\n    )\n\n\n@app.add_template_global\ndef secret(length=16):\n    charset = string.ascii_uppercase + string.digits\n    return ''.join(\n        random.SystemRandom().choice(charset)\n        for _ in range(length)\n    )\n\n#Original copied from https://github.com/andrewlkho/ulagen\ndef random_ipv6_subnet():\n    eui64 = uuid.getnode() >> 24 << 48 | 0xfffe000000 | uuid.getnode() & 0xffffff\n    eui64_canon = \"-\".join([format(eui64, \"02X\")[i:i+2] for i in range(0, 18, 2)])\n\n    h = hashlib.sha1()\n    h.update((eui64_canon + str(time.time() - time.mktime((1900, 1, 1, 0, 0, 0, 0, 1, -1)))).encode('utf-8'))\n    globalid = h.hexdigest()[0:10]\n\n    prefix = \":\".join((\"fd\" + globalid[0:2], globalid[2:6], globalid[6:10]))\n    return prefix\n\ndef build_app(path):\n\n    app.jinja_env.trim_blocks = True\n    app.jinja_env.lstrip_blocks = True\n\n    @app.context_processor\n    def app_context():\n        return dict(\n            versions=os.getenv(\"VERSIONS\",\"master\").split(','),\n            stable_version = os.getenv(\"stable_version\", \"master\")\n        )\n\n    prefix_bp = flask.Blueprint(version.replace(\".\", \"_\"), __name__)\n    prefix_bp.jinja_loader = jinja2.ChoiceLoader([\n        jinja2.FileSystemLoader(os.path.join(path, \"templates\")),\n        jinja2.FileSystemLoader(os.path.join(path, \"flavors\"))\n    ])\n\n    root_bp = flask.Blueprint(\"root\", __name__)\n    root_bp.jinja_loader = jinja2.ChoiceLoader([\n        jinja2.FileSystemLoader(os.path.join(path, \"templates\")),\n        jinja2.FileSystemLoader(os.path.join(path, \"flavors\"))\n    ])\n\n    @prefix_bp.context_processor\n    @root_bp.context_processor\n    def bp_context(version=version):\n        return dict(version=version)\n\n    @prefix_bp.route(\"/\")\n    @root_bp.route(\"/\")\n    def wizard():\n        return flask.render_template('wizard.html')\n\n    @prefix_bp.route(\"/submit_flavor\", methods=[\"POST\"])\n    @root_bp.route(\"/submit_flavor\", methods=[\"POST\"])\n    def submit_flavor():\n        data = flask.request.form.copy()\n        subnet6 = random_ipv6_subnet()\n        steps = sorted(os.listdir(os.path.join(path, \"templates\", \"steps\", data[\"flavor\"])))\n        return flask.render_template('wizard.html', flavor=data[\"flavor\"], steps=steps, subnet6=subnet6)\n\n    @prefix_bp.route(\"/submit\", methods=[\"POST\"])\n    @root_bp.route(\"/submit\", methods=[\"POST\"])\n    def submit():\n        data = flask.request.form.copy()\n        data['uid'] = str(uuid.uuid4())\n        try:\n            data['dns'] = str(ipaddress.IPv4Network(data['subnet'], strict=False)[-2])\n        except ValueError as err:\n            return \"Error while generating files: \" + str(err)\n        db.set(data['uid'], json.dumps(data))\n        return flask.redirect(flask.url_for('.setup', uid=data['uid']))\n\n    @prefix_bp.route(\"/setup/<uid>\", methods=[\"GET\"])\n    @root_bp.route(\"/setup/<uid>\", methods=[\"GET\"])\n    def setup(uid):\n        data = json.loads(db.get(uid))\n        flavor = data.get(\"flavor\", \"compose\")\n        rendered = render_flavor(flavor, \"setup.html\", data)\n        return flask.render_template(\"setup.html\", contents=rendered)\n\n    @prefix_bp.route(\"/file/<uid>/<filepath>\", methods=[\"GET\"])\n    @root_bp.route(\"/file/<uid>/<filepath>\", methods=[\"GET\"])\n    def file(uid, filepath):\n        data = json.loads(db.get(uid))\n        flavor = data.get(\"flavor\", \"compose\")\n        return flask.Response(\n            render_flavor(flavor, filepath, data),\n            mimetype=\"application/text\"\n        )\n\n    app.register_blueprint(prefix_bp, url_prefix=\"/{}\".format(version))\n    app.register_blueprint(root_bp)\n\n\nif __name__ == \"__main__\":\n    build_app(\"/tmp/mailutest\")\n    app.run(debug=True)\n", "path": "setup/server.py"}]}