From patchwork Sat Apr 14 12:49:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [3,of,7] hgweb: lift {sessionvars} to a wrapped type From: Yuya Nishihara X-Patchwork-Id: 31023 Message-Id: To: mercurial-devel@mercurial-scm.org Date: Sat, 14 Apr 2018 21:49:13 +0900 # HG changeset patch # User Yuya Nishihara # Date 1522591957 -32400 # Sun Apr 01 23:12:37 2018 +0900 # Node ID b7742898a29d79f01beb36c1cedd58acfdab05ab # Parent 8bee5eca0b75333eee2c555663ae535005505991 hgweb: lift {sessionvars} to a wrapped type Since a sessionvars object is updated in-place, we can't simply wrap it by mappinglist. diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py --- a/mercurial/hgweb/webutil.py +++ b/mercurial/hgweb/webutil.py @@ -651,7 +651,7 @@ def diffstat(tmpl, ctx, statgen, parity) 'parity': next(parity), }) -class sessionvars(object): +class sessionvars(templateutil.wrapped): def __init__(self, vars, start='?'): self._start = start self._vars = vars @@ -665,7 +665,7 @@ class sessionvars(object): def __copy__(self): return sessionvars(copy.copy(self._vars), self._start) - def __iter__(self): + def itermaps(self, context): separator = self._start for key, value in sorted(self._vars.iteritems()): yield {'name': key, @@ -674,6 +674,16 @@ class sessionvars(object): } separator = '&' + def join(self, context, mapping, sep): + # could be '{separator}{name}={value|urlescape}' + raise error.ParseError(_('not displayable without template')) + + def show(self, context, mapping): + return self.join(context, '') + + def tovalue(self, context, mapping): + return self._vars + class wsgiui(uimod.ui): # default termwidth breaks under mod_wsgi def termwidth(self):