prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Document the new setup utility
  Title says all
  
  --- 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 
  13 
  14 version = os.getenv("this_version")
  15 static_url_path = "/" + version + "/static"
  16 app = flask.Flask(__name__, static_url_path=static_url_path)
  17 flask_bootstrap.Bootstrap(app)
  18 db = redis.StrictRedis(host='redis', port=6379, db=0)
  19 
  20 
  21 def render_flavor(flavor, template, data):
  22     return flask.render_template(
  23         os.path.join(flavor, template),
  24         **data
  25     )
  26 
  27 
  28 @app.add_template_global
  29 def secret(length=16):
  30     charset = string.ascii_uppercase + string.digits
  31     return ''.join(
  32         random.SystemRandom().choice(charset)
  33         for _ in range(length)
  34     )
  35 
  36 
  37 def build_app(path):
  38 
  39     app.jinja_env.trim_blocks = True
  40     app.jinja_env.lstrip_blocks = True
  41 
  42     @app.context_processor
  43     def app_context():
  44         return dict(versions=os.getenv("VERSIONS","master").split(','))
  45 
  46     prefix_bp = flask.Blueprint(version, __name__)
  47     prefix_bp.jinja_loader = jinja2.ChoiceLoader([
  48         jinja2.FileSystemLoader(os.path.join(path, "templates")),
  49         jinja2.FileSystemLoader(os.path.join(path, "flavors"))
  50     ])
  51 
  52     root_bp = flask.Blueprint("root", __name__)
  53     root_bp.jinja_loader = jinja2.ChoiceLoader([
  54         jinja2.FileSystemLoader(os.path.join(path, "templates")),
  55         jinja2.FileSystemLoader(os.path.join(path, "flavors"))
  56     ])
  57 
  58     @prefix_bp.context_processor
  59     @root_bp.context_processor
  60     def bp_context(version=version):
  61         return dict(version=version)
  62 
  63     @prefix_bp.route("/")
  64     @root_bp.route("/")
  65     def wizard():
  66         return flask.render_template('wizard.html')
  67 
  68     @prefix_bp.route("/submit_flavor", methods=["POST"])
  69     @root_bp.route("/submit_flavor", methods=["POST"])
  70     def submit_flavor():
  71         data = flask.request.form.copy()
  72         steps = sorted(os.listdir(os.path.join(path, "templates", "steps", data["flavor"])))
  73         return flask.render_template('wizard.html', flavor=data["flavor"], steps=steps)
  74 
  75     @prefix_bp.route("/submit", methods=["POST"])
  76     @root_bp.route("/submit", methods=["POST"])
  77     def submit():
  78         data = flask.request.form.copy()
  79         data['uid'] = str(uuid.uuid4())
  80         data['dns'] = str(ipaddress.IPv4Network(data['subnet'])[-2])
  81         db.set(data['uid'], json.dumps(data))
  82         return flask.redirect(flask.url_for('.setup', uid=data['uid']))
  83 
  84     @prefix_bp.route("/setup/<uid>", methods=["GET"])
  85     @root_bp.route("/setup/<uid>", methods=["GET"])
  86     def setup(uid):
  87         data = json.loads(db.get(uid))
  88         flavor = data.get("flavor", "compose")
  89         rendered = render_flavor(flavor, "setup.html", data)
  90         return flask.render_template("setup.html", contents=rendered)
  91 
  92     @prefix_bp.route("/file/<uid>/<filepath>", methods=["GET"])
  93     @root_bp.route("/file/<uid>/<filepath>", methods=["GET"])
  94     def file(uid, filepath):
  95         data = json.loads(db.get(uid))
  96         flavor = data.get("flavor", "compose")
  97         return flask.Response(
  98             render_flavor(flavor, filepath, data),
  99             mimetype="application/text"
  100         )
  101 
  102     app.register_blueprint(prefix_bp, url_prefix="/{}".format(version))
  103     app.register_blueprint(root_bp)
  104 
  105 
  106 if __name__ == "__main__":
  107     build_app("/tmp/mailutest")
  108     app.run(debug=True)
  109
  ```
  --- 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
  @@ -11,7 +11,7 @@
   import hashlib
   
   
  -version = os.getenv("this_version")
  +version = os.getenv("this_version", "master")
   static_url_path = "/" + version + "/static"
   app = flask.Flask(__name__, static_url_path=static_url_path)
   flask_bootstrap.Bootstrap(app)
  
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@@ -11,7 +11,7 @@\n import hashlib\n \n \n-version = os.getenv(\"this_version\")\n+version = os.getenv(\"this_version\", \"master\")\n static_url_path = \"/\" + version + \"/static\"\n app = flask.Flask(__name__, static_url_path=static_url_path)\n flask_bootstrap.Bootstrap(app)\n", "issue": "Document the new setup utility\nTitle says all\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\n\n\nversion = os.getenv(\"this_version\")\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\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(versions=os.getenv(\"VERSIONS\",\"master\").split(','))\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        steps = sorted(os.listdir(os.path.join(path, \"templates\", \"steps\", data[\"flavor\"])))\n        return flask.render_template('wizard.html', flavor=data[\"flavor\"], steps=steps)\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        data['dns'] = str(ipaddress.IPv4Network(data['subnet'])[-2])\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\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\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(versions=os.getenv(\"VERSIONS\",\"master\").split(','))\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        steps = sorted(os.listdir(os.path.join(path, \"templates\", \"steps\", data[\"flavor\"])))\n        return flask.render_template('wizard.html', flavor=data[\"flavor\"], steps=steps)\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        data['dns'] = str(ipaddress.IPv4Network(data['subnet'])[-2])\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"}]}