<!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> </DIV>
<DIV><SPAN class=062082619-05082008><SPAN class=796103019-05082008><FONT><FONT
face=Arial><FONT size=2><SPAN class=265012220-05082008>At my
company, </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> </DIV>
<DIV><SPAN class=062082619-05082008><SPAN class=796103019-05082008><FONT
face=Arial size=2>We noticed a problem recently where Twill <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> </DIV>
<DIV><SPAN class=062082619-05082008><SPAN class=796103019-05082008><FONT
face=Arial size=2> <select py:if="not
tg.identity.anonymous" id="quick_link_menu">
<BR> <option value="">Quick
links</option> <BR>
<option value="/promotion/list/create_new">Create a new
promotion</option> <BR>
<option
value="/promotion/list/?type=planned&amp;dates.begin=&amp;dates.end=">Find
a planned promotion</option><BR>
</select></FONT></SPAN></SPAN></DIV>
<DIV><FONT size=2></FONT><SPAN class=062082619-05082008><SPAN
class=796103019-05082008><FONT face=Arial><BR> </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 <form> 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 <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>. </SPAN><SPAN
class=796103019-05082008>B</SPAN>ecause <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 <select> tag outside of a <form> tag.</SPAN></FONT></FONT></DIV>
<DIV><SPAN class=062082619-05082008><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><FONT face=Arial size=2> def
end_select(self):<BR>
debug("")<BR> if self._current_form is
self._global_form:<BR>
return<BR> if self._select is
None:<BR>
raise ParseError("end of SELECT before start")</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2> if
self._option is not
None:<BR>
self._end_option()</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>
self._select = None<BR></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial><FONT size=2> Thus, any subsequent <select> 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> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=062082619-05082008>
def start_select(self, attrs):<BR>
debug("%s", attrs)<BR> if self._select
is not
None:<BR>
raise ParseError("nested SELECTs")<BR>
if self._textarea is not
None:<BR>
raise ParseError("SELECT inside
TEXTAREA")<BR> d =
{}<BR> for key, val in
attrs:<BR>
d[key] = val</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN
class=062082619-05082008> self._select
= d<BR>
self._add_label(d)</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN
class=062082619-05082008>
self._append_select_control({"__select": d})<BR></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=062082619-05082008></SPAN></FONT> </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> if
self._current_form is self._global_form:</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=062082619-05082008>
self._select = None # NEW
CODE<BR>
return<BR></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=062082619-05082008></SPAN></FONT> </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> </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>
result = old_end_select(self)<BR> self._select =
None<BR> 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> </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> </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> </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> </DIV></BODY></HTML>