# HG changeset patch # User Pierre-Yves David # Date 1520026248 18000 # Node ID 0b3ab8b6f39d92a638d5058945424907d8661f78 # Parent 6b4272bbb65d08066455329938bc224577ea2f52 compat: only wrap wireprotoserver function if they exist Older version does not need the wrapping so everything should be fine. diff -r 6b4272bbb65d -r 0b3ab8b6f39d hgext3rd/evolve/obsexchange.py --- 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):