[twill] how to not follow redirects

Kevin Turner kevin at janrain.com
Wed Jun 20 16:33:54 PDT 2007


Hi,

I want to test the content of a Location response-header issued by the
server (in the case of a 302 redirect) without actually following the
redirect.  This is very hard to do in twill-0.9b1.

The first obstacle is that I found no option in twill to disable the
automatic redirect handling.

That can be overcome by digging in to mechanize a bit and doing
twill.commands.get_browser()._browser.set_handle_redirect(False).  Then
when twill receives a redirect, you can test to make sure it's a
redirect with twill.commands.code(302).

However, twill's ResponseWrapper doesn't make any of the headers
accessible, so I then had to pull them out of
get_browser()._browser.response().info().

Would it be okay to make public interfaces to these things?

Thanks,

 - Kevin





More information about the twill mailing list