compat: only wrap wireprotoserver function if they exist
Older version does not need the wrapping so everything should be fine.
--- 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):