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

Modified Files:
        bdbuser.py 
Log Message:
Profile support added


Index: bdbuser.py
===================================================================
RCS file: /cvsroot/mailman/mailman3/src/mailman/berkeleydb/bdbuser.py,v
retrieving revision 3.1
retrieving revision 3.2
diff -u -d -r3.1 -r3.2
--- bdbuser.py  30 Mar 2004 02:33:46 -0000      3.1
+++ bdbuser.py  6 Apr 2004 03:16:29 -0000       3.2
@@ -28,6 +28,7 @@
 from mailman.berkeleydb.txnprop import txnprop
 from mailman.config import configuration
 from mailman.dbmgr import dbmgr
+from mailman.interfaces import profile
 from mailman.interfaces.storages import IUserStorage
 from mailman.interfaces.user import IUser
 
@@ -65,6 +66,12 @@
     #
     # realnames -- {userid\0label -> realname}
     #     Maps userid/label keys to real names
+    #
+    # userprofiles -- {userid -> profiledata}
+    #     Maps user ids to profile ids
+    #
+    # addrprofiles -- {userid\0label -> profiledata}
+    #     Maps userid/label keys to profile ids
 
     __implements__ = BerkeleyDB.__implements__ + (IUserStorage,)
 
@@ -75,8 +82,11 @@
         self._passwords = self._mktable('passwords')
         self._addresses = self._mktable('addresses')
         self._realnames = self._mktable('realnames')
+        self._userprofiles = self._mktable('userprofiles')
+        self._addrprofiles = self._mktable('addrprofiles')
         self._uidlock = lockfile.LockFile(
             os.path.join(configuration.layout.lockdir, 'uid.lock'))
+        # Initialize the next user id
         self._uidlock.lock()
         try:
             nextuid = self._metainfo.get('nextuid')
@@ -88,9 +98,12 @@
     def _inituids(self):
         # BAW: reserve uid 0 for 'something special'
         self._metainfo.put('nextuid', int2uid(1), txn=self.txn)
-
     _inituids = txnprop(_inituids)
 
+    def _initpids(self):
+        self._metainfo.put('nextpid', int2uid(1), txn=self.txn)
+    _initpids = txnprop(_initpids)
+
     # IUserStorage
 
     def _get_user(self, uid, domain):
@@ -123,6 +136,9 @@
 
     create_user = txnprop(_create_user)
 
+    def create_profile(self, domain):
+        return _Profile()
+
     # User class helpers
 
     def _get_password(self, uid):
@@ -184,6 +200,44 @@
         finally:
             c.close()
         return labels
+    get_labels = txnprop(_get_labels)
+
+    # Profile helper functions
+
+    def _get_user_profile(self, uid):
+        data = self._userprofiles.get(uid, txn=self.txn)
+        if data is None:
+            return None
+        return cPickle.loads(data)
+    get_user_profile = txnprop(_get_user_profile)
+
+    def _set_user_profile(self, uid, profile):
+        data = cPickle.dumps(profile, cPickle.HIGHEST_PROTOCOL)
+        self._userprofiles.put(uid, data, txn=self.txn)
+    set_user_profile = txnprop(_set_user_profile)
+
+    def _del_user_profile(self, uid):
+        self._userprofiles.delete(uid, txn=self.txn)
+    del_user_profile = txnprop(_del_user_profile)
+
+    def _get_addr_profile(self, uid, label):
+        key = '%s\0%s' % (uid, label)
+        data = self._addrprofiles.get(key, txn=self.txn)
+        if data is None:
+            return None
+        return cPickle.loads(data)
+    get_addr_profile = txnprop(_get_addr_profile)
+
+    def _set_addr_profile(self, uid, label, profile):
+        key = '%s\0%s' % (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)
+        self._addrprofiles.delete(key, txn=self.txn)
+    del_addr_profile = txnprop(_del_addr_profile)
 
 
 
@@ -227,7 +281,6 @@
 
     def _get_uid(self):
         return uid2int(self._uid)
-
     uid = readonly(_get_uid)
 
     def _get_password(self):
@@ -265,6 +318,17 @@
 
     address = readonly(_addresses)
 
+    def _get_profile(self):
+        return self._db.get_user_profile(self._uid)
+
+    def _set_profile(self, profile):
+        self._db.set_user_profile(self._uid, profile)
+
+    def _del_profile(self):
+        self._db.del_user_profile(self._uid)
+
+    profile = property(_get_profile, _set_profile, _del_profile)
+
 
 
 class Address(object):
@@ -298,3 +362,54 @@
         self._db.set_realname(self._uid, self._label, realname)
 
     realname = property(_get_realname, _set_realname)
+
+    def _get_addr_profile(self):
+        return self._db.get_addr_profile(self._uid, self._label)
+
+    def _set_addr_profile(self, profile):
+        self._db.set_addr_profile(self._uid, self._label, profile)
+
+    def _del_addr_profile(self):
+        self._db.del_addr_profile(self._uid, self._label)
+
+    profile = property(_get_addr_profile, _set_addr_profile, _del_addr_profile)
+
+
+
+class _Profile(object):
+    __slots__ = ['status', 'mode', 'ownposts', 'ackposts',
+                 'duplicates', 'save_during_vacation',
+                 'vacation_return_date']
+
+    def __init__(self):
+        self.status = profile.DeliveryStatus.Enabled
+        self.mode = profile.DeliveryMode.Regular
+        self.ownposts = True
+        self.ackposts = False
+        self.duplicates = True
+        self.save_during_vacation = False
+        self.vacation_return_date = None
+
+
+class Profile(object):
+    def __init__(self, db, pid):
+        self._pid = pid
+        self._db = db
+
+    def __getattribute__(self, attr):
+        if attr.startswith('_'):
+            return super(Profile, self).__getattribute__(attr)
+        if attr == 'pid':
+            return uid2int(self._pid)
+        profile = self._db.get_profile(self._pid)
+        return getattr(profile, attr)
+
+    def __setattr__(self, attr, val):
+        if attr.startswith('_'):
+            super(Profile, self).__setattr__(attr, val)
+            return
+        if attr == 'pid':
+            raise AttributeError('pid is read-only')
+        profile = self._db.get_profile(self._pid)
+        setattr(profile, attr, val)
+        self._db.put_profile(self._pid, profile)


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

Reply via email to