[Mailman-Developers] More extend.py questions

Martin Whinnery <martin.whinnery@sbirmc.ac.uk> e008993@cobalt.sbirmc.ac.uk
Wed Oct 30 20:56:11 2002



On Wed, 30 Oct 2002, Greg Ward wrote:

> On 30 October 2002, Martin Whinnery said:
> > Please indulge a python virgin. Barry has advised someone to 'overload
> > the Load & Save function' in extend.py . Would someone help me with a
> > little sample? It doesn't need to do anything useful, just replace the
> > original function.
> 
> Huh?  There's no file called extend.py in the Mailman source tree.  Just
> what are you trying to accomplish?
> 

And I quote (From NEWS 2.36)
"   
    - Membership Adaptors
        o Internally, mailing list memberships are accessed through a
          MemberAdaptor interface.  This would allow for integrating
          membership databases with external sources (e.g. Zope or
          LDAP), although the only MemberAdaptor currently implemented
          is a "classic" adaptor which stores the membership
          information on the MailList object.
...
    - List Extensibility
        o A framework has been added which can be used to specialize
          and extend specific mailing lists.  If there is a file
          called lists/<yourlist>/extend.py, it is execfile()'d after
          the MailList object is instantiated.  The file should
          contain a function extend() which will be called with the
          MailList instance...
"

Now after a little more digging (And I take your point about not hacking
the actual source, I don't know what I was thinking. Probably why I'm
'just the assistant') it appears that what I need to do is implement new
Load() and Save() functions ( orginally defined in MailList.py ), which
cause membership information to be read into the mlist structure from LDAP
rather than from config.pck, and which fail to write that information back
to config.pck.

I appreciate that this will leave membership options unable to be changed,
but that's what we want. A later version might be able to write that info
back to LDAP, but there's authentication issues and the matter of schema
definitions, and I don't need to go there just yet.

Here, look. This code is in file

/usr/local/mailman/lists/ldaplist/extend.py

# Extension mechanism for a list.
# This ought to cause a lists membership info to read from LDAP

from ldap import *
from Mailman.ldap_cfg import *
from Mailman.LDAPMemberships import *
## Note that the file LDAPMemberships.py is identical to
## OldStyleMembership.py except that names the class LDAPMemberships.
## All the methods are currently identical
 
class LDAPMailList:
    def __init__(self,oldfunc):
        self.oldfunc = oldfunc

    def Save(self):
        myldap = initialize(LDAP_URL)
        myldap.simple_bind("dummy","")
        return

    def Load(self):
        """Load method which ought to overload that defined in MailList"""
        myldap = initialize(LDAP_URL)
        myldap.simple_bind("","")
        # Populate membership
        filter = "(&(objectclass=" + LDAP_LIST_CLASS + ")(" +
LDAP_LIST_RDN_ATTR + "=" + mlist.real_name + "))"
	blah blah blah LDAP stuff blah blah blah
        return


def extend(mlist):
    mlist = LDAPMailList(mlist)
    mlist.__memberadaptor = LDAPMemberships(mlist)

----- snip ----------

Now, what I want is for the Load() and Save() functions defined in
MailList.py to be overridden for this list with my own versions.

I just don't understand Python/Mailman well enough.

I suspect that I'm trying to do one thing two ways, and that I should
forget the LDAPMemberships / MemberAdaptor stuff for the moment.

Any examples, flames, advice or witticisms will be revered in a darkened
room.


Thanks in advance (I like the desperate sound that makes when I say it)

Martin Whinnery
"Just the" Assistant Network Manager
South Birmingham College