<!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.6000.16674" name=GENERATOR></HEAD>
<BODY>
<DIV>
<DIV><SPAN class=062082619-05082008><SPAN class=796103019-05082008><FONT 
face=Arial size=2><SPAN 
class=265012220-05082008>Hi,</SPAN></FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=062082619-05082008><SPAN class=796103019-05082008><FONT 
face=Arial size=2><SPAN 
class=265012220-05082008></SPAN></FONT></SPAN></SPAN>&nbsp;</DIV>
<DIV><SPAN class=062082619-05082008><SPAN class=796103019-05082008><FONT><FONT 
face=Arial><FONT size=2><SPAN class=265012220-05082008>At my 
company,&nbsp;</SPAN><SPAN class=265012220-05082008>w</SPAN>e are starting to 
use Twill for server monitoring and load 
testing.</FONT></FONT></FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=062082619-05082008><SPAN class=796103019-05082008><FONT 
face=Arial size=2></FONT></SPAN></SPAN>&nbsp;</DIV>
<DIV><SPAN class=062082619-05082008><SPAN class=796103019-05082008><FONT 
face=Arial size=2>We noticed a problem recently where Twill&nbsp;<SPAN 
class=265012220-05082008>would </SPAN>report a "nested SELECTs" parse error on a 
page which looked fine to us. On further investigation, this was the HTML 
causing the problem. It is a 'quick links' drop-down which we include at the top 
of every page:</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=062082619-05082008><SPAN class=796103019-05082008><FONT 
face=Arial size=2></FONT></SPAN></SPAN>&nbsp;</DIV>
<DIV><SPAN class=062082619-05082008><SPAN class=796103019-05082008><FONT 
face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;select py:if="not 
tg.identity.anonymous" id="quick_link_menu"&gt;&nbsp; 
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;option value=""&gt;Quick 
links&lt;/option&gt;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;option value="/promotion/list/create_new"&gt;Create a new 
promotion&lt;/option&gt;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;option 
value="/promotion/list/?type=planned&amp;amp;dates.begin=&amp;amp;dates.end="&gt;Find 
a planned promotion&lt;/option&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;/select&gt;</FONT></SPAN></SPAN></DIV>
<DIV><FONT size=2></FONT><SPAN class=062082619-05082008><SPAN 
class=796103019-05082008><FONT face=Arial><BR>&nbsp;</DIV></FONT></SPAN></SPAN>
<DIV><FONT face=Arial><FONT size=2><SPAN class=062082619-05082008><SPAN 
class=796103019-05082008>Because events on this select tag control are processed 
on the browser side by JavaScript, it is not enclosed in a &lt;form&gt; tag. 
This HTML uncovered an apparent bug in twill/other_packages/_mechanize_dist<SPAN 
class=265012220-05082008>. </SPAN></SPAN></SPAN>T<SPAN 
class=062082619-05082008><SPAN class=796103019-05082008>he problem&nbsp;<SPAN 
class=265012220-05082008>stems from </SPAN></SPAN></SPAN><SPAN 
class=062082619-05082008><SPAN class=796103019-05082008>t</SPAN>he following 
function in ClientForm.py<SPAN class=796103019-05082008>.&nbsp;</SPAN><SPAN 
class=796103019-05082008>B</SPAN>ecause&nbsp;<SPAN 
class=265012220-05082008>end_select() </SPAN>exits immediately if 
self._current_form is self._global_form, it leaves self._select set if there is 
a &lt;select&gt; tag outside of a &lt;form&gt; tag.</SPAN></FONT></FONT></DIV>
<DIV><SPAN class=062082619-05082008><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; def 
end_select(self):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
debug("")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if self._current_form is 
self._global_form:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
return<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if self._select is 
None:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
raise ParseError("end of SELECT before start")</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if 
self._option is not 
None:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self._end_option()</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self._select = None<BR></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2>&nbsp;Thus, any subsequent &lt;select&gt; tag 
will cause a parse error in start_select()<SPAN 
class=062082619-05082008>:</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=062082619-05082008></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><SPAN class=062082619-05082008>&nbsp;&nbsp;&nbsp; 
def start_select(self, attrs):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
debug("%s", attrs)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if self._select 
is not 
None:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
raise ParseError("nested SELECTs")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
if self._textarea is not 
None:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
raise ParseError("SELECT inside 
TEXTAREA")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d = 
{}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for key, val in 
attrs:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
d[key] = val</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=062082619-05082008>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self._select 
= d<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self._add_label(d)</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=062082619-05082008>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self._append_select_control({"__select": d})<BR></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=062082619-05082008></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><SPAN class=062082619-05082008>A possible fix is to 
to clear self._select here:</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=062082619-05082008>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if 
self._current_form is self._global_form:</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=062082619-05082008>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self._select = None # NEW 
CODE<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
return<BR></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=062082619-05082008></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><SPAN class=062082619-05082008><SPAN 
class=796103019-05082008>or you can monkeypatch around it, as I'm 
doing:</SPAN></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=062082619-05082008><SPAN 
class=796103019-05082008></SPAN></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><SPAN class=062082619-05082008><SPAN 
class=796103019-05082008># Patch the form parser class to ensure end select tags 
are processed correctly<BR>from twill.other_packages._mechanize_dist import 
ClientForm<BR>form_parser_class = 
b._browser._factory.soup_factory._forms_factory.form_parser_class<BR>old_end_select 
= form_parser_class.end_select<BR>def end_select(self):<BR>&nbsp;&nbsp;&nbsp; 
result = old_end_select(self)<BR>&nbsp;&nbsp;&nbsp; self._select = 
None<BR>&nbsp;&nbsp;&nbsp; return result<BR>form_parser_class.end_select = 
end_select<BR></SPAN></SPAN></FONT></DIV>
<DIV><SPAN class=062082619-05082008>
<DIV><SPAN class=062082619-05082008><FONT face=Arial size=2><SPAN 
class=796103019-05082008></SPAN></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=062082619-05082008><FONT face=Arial><FONT size=2><SPAN 
class=796103019-05082008>Either of these fixes works but </SPAN>with one 
apparent side effect - now all the form indices are shifted by 1, e.g. form 1 
becomes form 2.</FONT></FONT></SPAN></DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=062082619-05082008></SPAN></FONT>&nbsp;</DIV>
<DIV><SPAN class=062082619-05082008><SPAN class=796103019-05082008><SPAN 
class=265012220-05082008><FONT face=Arial size=2>If either of these changes 
looks okay, could one of them be incorporated in Twill or 
mechanize?</FONT></SPAN></SPAN></SPAN></DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=062082619-05082008></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><SPAN class=062082619-05082008><SPAN 
class=796103019-05082008>Thanks,</SPAN></SPAN></FONT></DIV></SPAN></DIV>
<DIV><SPAN class=062082619-05082008><FONT face=Arial><FONT size=2>Barry<SPAN 
class=796103019-05082008> Hart</SPAN></FONT></FONT></DIV></SPAN></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV></BODY></HTML>