##// END OF EJS Templates
py3: handle sysstr conversion around get/set attr in contrib/perf
Matt Harbison -
r39846:6787dc1b default
parent child Browse files
Show More
@@ -67,9 +67,11 b' except ImportError:'
67 try:
67 try:
68 from mercurial import pycompat
68 from mercurial import pycompat
69 getargspec = pycompat.getargspec # added to module after 4.5
69 getargspec = pycompat.getargspec # added to module after 4.5
70 _sysstr = pycompat.sysstr # since 4.0 (or 2219f4f82ede)
70 except (ImportError, AttributeError):
71 except (ImportError, AttributeError):
71 import inspect
72 import inspect
72 getargspec = inspect.getargspec
73 getargspec = inspect.getargspec
74 _sysstr = lambda x: x # no py3 support
73
75
74 try:
76 try:
75 # 4.7+
77 # 4.7+
@@ -95,7 +97,7 b' except (AttributeError, ImportError):'
95 # available since 1.9.3 (or 94b200a11cf7)
97 # available since 1.9.3 (or 94b200a11cf7)
96 _undefined = object()
98 _undefined = object()
97 def safehasattr(thing, attr):
99 def safehasattr(thing, attr):
98 return getattr(thing, attr, _undefined) is not _undefined
100 return getattr(thing, _sysstr(attr), _undefined) is not _undefined
99 setattr(util, 'safehasattr', safehasattr)
101 setattr(util, 'safehasattr', safehasattr)
100
102
101 # for "historical portability":
103 # for "historical portability":
@@ -340,12 +342,12 b' def safeattrsetter(obj, name, ignoremiss'
340 raise error.Abort((b"missing attribute %s of %s might break assumption"
342 raise error.Abort((b"missing attribute %s of %s might break assumption"
341 b" of performance measurement") % (name, obj))
343 b" of performance measurement") % (name, obj))
342
344
343 origvalue = getattr(obj, name)
345 origvalue = getattr(obj, _sysstr(name))
344 class attrutil(object):
346 class attrutil(object):
345 def set(self, newvalue):
347 def set(self, newvalue):
346 setattr(obj, name, newvalue)
348 setattr(obj, _sysstr(name), newvalue)
347 def restore(self):
349 def restore(self):
348 setattr(obj, name, origvalue)
350 setattr(obj, _sysstr(name), origvalue)
349
351
350 return attrutil()
352 return attrutil()
351
353
General Comments 0
You need to be logged in to leave comments. Login now