cmdutil: use safehasattr instead of hasattr
authorAugie Fackler <durin42@gmail.com>
Mon, 25 Jul 2011 15:32:42 -0500
changeset 14948 32302480b402
parent 14947 3aa34005a73d
child 14949 a4435770cf57
cmdutil: use safehasattr instead of hasattr
mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Mon Jul 25 15:09:17 2011 -0500
+++ b/mercurial/cmdutil.py	Mon Jul 25 15:32:42 2011 -0500
@@ -161,7 +161,7 @@
 
     if not pat or pat == '-':
         fp = writable and repo.ui.fout or repo.ui.fin
-        if hasattr(fp, 'fileno'):
+        if util.safehasattr(fp, 'fileno'):
             return os.fdopen(os.dup(fp.fileno()), mode)
         else:
             # if this fp can't be duped properly, return
@@ -177,9 +177,9 @@
                         return getattr(self.f, attr)
 
             return wrappedfileobj(fp)
-    if hasattr(pat, 'write') and writable:
+    if util.safehasattr(pat, 'write') and writable:
         return pat
-    if hasattr(pat, 'read') and 'r' in mode:
+    if util.safehasattr(pat, 'read') and 'r' in mode:
         return pat
     return open(makefilename(repo, pat, node, total, seqno, revwidth,
                               pathname),
@@ -520,7 +520,7 @@
                              revwidth=revwidth, mode='ab')
             if fp != template:
                 shouldclose = True
-        if fp != sys.stdout and hasattr(fp, 'name'):
+        if fp != sys.stdout and util.safehasattr(fp, 'name'):
             repo.ui.note("%s\n" % fp.name)
 
         fp.write("# HG changeset patch\n")