[twill] Working around <br/> issue?

Howard B. Golden hgolden at socal.rr.com
Wed Dec 30 16:54:45 PST 2009

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.

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.

As far as how to proceed, you could step through shell.py right there 
(in the do_cmd method) and see what type is being used. Another approach 
that might be easier is to put "twill." in front of "parse." on lines 
30, 31 and 37 of shell.py. This will make sure that the right "parse" is 
being used. If it corrects the problem, then it supports my hypothesis.


More information about the twill mailing list