[twill] Extending Twill Question
Titus Brown
titus at caltech.edu
Sun Jun 4 21:00:28 PDT 2006
On Fri, May 26, 2006 at 04:01:38PM -0700, Austin wrote:
-> Hi,
->
-> I'm pretty new to twill and python in general (installing both just
-> yesterday :)) and was looking to see how I might add a couple new
-> functions for personal use or if anyone was interested (I am not very
-> clear on how the licensing works.) but need a bit of help getting started.
twill is completely open source and redistributable etc, unless you're
looking to sell it. Then we should talk, or you should have a lawyer
check out the license.
Adding functions is pretty simple, as long as you don't need to modify
the core browser functionality; check out the extensions documentation at
http://issola.caltech.edu/~t/twill/doc/extensions.html
-> The first function is just forward, it looks like beyond adding
-> functions in commands.py and browser.py, the real changes would have to
-> be made in _mechanize.py since the History class doesn't seem to have
-> any support for going forward. It also doesn't seem to know what the
-> current page is which makes things a bit more difficult. I think I need
-> to store the current page in the History class, and then make some kind
-> of modifications in _mech_open, and to the functions defined in the
-> history class. Is this the right direction for doing this, or am I
-> missing something else?
Well, what's your goal with this? Right now the history works like
a simple stack; it wouldn't be hard to change it to be a list, if
that's what you need. You're right that it doesn't get the current
page, but twill has that information... so it really depends on what
you want to do.
-> Second, I would like to be able to follow a link by its number printed
-> out after using showlinks.
->
-> I added to commands.py:
->
-> def followbynum(num):
-> """
-> >> follow <link#>
->
-> Visit the page at position link# in the list returned by showlinks.
-> """
->
-> def follow_link_num(self, linknum):
-> """
-> Follow the link by its number on the page.
-> """
-> This seems to work right now, but I'm afraid there's something I am
-> missing, or some error case that I'm not considering.
Nope, it looks good to me!
I could add this functionality in to 'follow' 'as is', actually, by just
choosing the link by number in 'follow' if it's an integer. Any
objections, anyone?
cheers,
--titus
More information about the twill
mailing list