[PATCH 1 of 6 hglib] client: replace usage of namedtuple for python 2.4 compatibility

Idan Kamara idankk86 at gmail.com
Thu Dec 22 11:18:40 CST 2011


# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1324573959 -7200
# Node ID b894c2222dff30183d26388812a257c93e8f8a5a
# Parent  351d2799f145d19bb642e795f20786399fd02326
client: replace usage of namedtuple for python 2.4 compatibility

diff --git a/hglib/client.py b/hglib/client.py
--- a/hglib/client.py
+++ b/hglib/client.py
@@ -1,17 +1,42 @@
-import subprocess, os, struct, cStringIO, collections, re
+import subprocess, os, struct, cStringIO, re
 import hglib, error, util, templates, merge
 
 from util import cmdbuilder
 
+class revision(tuple):
+    def __new__(cls, rev, node, tags, branch, author, desc):
+        return tuple.__new__(cls, (rev, node, tags, branch, author, desc))
+
+    @property
+    def rev(self):
+       return self[0]
+
+    @property
+    def node(self):
+       return self[1]
+
+    @property
+    def tags(self):
+       return self[2]
+
+    @property
+    def branch(self):
+       return self[3]
+
+    @property
+    def author(self):
+       return self[4]
+
+    @property
+    def desc(self):
+       return self[5]
+
 class hgclient(object):
     inputfmt = '>I'
     outputfmt = '>cI'
     outputfmtsize = struct.calcsize(outputfmt)
     retfmt = '>i'
 
-    revision = collections.namedtuple('revision', 'rev, node, tags, '
-                                                  'branch, author, desc')
-
     def __init__(self, path, encoding, configs):
         args = [hglib.HGPATH, 'serve', '--cmdserver', 'pipe',
                 '--config', 'ui.interactive=True']
@@ -68,7 +93,7 @@
     def _parserevs(self, splitted):
         ''' splitted is a list of fields according to our rev.style, where each 6
         fields compose one revision. '''
-        return [self.revision._make(rev) for rev in util.grouper(6, splitted)]
+        return [revision(*rev) for rev in util.grouper(6, splitted)]
 
     def runcommand(self, args, inchannels, outchannels):
         def writeblock(data):


More information about the Mercurial-devel mailing list