Commits

Dirkjan Ochtman  committed 0bf0045

some modernization cleanups, forward compatibility

  • Participants
  • Parent commits 94e9120

Comments (0)

Files changed (7)

                 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)

File mercurial/byterange.py

 import stat
 import urllib
 import urllib2
-import rfc822
+import email.utils
 
 try:
     from cStringIO import StringIO
         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)

File mercurial/commands.py

         # description
         if not doc:
             doc = _("(no help text available)")
-        if callable(doc):
+        if hasattr(doc, '__call__'):
             doc = doc()
 
         ui.write("%s\n" % header)

File mercurial/fancyopts.py

         # 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

File mercurial/hook.py

 
     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 '
             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))
 
     env = {}
     for k, v in args.iteritems():
-        if callable(v):
+        if hasattr(v, '__call__'):
             v = v()
         env['HG_' + k.upper()] = v
 
         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:

File mercurial/merge.py

 
     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"
     ms = mergestate(repo)
     ms.reset(wctx.parents()[0].node())
     moves = []
-    action.sort(actioncmp)
+    action.sort(key=actionkey)
 
     # prescan for merges
     for a in action:

File mercurial/templater.py

                 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__'):