<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=US-ASCII">
<META content="MSHTML 6.00.2800.1528" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=132384414-20042006><FONT size=2>All,</FONT></SPAN></DIV>
<DIV><SPAN class=132384414-20042006><FONT size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=132384414-20042006><FONT size=2>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:</FONT></SPAN></DIV>
<DIV><SPAN class=132384414-20042006><FONT size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=132384414-20042006><FONT size=2> def
make_counter(x):<BR> while
1:<BR> yield
x<BR> x = x +
1</FONT></SPAN></DIV>
<DIV> </DIV>
<DIV><SPAN class=132384414-20042006><FONT size=2> counter =
make_counter(1)</FONT></SPAN></DIV>
<DIV> </DIV>
<DIV><SPAN class=132384414-20042006><FONT size=2>
security.declarePublic('getUnauthorizedURL')<BR> def
getUnauthorizedURL(self):<BR>
'''<BR> Redirects to the login
page.<BR>
'''<BR> req =
self.REQUEST<BR> resp =
req['RESPONSE']<BR> attempt =
getattr(req, '_cookie_auth',
ATTEMPT_NONE)<BR> if attempt ==
ATTEMPT_NONE:<BR>
# An anonymous user was denied access to
something.<BR>
page_id =
self.auto_login_page<BR>
retry = ''<BR> elif attempt ==
ATTEMPT_LOGIN:<BR>
# The login attempt failed. Try
again.<BR>
page_id =
self.auto_login_page<BR>
#retry =
'1'<BR> retry
= counter.next()</FONT></SPAN></DIV>
<DIV><SPAN class=132384414-20042006><FONT size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=132384414-20042006><FONT size=2>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 so:</FONT></SPAN></DIV>
<DIV><SPAN class=132384414-20042006><FONT size=2>counter =
context.make_counter(1)</FONT></SPAN></DIV>
<DIV><SPAN class=132384414-20042006><FONT size=2>return
counter.next()</FONT></SPAN></DIV>
<DIV><SPAN class=132384414-20042006><FONT size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=132384414-20042006><FONT size=2>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?</FONT></SPAN></DIV>
<DIV><SPAN class=132384414-20042006><FONT size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=132384414-20042006><FONT size=2>Thanks,</FONT></SPAN></DIV>
<DIV><SPAN class=132384414-20042006><FONT size=2>Tom
Palermo</FONT></SPAN></DIV></BODY></HTML>