hgweb: update _runwsgi try/except range to be valid
The `tmpl` variable is used in the `except` and `finally`, so we need it created
before the `try` is open.
--- a/mercurial/hgweb/hgwebdir_mod.py Tue Dec 19 21:36:52 2023 +0100
+++ b/mercurial/hgweb/hgwebdir_mod.py Tue Dec 19 21:38:46 2023 +0100
@@ -410,15 +410,15 @@
gc.collect(generation=1)
def _runwsgi(self, req, res):
- try:
- self.refresh()
+ self.refresh()
- csp, nonce = cspvalues(self.ui)
- if csp:
- res.headers[b'Content-Security-Policy'] = csp
+ csp, nonce = cspvalues(self.ui)
+ if csp:
+ res.headers[b'Content-Security-Policy'] = csp
- virtual = req.dispatchpath.strip(b'/')
- tmpl = self.templater(req, nonce)
+ virtual = req.dispatchpath.strip(b'/')
+ tmpl = self.templater(req, nonce)
+ try:
ctype = tmpl.render(b'mimetype', {b'encoding': encoding.encoding})
# Global defaults. These can be overridden by any handler.