# HG changeset patch # User Augie Fackler # Date 1507228153 14400 # Node ID 8afc25e7effc71241f53bf709c24c72bfae0f6b6 # Parent 528b21b853aa95ecb1dbdb46059b18740a4853ba hgweb: extract function for loading style from request context Also make it work on Python 3. Differential Revision: https://phab.mercurial-scm.org/D970 diff -r 528b21b853aa -r 8afc25e7effc mercurial/hgweb/hgweb_mod.py --- a/mercurial/hgweb/hgweb_mod.py Thu Oct 05 14:27:21 2017 -0400 +++ b/mercurial/hgweb/hgweb_mod.py Thu Oct 05 14:29:13 2017 -0400 @@ -30,6 +30,7 @@ hg, hook, profiling, + pycompat, repoview, templatefilters, templater, @@ -60,6 +61,17 @@ ('bz2', ('application/x-bzip2', 'tbz2', '.tar.bz2', None)), )) +def getstyle(req, configfn, templatepath): + fromreq = req.form.get('style', [None])[0] + if fromreq is not None: + fromreq = pycompat.sysbytes(fromreq) + styles = ( + fromreq, + configfn('web', 'style'), + 'paper', + ) + return styles, templater.stylemap(styles, templatepath) + def makebreadcrumb(url, prefix=''): '''Return a 'URL breadcrumb' list @@ -170,12 +182,8 @@ # figure out which style to use vars = {} - styles = ( - req.form.get('style', [None])[0], - self.config('web', 'style'), - 'paper', - ) - style, mapfile = templater.stylemap(styles, self.templatepath) + styles, (style, mapfile) = getstyle(req, self.config, + self.templatepath) if style == styles[0]: vars['style'] = style diff -r 528b21b853aa -r 8afc25e7effc mercurial/hgweb/hgwebdir_mod.py --- a/mercurial/hgweb/hgwebdir_mod.py Thu Oct 05 14:27:21 2017 -0400 +++ b/mercurial/hgweb/hgwebdir_mod.py Thu Oct 05 14:29:13 2017 -0400 @@ -503,12 +503,8 @@ url += '/' vars = {} - styles = ( - req.form.get('style', [None])[0], - config('web', 'style'), - 'paper' - ) - style, mapfile = templater.stylemap(styles, self.templatepath) + styles, (style, mapfile) = hgweb_mod.getstyle(req, config, + self.templatepath) if style == styles[0]: vars['style'] = style