1. Christian Ebert
  2. muttils

Commits

Christian Ebert  committed 3d69a1f

Provide safe hasattr() and use it in wget

  • Participants
  • Parent commits 77dd2e2
  • Branches default

Comments (0)

Files changed (2)

File muttils/util.py

View file
  • Ignore whitespace
 
 import os, subprocess, sys
 
+_notset = object()
+
+def safehasattr(thing, attr):
+    '''Deal with python compatibility problems of hasattr().
+    See: http://selenic.com/hg/rev/5a0fdc715769'''
+    return getattr(thing, attr, _notset) is not _notset
+
+
 class DeadMan(Exception):
     '''Exception class for muttils package.
     '''

File muttils/wget.py

View file
  • Ignore whitespace
             self.opener.addheaders = headers
 
     def wwarn(self, url, inst):
-        if hasattr(inst, 'reason'):
+        if util.safehasattr(inst, 'reason'):
             self.ui.warn('failed to reach a server for %s\n' % url,
                          'reason: %s\n' % inst)
         else:
                 raise util.DeadMan('%s: invalid request instruction')
             fp.close()
         except urllib2.URLError, inst:
-            if hasattr(inst, 'reason'):
+            if util.safehasattr(inst, 'reason'):
                 self.ui.warn('failed to reach a server for %s\n' % req,
                              'reason: %s\n' % inst)
             else: