# HG changeset patch # User Augie Fackler # Date 2011-07-25 21:04:40 # Node ID b7dbe957585c6fd2b84c7ac5d1e45f675af4b48f # Parent 376091a4ad23c658cb2ae8b5b85bd16fbbfe68a6 util: use safehasattr or getattr instead of hasattr diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -358,8 +358,8 @@ def mainfrozen(): The code supports py2exe (most common, Windows only) and tools/freeze (portable, not much used). """ - return (hasattr(sys, "frozen") or # new py2exe - hasattr(sys, "importers") or # old py2exe + return (safehasattr(sys, "frozen") or # new py2exe + safehasattr(sys, "importers") or # old py2exe imp.is_frozen("__main__")) # tools/freeze def hgexecutable(): @@ -783,7 +783,7 @@ class atomictempfile(object): self._fp.close() def __del__(self): - if hasattr(self, '_fp'): # constructor actually did something + if safehasattr(self, '_fp'): # constructor actually did something self.close() def makedirs(name, mode=None): @@ -1254,8 +1254,9 @@ def rundetached(args, condfn): def handler(signum, frame): terminated.add(os.wait()) prevhandler = None - if hasattr(signal, 'SIGCHLD'): - prevhandler = signal.signal(signal.SIGCHLD, handler) + SIGCHLD = getattr(signal, 'SIGCHLD', None) + if SIGCHLD is not None: + prevhandler = signal.signal(SIGCHLD, handler) try: pid = spawndetached(args) while not condfn():