[Mailman-Developers] Another extend.py thing.. (was Re: MemberAdaptor... trouble with API?)

Barry A. Warsaw barry@python.org
Tue, 20 Aug 2002 19:36:54 -0400


>>>>> "SS" == Steve Spicklemire <steve@spvi.com> writes:

    SS> I think the basic issue is that when I assign the modified
    SS> method to an instance of a MailList, it get's stored in the
    SS> instance's __dict__, which during the "Save" method, is then
    SS> copied and (unsuccessfully) pickled.

Save() has a filter on names starting with underscore, and object that
are methods -- type(value) is MethodType.  But the way you're creating
the new authenticateMethod() is you're creating a function, not a
method (it's not in a class).

You could try something like the following (untested) instead, or we
could add another test in the attribute filter in Save() to ignore
functions.  Side note: all this gets much easier in Python 2.2,
because I think properties make our lives much nice.

class NewAuthenticator:
    def __init__(self, oldfunc):
        self._oldfunc = oldfunc
	
    def authenticateMember(member, response):
	l_r = member.split('@')
	if len(l_r) == 2:
	    if l_r[1] == 'our.domain':
		if checkLDAP(None, member, response):
		    return response
	return self._oldfunc(member, response)


def extend(mlist):
    authenticator = NewAuthenticator(mlist.authenticateMember)
    mlist.authenticateMember = authenticator.authenticateMember

HTH,
-Barry