Update of /cvsroot/mailman/mailman3/src/mailman/berkeleydb
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20100
Modified Files:
bdbuser.py
Log Message:
_init(): Add the revaddrs table for the reverse mapping of addresses to
userid+label keys.
Also, since the user ids will always be 8 bytes and may have null characters
in it, we use a different method for combining uids and labels. Now we just
concatenate them and split the first 8 bytes off for the uid, while the rest
is the label.
find_address(): Add an implementation of this method.
_get_labels(): We don't need to wrap the cursor set_range() call in a
try/except because of the new setting for set_get_returns_none() in the base
class.
Address class: Added rich comparisons (of which == and <> are the only
implementations that don't raise TypeError).
Index: bdbuser.py
===================================================================
RCS file: /cvsroot/mailman/mailman3/src/mailman/berkeleydb/bdbuser.py,v
retrieving revision 3.2
retrieving revision 3.3
diff -u -d -r3.2 -r3.3
--- bdbuser.py 6 Apr 2004 03:16:29 -0000 3.2
+++ bdbuser.py 7 Apr 2004 03:21:36 -0000 3.3
@@ -61,16 +61,19 @@
# passwords -- {userid -> password}
# Maps user ids to that person's hashed passwords.
#
- # addresses -- {userid\0label -> address}
+ # addresses -- {userid+label -> address}
# Maps userid/label keys to email addresses
#
- # realnames -- {userid\0label -> realname}
+ # revaddrs -- {address -> userid+label}
+ # Reverse mapping of email addresses to userid/labels
+ #
+ # realnames -- {userid+label -> realname}
# Maps userid/label keys to real names
#
# userprofiles -- {userid -> profiledata}
# Maps user ids to profile ids
#
- # addrprofiles -- {userid\0label -> profiledata}
+ # addrprofiles -- {userid+label -> profiledata}
# Maps userid/label keys to profile ids
__implements__ = BerkeleyDB.__implements__ + (IUserStorage,)
@@ -81,6 +84,7 @@
self._users = self._mktable('users')
self._passwords = self._mktable('passwords')
self._addresses = self._mktable('addresses')
+ self._revaddrs = self._mktable('revaddrs')
self._realnames = self._mktable('realnames')
self._userprofiles = self._mktable('userprofiles')
self._addrprofiles = self._mktable('addrprofiles')
@@ -105,20 +109,28 @@
_initpids = txnprop(_initpids)
# IUserStorage
+ #
+ # BAW: We're ignoing the domain since that's only useful when there are
+ # multiple backends, and here, all domains are stored in the same storage.
def _get_user(self, uid, domain):
- # BAW: we ignore the domain because that's only useful when there are
- # multiple backends.
- #
# The keys are always utf-8 encoded because the bsddb module does not
# allow unicode keys.
suid = int2uid(uid)
if self._users.get(suid, _missing, txn=self.txn) is _missing:
raise errors.NoUserError(uid)
return User(self, suid)
-
get_user = txnprop(_get_user)
+ def _find_address(self, address, domain):
+ key = self._revaddrs.get(address, txn=self.txn)
+ if key is None:
+ return None
+ uid = key[:8]
+ label = key[8:]
+ return Address(self, uid, label)
+ find_address = txnprop(_find_address)
+
def _create_user(self, domain):
# We need to calculate a new user id that's guaranteed to be
# unique. To do this, we'll acquire a global file lock.
@@ -133,7 +145,6 @@
data = cPickle.dumps(utcnow, cPickle.HIGHEST_PROTOCOL)
self._users.put(nextuid, data, txn=self.txn)
return User(self, nextuid)
-
create_user = txnprop(_create_user)
def create_profile(self, domain):
@@ -152,32 +163,35 @@
def _get_address(self, uid, label):
# labels may be unicodes
enc = label.encode('utf-8')
- key = '%s\0%s' % (uid, enc)
+ key = uid + enc
return self._addresses.get(key, txn=self.txn)
get_address = txnprop(_get_address)
def _add_address(self, uid, label, address):
enc = label.encode('utf-8')
- key = '%s\0%s' % (uid, enc)
+ key = uid + enc
self._addresses.put(key, address, txn=self.txn)
+ self._revaddrs.put(address, key, txn=self.txn)
add_address = txnprop(_add_address)
def _delete_address(self, uid, label):
enc = label.encode('utf-8')
- key = '%s\0%s' % (uid, enc)
+ key = uid + enc
+ addr = self._address.get(key, txn=self.txn)
self._addresses.delete(key, txn=self.txn)
+ self._revaddrs.delete(addr, txn=self.txn)
delete_address = txnprop(_delete_address)
def _get_realname(self, uid, label):
# labels may be unicodes
enc = label.encode('utf-8')
- key = '%s\0%s' % (uid, enc)
+ key = uid + enc
return self._realnames.get(key, txn=self.txn)
get_realname = txnprop(_get_realname)
def _set_realname(self, uid, label, realname):
enc = label.encode('utf-8')
- key = '%s\0%s' % (uid, enc)
+ key = uid + enc
self._realnames.put(key, realname, txn=self.txn)
set_realname = txnprop(_set_realname)
@@ -186,14 +200,12 @@
labels = []
c = self._addresses.cursor(txn=self.txn)
try:
- try:
- rec = c.set_range(uid)
- except db.DBNotFoundError:
- rec = None
+ rec = c.set_range(uid)
while rec:
key, val = rec
rec = c.next()
- kuid, label = key.split('\0', 1)
+ kuid = key[:8]
+ label = key[8:]
if kuid <> uid:
break
labels.append(label)
@@ -221,7 +233,7 @@
del_user_profile = txnprop(_del_user_profile)
def _get_addr_profile(self, uid, label):
- key = '%s\0%s' % (uid, label)
+ key = uid + label
data = self._addrprofiles.get(key, txn=self.txn)
if data is None:
return None
@@ -229,13 +241,13 @@
get_addr_profile = txnprop(_get_addr_profile)
def _set_addr_profile(self, uid, label, profile):
- key = '%s\0%s' % (uid, label)
+ key = uid + label
data = cPickle.dumps(profile, cPickle.HIGHEST_PROTOCOL)
self._addrprofiles.put(key, data, txn=self.txn)
set_addr_profile = txnprop(_set_addr_profile)
def _del_addr_profile(self, uid, label):
- key = '%s\0%s' % (uid, label)
+ key = uid + label
self._addrprofiles.delete(key, txn=self.txn)
del_addr_profile = txnprop(_del_addr_profile)
@@ -265,10 +277,10 @@
# Only equality is supported for comparing users
def __eq__(self, other):
- return self.uid == other.uid
+ return self._uid == other._uid
def __ne__(self, other):
- return self.uid <> other.uid
+ return self._uid <> other._uid
def __lt__(self, other):
raise TypeError('Not supported')
@@ -337,6 +349,20 @@
self._uid = uid
self._label = label
+ # Only equality is supported for comparing users
+ def __eq__(self, other):
+ return self._uid == other._uid and self._label == other._label
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __lt__(self, other):
+ raise TypeError('Not supported')
+
+ __gt__ = __lt__
+ __le__ = __lt__
+ __ge__ = __lt__
+
def _get_user(self):
return User(self._db, self._uid)
_______________________________________________
Mailman-checkins mailing list
[EMAIL PROTECTED]
Unsubscribe: http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org