Update of /cvsroot/mailman/mailman3/src/mailman/stubbackend
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28224
Modified Files:
Tag: 3.0
stubimpl.py
Log Message:
full credit ;)
--- NEW FILE: stubimpl.py ---
# Copyright (C) 2004 Barry A. Warsaw
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place - Suite 330, Boston, MA 02111-1307, USA.
"""A stub implementation of the storage interfaces."""
# Author: Maki (Michael Kato)
from datetime import datetime
from mailman import errors
from mailman.interfaces import profile
from mailman.interfaces.storages import IListStorage
from mailman.interfaces.storages import IUserStorage
from mailman.interfaces.transactions import ITransaction, ITransactionManager
from mailman.interfaces.user import IUser
from protocols.api import advise
class StubTransaction(object):
"""A stub class representing a transaction."""
advise(instancesProvide = [ITransaction])
def abort(self):
pass
def commit(self):
pass
class StubUser(object):
"""A class that implements a stub IUser interface."""
advise(instancesProvide = [IUser])
def __init__(self, uid):
self._addresses = []
self.uid = uid
def authenticate(self, challenge):
return True
def get_address(self, label):
return None
def add_address(self, label, address):
return None
def delete_address(self, label):
return None
class StubUserStorage(object):
advise(instancesProvide = [IUserStorage, ITransactionManager])
def __init__(self):
# A dictionary of users keyed by domain.
self._domains = {}
self._nextUid = 1
def open(self):
pass
def close(self):
pass
def get_user(self, uid, domain):
try:
return self._domains[domain][uid]
except KeyError:
raise errors.NoUserError
def create_user(self, domain):
d = self._domains.setdefault(domain, {})
result = d[self._nextUid] = StubUser(self._nextUid)
self._nextUid += 1
return result
def begin(self):
return StubTransaction()
def create_profile(self, domain):
return _Profile()
stubuserstorage = StubUserStorage()
class StubListStorage(object):
advise(instancesProvide = [IListStorage, ITransactionManager])
def __init__(self):
self._listdata = {
'[EMAIL PROTECTED]': {
'name': 'mylist1',
'description': 'my first list'
}
}
def open(self):
pass
def close(self):
pass
def set(self, listid, var, data):
self._listdata[listid][var] = data
def get(self, listid, var):
"""Return the value of a variable given the listid.
For the stub we'll answer the following for listid=1:
name = mylist1
description = my first list
"""
if self._listdata.has_key(listid):
return self._listdata[listid][var]
return None
def list_exists(self, listid):
return self._listdata.has_key(listid)
def create_list(self, listid):
self._listdata[listid] = {}
return datetime.now()
def delete_list(self, listid):
pass
def begin(self):
return StubTransaction()
def listids(self):
# XXX The interface says to return a generator, but for now we'll
# return a list.
return self._listdata.keys()
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
_______________________________________________
Mailman-checkins mailing list
[EMAIL PROTECTED]
Unsubscribe: http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org