changeset 8366:0bf0045000b5

some modernization cleanups, forward compatibility
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Wed, 13 May 2009 14:08:39 +0200
parents 94e91205d9b6
children 7cf3d20f5967
files hgext/mq.py mercurial/byterange.py mercurial/commands.py mercurial/fancyopts.py mercurial/hook.py mercurial/merge.py mercurial/templater.py
diffstat 7 files changed, 13 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/mq.py	Tue May 12 10:03:36 2009 -0400
+++ b/hgext/mq.py	Wed May 13 14:08:39 2009 +0200
@@ -741,7 +741,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)
--- a/mercurial/byterange.py	Tue May 12 10:03:36 2009 -0400
+++ b/mercurial/byterange.py	Wed May 13 14:08:39 2009 +0200
@@ -23,7 +23,7 @@
 import stat
 import urllib
 import urllib2
-import rfc822
+import email.utils
 
 try:
     from cStringIO import StringIO
@@ -214,7 +214,7 @@
         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)
--- a/mercurial/commands.py	Tue May 12 10:03:36 2009 -0400
+++ b/mercurial/commands.py	Wed May 13 14:08:39 2009 +0200
@@ -1464,7 +1464,7 @@
         # description
         if not doc:
             doc = _("(no help text available)")
-        if callable(doc):
+        if hasattr(doc, '__call__'):
             doc = doc()
 
         ui.write("%s\n" % header)
--- a/mercurial/fancyopts.py	Tue May 12 10:03:36 2009 -0400
+++ b/mercurial/fancyopts.py	Wed May 13 14:08:39 2009 +0200
@@ -70,7 +70,7 @@
         # 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
--- a/mercurial/hook.py	Tue May 12 10:03:36 2009 -0400
+++ b/mercurial/hook.py	Wed May 13 14:08:39 2009 +0200
@@ -21,7 +21,7 @@
 
     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 @@
             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 @@
 
     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 @@
         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:
--- a/mercurial/merge.py	Tue May 12 10:03:36 2009 -0400
+++ b/mercurial/merge.py	Wed May 13 14:08:39 2009 +0200
@@ -263,16 +263,8 @@
 
     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 @@
     ms = mergestate(repo)
     ms.reset(wctx.parents()[0].node())
     moves = []
-    action.sort(actioncmp)
+    action.sort(key=actionkey)
 
     # prescan for merges
     for a in action:
--- a/mercurial/templater.py	Tue May 12 10:03:36 2009 -0400
+++ b/mercurial/templater.py	Wed May 13 14:08:39 2009 +0200
@@ -89,7 +89,7 @@
                 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__'):