<!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>&nbsp;</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&nbsp;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>&nbsp;</DIV>
<DIV><SPAN class=132384414-20042006><FONT size=2>&nbsp;def 
make_counter(x):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while 
1:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; yield 
x<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x = x + 
1</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV><SPAN class=132384414-20042006><FONT size=2>&nbsp;&nbsp;&nbsp; counter = 
make_counter(1)</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV><SPAN class=132384414-20042006><FONT size=2>&nbsp;&nbsp;&nbsp; 
security.declarePublic('getUnauthorizedURL')<BR>&nbsp;&nbsp;&nbsp; def 
getUnauthorizedURL(self):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
'''<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Redirects to the login 
page.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
'''<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; req = 
self.REQUEST<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; resp = 
req['RESPONSE']<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; attempt = 
getattr(req, '_cookie_auth', 
ATTEMPT_NONE)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if attempt == 
ATTEMPT_NONE:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
# An anonymous user was denied access to 
something.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
page_id = 
self.auto_login_page<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
retry = ''<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; elif attempt == 
ATTEMPT_LOGIN:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
# The login attempt failed.&nbsp; Try 
again.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
page_id = 
self.auto_login_page<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
#retry = 
'1'<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retry 
= counter.next()</FONT></SPAN></DIV>
<DIV><SPAN class=132384414-20042006><FONT size=2></FONT></SPAN>&nbsp;</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>&nbsp;</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 &lt;generator object at 0xb48d56cc&gt;. 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>&nbsp;</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>