Mercurial > evolve
changeset 3508:0b3ab8b6f39d
compat: only wrap wireprotoserver function if they exist
Older version does not need the wrapping so everything should be fine.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 02 Mar 2018 16:30:48 -0500 |
parents | 6b4272bbb65d |
children | 174d966e1eaa |
files | hgext3rd/evolve/obsexchange.py |
diffstat | 1 files changed, 24 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext3rd/evolve/obsexchange.py Mon Feb 26 13:59:30 2018 +0100 +++ b/hgext3rd/evolve/obsexchange.py Fri Mar 02 16:30:48 2018 -0500 @@ -25,9 +25,14 @@ pushkey, util, wireproto, - wireprotoserver, ) +try: + from mercurial import wireprotoserver + wireprotoserver.parsehttprequest +except ImportError: + wireprotoserver = None + from mercurial.hgweb import common as hgwebcommon from . import ( @@ -231,25 +236,26 @@ raise err return {} -# reinstall dispatch catching ResponseError as in hg 4.5 < -@eh.wrapfunction(wireprotoserver, 'parsehttprequest') -def parsehttprequest(orig, repo, req, query): - protohandler = orig(repo, req, query) - olddispatch = protohandler['dispatch'] +if wireprotoserver is not None: + # reinstall dispatch catching ResponseError as in hg 4.5 < + @eh.wrapfunction(wireprotoserver, 'parsehttprequest') + def parsehttprequest(orig, repo, req, query): + protohandler = orig(repo, req, query) + olddispatch = protohandler['dispatch'] - def newdispatch(): - try: - return olddispatch() - except hgwebcommon.ErrorResponse as inst: - if protohandler['cmd'] != 'listkeys': - raise - req.headers.append((r'Connection', r'Close')) - req.respond(inst, wireprotoserver.HGTYPE, - body='0\n%s\n' % inst) - return '' + def newdispatch(): + try: + return olddispatch() + except hgwebcommon.ErrorResponse as inst: + if protohandler['cmd'] != 'listkeys': + raise + req.headers.append((r'Connection', r'Close')) + req.respond(inst, wireprotoserver.HGTYPE, + body='0\n%s\n' % inst) + return '' - protohandler['dispatch'] = newdispatch - return protohandler + protohandler['dispatch'] = newdispatch + return protohandler @eh.uisetup def setuppushkeyforbidding(ui):