comparison mercurial/dispatch.py @ 14950:144e97421f6b

dispatch: use safehasattr instead of hasattr
author Augie Fackler <durin42@gmail.com>
date Mon, 25 Jul 2011 15:17:47 -0500
parents ebdfdba0faaf
children f6a737357195
comparison
equal deleted inserted replaced
14949:a4435770cf57 14950:144e97421f6b
157 if m in "mpatch bdiff".split(): 157 if m in "mpatch bdiff".split():
158 ui.warn(_("(did you forget to compile extensions?)\n")) 158 ui.warn(_("(did you forget to compile extensions?)\n"))
159 elif m in "zlib".split(): 159 elif m in "zlib".split():
160 ui.warn(_("(is your Python install correct?)\n")) 160 ui.warn(_("(is your Python install correct?)\n"))
161 except IOError, inst: 161 except IOError, inst:
162 if hasattr(inst, "code"): 162 if util.safehasattr(inst, "code"):
163 ui.warn(_("abort: %s\n") % inst) 163 ui.warn(_("abort: %s\n") % inst)
164 elif hasattr(inst, "reason"): 164 elif util.safehasattr(inst, "reason"):
165 try: # usually it is in the form (errno, strerror) 165 try: # usually it is in the form (errno, strerror)
166 reason = inst.reason.args[1] 166 reason = inst.reason.args[1]
167 except (AttributeError, IndexError): 167 except (AttributeError, IndexError):
168 # it might be anything, for example a string 168 # it might be anything, for example a string
169 reason = inst.reason 169 reason = inst.reason
170 ui.warn(_("abort: error: %s\n") % reason) 170 ui.warn(_("abort: error: %s\n") % reason)
171 elif hasattr(inst, "args") and inst.args[0] == errno.EPIPE: 171 elif util.safehasattr(inst, "args") and inst.args[0] == errno.EPIPE:
172 if ui.debugflag: 172 if ui.debugflag:
173 ui.warn(_("broken pipe\n")) 173 ui.warn(_("broken pipe\n"))
174 elif getattr(inst, "strerror", None): 174 elif getattr(inst, "strerror", None):
175 if getattr(inst, "filename", None): 175 if getattr(inst, "filename", None):
176 ui.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) 176 ui.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename))
336 def __call__(self, ui, *args, **opts): 336 def __call__(self, ui, *args, **opts):
337 if self.shadows: 337 if self.shadows:
338 ui.debug("alias '%s' shadows command '%s'\n" % 338 ui.debug("alias '%s' shadows command '%s'\n" %
339 (self.name, self.cmdname)) 339 (self.name, self.cmdname))
340 340
341 if hasattr(self, 'shell'): 341 if util.safehasattr(self, 'shell'):
342 return self.fn(ui, *args, **opts) 342 return self.fn(ui, *args, **opts)
343 else: 343 else:
344 try: 344 try:
345 util.checksignature(self.fn)(ui, *args, **opts) 345 util.checksignature(self.fn)(ui, *args, **opts)
346 except error.SignatureError: 346 except error.SignatureError:
504 return 504 return
505 505
506 cmd = aliases[0] 506 cmd = aliases[0]
507 fn = entry[0] 507 fn = entry[0]
508 508
509 if cmd and hasattr(fn, 'shell'): 509 if cmd and util.safehasattr(fn, 'shell'):
510 d = lambda: fn(ui, *args[1:]) 510 d = lambda: fn(ui, *args[1:])
511 return lambda: runcommand(lui, None, cmd, args[:1], ui, options, d, [], {}) 511 return lambda: runcommand(lui, None, cmd, args[:1], ui, options, d, [], {})
512 512
513 commands.norepo = norepo 513 commands.norepo = norepo
514 514