diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -741,7 +741,7 @@ class queue: elif user: p.write("From: " + user + "\n\n") - if callable(msg): + if hasattr(msg, '__call__'): msg = msg() commitmsg = msg and msg or ("[mq]: %s" % patchfn) n = repo.commit(commitfiles, commitmsg, user, date, match=match, force=True) diff --git a/mercurial/byterange.py b/mercurial/byterange.py --- a/mercurial/byterange.py +++ b/mercurial/byterange.py @@ -23,7 +23,7 @@ import os import stat import urllib import urllib2 -import rfc822 +import email.utils try: from cStringIO import StringIO @@ -214,7 +214,7 @@ class FileRangeHandler(urllib2.FileHandl localfile = urllib.url2pathname(file) stats = os.stat(localfile) size = stats[stat.ST_SIZE] - modified = rfc822.formatdate(stats[stat.ST_MTIME]) + modified = email.utils.formatdate(stats[stat.ST_MTIME]) mtype = mimetypes.guess_type(file)[0] if host: host, port = urllib.splitport(host) diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -1464,7 +1464,7 @@ def help_(ui, name=None, with_version=Fa # description if not doc: doc = _("(no help text available)") - if callable(doc): + if hasattr(doc, '__call__'): doc = doc() ui.write("%s\n" % header) diff --git a/mercurial/fancyopts.py b/mercurial/fancyopts.py --- a/mercurial/fancyopts.py +++ b/mercurial/fancyopts.py @@ -70,7 +70,7 @@ def fancyopts(args, options, state, gnu= # copy defaults to state if isinstance(default, list): state[name] = default[:] - elif callable(default): + elif hasattr(default, '__call__'): state[name] = None else: state[name] = default diff --git a/mercurial/hook.py b/mercurial/hook.py --- a/mercurial/hook.py +++ b/mercurial/hook.py @@ -21,7 +21,7 @@ def _pythonhook(ui, repo, name, hname, f ui.note(_("calling hook %s: %s\n") % (hname, funcname)) obj = funcname - if not callable(obj): + if not hasattr(obj, '__call__'): d = funcname.rfind('.') if d == -1: raise util.Abort(_('%s hook is invalid ("%s" not in ' @@ -44,7 +44,7 @@ def _pythonhook(ui, repo, name, hname, f raise util.Abort(_('%s hook is invalid ' '("%s" is not defined)') % (hname, funcname)) - if not callable(obj): + if not hasattr(obj, '__call__'): raise util.Abort(_('%s hook is invalid ' '("%s" is not callable)') % (hname, funcname)) @@ -74,7 +74,7 @@ def _exthook(ui, repo, name, cmd, args, env = {} for k, v in args.iteritems(): - if callable(v): + if hasattr(v, '__call__'): v = v() env['HG_' + k.upper()] = v @@ -107,7 +107,7 @@ def hook(ui, repo, name, throw=False, ** for hname, cmd in ui.configitems('hooks'): if hname.split('.')[0] != name or not cmd: continue - if callable(cmd): + if hasattr(cmd, '__call__'): r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r elif cmd.startswith('python:'): if cmd.count(':') == 2: diff --git a/mercurial/merge.py b/mercurial/merge.py --- a/mercurial/merge.py +++ b/mercurial/merge.py @@ -263,16 +263,8 @@ def manifestmerge(repo, p1, p2, pa, over return action -def actioncmp(a1, a2): - m1 = a1[1] - m2 = a2[1] - if m1 == m2: - return cmp(a1, a2) - if m1 == 'r': - return -1 - if m2 == 'r': - return 1 - return cmp(a1, a2) +def actionkey(a): + return a[1] == 'r' and -1 or 0, a def applyupdates(repo, action, wctx, mctx): "apply the merge action list to the working directory" @@ -281,7 +273,7 @@ def applyupdates(repo, action, wctx, mct ms = mergestate(repo) ms.reset(wctx.parents()[0].node()) moves = [] - action.sort(actioncmp) + action.sort(key=actionkey) # prescan for merges for a in action: diff --git a/mercurial/templater.py b/mercurial/templater.py --- a/mercurial/templater.py +++ b/mercurial/templater.py @@ -89,7 +89,7 @@ class engine(object): v = map[key] else: v = self.defaults.get(key, "") - if callable(v): + if hasattr(v, '__call__'): v = v(**map) if format: if not hasattr(v, '__iter__'):