[twill] Working around <br/> issue?

C. Titus Brown ctb at msu.edu
Sun Jan 3 23:45:46 PST 2010


On Wed, Dec 30, 2009 at 04:54:45PM -0800, Howard B. Golden wrote:
> On Wednesday December 30, 2009, Misha Koshelev wrote:
> > Thank you. Very helpful!!! I have used the following code:
> > 
> > go http://www.google.com/voice#trash
> > fv 1 Email email
> > fv 1 Passwd passwd
> > submit
> > run "b=get_browser();b.result.page=b.result.page.replace('<br/>','<br
> >  />');"
> > 
> > It works as I can confirm with a save_html. However, when doing a 
> showforms I still get:
> > >> showforms
> > 
> > Traceback (most recent call last):
> >   File "/usr/bin/twill-sh", line 20, in <module>
> >     twill.shell.main()
> >   File "/var/lib/python-support/python2.5/twill/shell.py", line 387,
> >  in main shell.cmdloop(welcome_msg)
> >   File "/usr/lib/python2.5/cmd.py", line 142, in cmdloop
> >     stop = self.onecmd(line)
> >   File "/usr/lib/python2.5/cmd.py", line 219, in onecmd
> >     return func(arg)
> >   File "/var/lib/python-support/python2.5/twill/shell.py", line 42,
> >  in do_cmd print '\nERROR: %s\n' % (str(e),)
> >   File "/usr/lib/python2.5/HTMLParser.py", line 59, in __str__
> >     result = self.msg
> > AttributeError: 'ParseError' object has no attribute 'msg'
> > 
> > Any idea how I can figure out what's causing this? I'd like to avoid
> >  sending the HTML to a public list, but will gladly send over
> >  personal (individual) email.
> 
> If you look at the traceback, it is _very_ strange. The error occurred 
> in HTMLParser.py line 59, which is part of the HTMLParseError class. 
> However, it was called from shell.py line 42, which is an exception 
> handler for a twill.parse.execute_command (or at least is _should_ be). 
> But based on the traceback, somehow, the _str_() method of 
> HTMLParseError is being executed instead.

The 'msg' attribute of HTMLParser.HTMLParseError isn't being set properly,
which is causing HTMLParseError.__str__ to fail.

This can in turn be traced to the munged inheritance hierarchy in ClientForm.py
around line 440, where ClientForm.ParseError inherits from
sgmllib.SGMLParseError (which doesn't check to make sure msg is set) as well as
HTMLParser.HTMLParser (which does).

The upshot is that a minor problem in the version of ClientForm included
with twill is obscuring a presumably legitimate parse error in the HTML.
Misha, if you send me the original HTML I can track it down.  Then I can
make sure the latest ClientForm is working, as well as twill.

> I'm not sure what is going on, but I suspect it may have to do with 
> Titus's manipulation of the global and local dictionaries in shell.py 
> line 25. If my suspicion is correct, the "parse" in line 42 is referring 
> to an HTMLParser object instead of a twill.parse object.

Byte thy tongue ;)

cheers,
--titus
-- 
C. Titus Brown, ctb at msu.edu



More information about the twill mailing list