[Zope] Python Generators and Zope question

Palermo, Tom TPalermo at constellagroup.com
Thu Apr 20 10:52:00 EDT 2006

I have a site that uses CookieCrumbler for user login. I need to track how
many incorrect login attempts a user makes. I am trying to use a python
generator to do this but it makes Zope hang when I try to do an invalid
login (eg. no password or incorrect password). Here's a snippet:
 def make_counter(x):
        while 1:
            yield x
            x = x + 1
    counter = make_counter(1)
    def getUnauthorizedURL(self):
        Redirects to the login page.
        req = self.REQUEST
        resp = req['RESPONSE']
        attempt = getattr(req, '_cookie_auth', ATTEMPT_NONE)
        if attempt == ATTEMPT_NONE:
            # An anonymous user was denied access to something.
            page_id = self.auto_login_page
            retry = ''
        elif attempt == ATTEMPT_LOGIN:
            # The login attempt failed.  Try again.
            page_id = self.auto_login_page
            #retry = '1'
            retry = counter.next()
I added the make_counter function. It seems the culprit is the retry =
counter.next() bit. I tried doing this same thing with the make_counter
function in an External method and then calling it from a python script like
counter = context.make_counter(1)
return counter.next()
In that case, an unauthorized exception is raised complaining about next. I
can however, just return the counter which gives me <generator object at
0xb48d56cc>. Am I calling the next method incorrectly or is there something
else I'm missing or being dumb about?
Tom Palermo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/zope/attachments/20060420/16343863/attachment.htm

More information about the Zope mailing list