Update of /cvsroot/mailman/mailman3/src/mailman/berkeleydb
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17799

Modified Files:
        bdbuser.py 
Log Message:
_inituids(), _create_user(): Fix these to maintain the invariant that internal
uids are packed long longs, while externally they are Python longs.

class User: Add rich comparisons for == and <> but raise TypeError for other
types of comparisons.


Index: bdbuser.py
===================================================================
RCS file: /cvsroot/mailman/mailman3/src/mailman/berkeleydb/bdbuser.py,v
retrieving revision 3.0
retrieving revision 3.1
diff -u -d -r3.0 -r3.1
--- bdbuser.py  29 Mar 2004 05:18:50 -0000      3.0
+++ bdbuser.py  30 Mar 2004 02:33:46 -0000      3.1
@@ -84,10 +84,10 @@
                 self._inituids()
         finally:
             self._uidlock.unlock()
-        
+
     def _inituids(self):
         # BAW: reserve uid 0 for 'something special'
-        self._metainfo.put('nextuid', pack('>Q', 1), txn=self.txn)
+        self._metainfo.put('nextuid', int2uid(1), txn=self.txn)
 
     _inituids = txnprop(_inituids)
 
@@ -111,15 +111,15 @@
         # unique.  To do this, we'll acquire a global file lock.
         self._uidlock.lock()
         try:
-            uid = self._metainfo.get('nextuid', txn=self.txn)
-            next = pack('>Q', unpack('>Q', uid)[0] + 1)
-            self._metainfo.put('nextuid', next, txn=self.txn)
+            nextuid = self._metainfo.get('nextuid', txn=self.txn)
+            uid = uid2int(nextuid)
+            self._metainfo.put('nextuid', int2uid(uid+1), txn=self.txn)
         finally:
             self._uidlock.unlock()
         utcnow = datetime.datetime.utcnow()
         data = cPickle.dumps(utcnow, cPickle.HIGHEST_PROTOCOL)
-        self._users.put(uid, data, txn=self.txn)
-        return User(self, uid)
+        self._users.put(nextuid, data, txn=self.txn)
+        return User(self, nextuid)
 
     create_user = txnprop(_create_user)
 
@@ -201,6 +201,7 @@
         raise AttributeError(obj)
 
 
+
 class User(object):
     __implements__ = IUser
 
@@ -208,6 +209,22 @@
         self._db = db
         self._uid = uid
 
+    # Only equality is supported for comparing users
+    def __eq__(self, other):
+        return self.uid == other.uid
+
+    def __ne__(self, other):
+        return self.uid <> other.uid
+
+    def __lt__(self, other):
+        raise TypeError('Not supported')
+
+    __gt__ = __lt__
+    __le__ = __lt__
+    __ge__ = __lt__
+
+    # Properties
+
     def _get_uid(self):
         return uid2int(self._uid)
 


_______________________________________________
Mailman-checkins mailing list
[EMAIL PROTECTED]
Unsubscribe: http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to