# HG changeset patch # User Pierre-Yves David # Date 2023-12-19 20:38:46 # Node ID 3972d090aba28cfc75ca7db3d25b8a8669cc7e15 # Parent 011eec5a66b2de085b74c346ac8b7b0dc63e75fe 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. diff --git a/mercurial/hgweb/hgwebdir_mod.py b/mercurial/hgweb/hgwebdir_mod.py --- a/mercurial/hgweb/hgwebdir_mod.py +++ b/mercurial/hgweb/hgwebdir_mod.py @@ -410,15 +410,15 @@ class hgwebdir: 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.