equal
deleted
inserted
replaced
65 except ImportError: |
65 except ImportError: |
66 pass |
66 pass |
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+ |
76 queue = pycompat.queue.Queue |
78 queue = pycompat.queue.Queue |
77 except (AttributeError, ImportError): |
79 except (AttributeError, ImportError): |
93 # for "historical portability": |
95 # for "historical portability": |
94 # define util.safehasattr forcibly, because util.safehasattr has been |
96 # define util.safehasattr forcibly, because util.safehasattr has been |
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": |
102 # define util.timer forcibly, because util.timer has been available |
104 # define util.timer forcibly, because util.timer has been available |
103 # since ae5d60bb70c9 |
105 # since ae5d60bb70c9 |
338 if ignoremissing: |
340 if ignoremissing: |
339 return None |
341 return None |
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 |
352 # utilities to examine each internal API changes |
354 # utilities to examine each internal API changes |
353 |
355 |