configwizard: implement safehasattr (
bug 1282293); r?glob
util.safehasattr was added in hg 2.0. We implement our own
safehasattr() so the extension can load on hg 1.9.
MozReview-Commit-ID: KnQSC2hOT2m
--- a/hgext/configwizard/__init__.py
+++ b/hgext/configwizard/__init__.py
@@ -840,19 +840,25 @@ class configobjwrapper(object):
lines = self.c.write()
for line in lines:
if line.startswith('#%s ' % self._random):
line = line[2 + len(self._random):]
fh.write('%s\n' % line)
+# Ancient versions of Mercurial lack util.safehasattr(). So implement it here.
+_notset = object()
+def safehasattr(thing, attr):
+ return getattr(thing, attr, _notset) is not _notset
+
+
def uisetup(ui):
# hasconfig() was added in 3.7. Backport until we require 3.7.
- if util.safehasattr(ui, 'hasconfig'):
+ if safehasattr(ui, 'hasconfig'):
return
class configui(ui.__class__):
def hasconfig(self, section, name, untrusted=False):
return name in self._data(untrusted)._data.get(section, {})
ui.__class__ = configui
uimod.ui = configui
@@ -881,10 +887,10 @@ def extsetup(ui):
if n == 2:
return (vints[0], vints[1])
if n == 3:
return (vints[0], vints[1], vints[2])
if n == 4:
return (vints[0], vints[1], vints[2], extra)
- if not util.safehasattr(util, 'versiontuple'):
+ if not safehasattr(util, 'versiontuple'):
util.versiontuple = versiontuple