[27275] in Source-Commits

home help back first fref pref prev next nref lref last post

python-discuss commit: Make transactions sortable

daemon@ATHENA.MIT.EDU (Victor Vasiliev)
Sat Sep 14 22:38:20 2013

Date: Sat, 14 Sep 2013 22:38:12 -0400
From: Victor Vasiliev <vasilvv@MIT.EDU>
Message-Id: <201309150238.r8F2cCHH022668@drugstore.mit.edu>
To: source-commits@MIT.EDU

https://github.com/mit-athena/python-discuss/commit/6c459eeb3db865b2c565a25e2097ec56ba534335
commit 6c459eeb3db865b2c565a25e2097ec56ba534335
Author: Victor Vasiliev <vasilvv@mit.edu>
Date:   Sat Sep 14 20:49:06 2013 -0400

    Make transactions sortable

 discuss/client.py |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/discuss/client.py b/discuss/client.py
index 676e67a..ab1f434 100644
--- a/discuss/client.py
+++ b/discuss/client.py
@@ -8,7 +8,7 @@
 from .rpc import USPBlock, RPCClient, ProtocolError
 from . import constants
 
-from functools import wraps
+from functools import total_ordering, wraps
 import datetime
 import socket
 
@@ -312,6 +312,7 @@ class Meeting(object):
         if result != 0:
             raise DiscussError(result)
 
+@total_ordering
 class Transaction(object):
     """Discuss transaction. Returned by methods of the meeting object."""
 
@@ -352,3 +353,12 @@ class Transaction(object):
         result = reply.read_long_integer()
         if result != 0:
             raise DiscussError(result)
+
+    def __le__(self, other):
+        return self.number < other.number
+
+    def __eq__(self, other):
+        if isinstance(other, Transaction):
+            return self.number == other.number and self.meeting.name == other.meeting.name
+        else:
+            return False

home help back first fref pref prev next nref lref last post