A few weeks ago I thought I had the need to script (for the life of my I can't remember why I wanted to do this, I should have blogged on it) Firefox. Well I didn't any Python or Ruby tools for taking control of the browser (I remember seeing how to do this with Python and IE a loooong time ago) but tonight I ran across Twill which looks pretty cool and I assume uses the cmd module
mfranz@gutsy61:~$ twill-sh
-= Welcome to twill! =-
current page: *empty page*
>> go http://www.threatmind.net/secwiki
==> at http://www.threatmind.net/secwiki
current page: http://www.threatmind.net/secwiki
>> showforms
Form #1
## ## __Name__________________ __Type___ __ID________ __Value__________________
1 action hidden (None) fullsearch
2 context hidden (None) 180
3 value text searchinput
4 1 titlesearch submit titlesearch Titles
5 2 fullsearch submit fullsearch Text
Form #2
## ## __Name__________________ __Type___ __ID________ __Value__________________
1 action select (None) ['raw'] of ['raw', 'print', 'refresh ...
2 1 None submit (None) Do
Form #3
## ## __Name__________________ __Type___ __ID________ __Value__________________
1 action select (None) ['raw'] of ['raw', 'print', 'refresh ...
2 1 None submit (None) Do
current page: http://www.threatmind.net/secwiki
>> help
Undocumented commands:
======================
add_auth fa info save_html title
add_extra_header find load_cookies setglobal url
agent follow notfind setlocal
back formaction redirect_error show
clear_cookies formclear redirect_output show_cookies
clear_extra_headers formfile reload show_extra_headers
code formvalue reset_browser showforms
config fv reset_error showhistory
debug get_browser reset_output showlinks
echo getinput run sleep
exit getpassword runfile submit
extend_with go save_cookies tidy_ok
Friday, December 28, 2007
Thursday, December 27, 2007
Obviously I'm not Even an Intermediate Level Python Programmer
While a thread on regex performance revealed how much I've forgotten (or never knew) even though I started coding in Python (1.5.x) back in 1999. My confusion didn't have really anything to do with regexes but the two different approaches, one which was more peculiar to my only-coding-in-Ruby-recently brain:
Class Approach
After I remembered what the __call__ was used for (which I actually like) and got used to the __'s (which I don't like) and I've never liked the self's in Python method arguments -- this made sense.
Function Returning a Function
At first this didn't make much sense and I got tricked by the underscore (thinking it was some sort of Perl-like special function name or something, it isn't though!). Wny would I call a function returning another function that I would use over and over again. Why would you do that? What is interesting though is if that s("dog")("dog") also produces identical results although I have no idea why (except that the first nested function within a function always executes the second parameter).
Class Approach
import re
class Searcher(object):
def __init__(self, rex):
self.crex = re.compile(rex)
def __call__(self, txt):
return self.crex.search(txt)
s = Searcher("dog")
print s("dog").string
After I remembered what the __call__ was used for (which I actually like) and got used to the __'s (which I don't like) and I've never liked the self's in Python method arguments -- this made sense.
Function Returning a Function
import re
def searcher(rex):
crex = re.compile(rex)
def _(txt):
return crex.search(txt)
return _
s = searcher("dog")
print s("dog").string
At first this didn't make much sense and I got tricked by the underscore (thinking it was some sort of Perl-like special function name or something, it isn't though!). Wny would I call a function returning another function that I would use over and over again. Why would you do that? What is interesting though is if that s("dog")("dog") also produces identical results although I have no idea why (except that the first nested function within a function always executes the second parameter).
Monday, December 24, 2007
Names, Objects, Bindings, and Thinking Like a Pythonista
On the Python Mailing list there was a discussion about "references" and someone posted a link to How to think like a Pythonista with some nice ASCII art.
Names look like this:
,-----.
| foo |
`-----'
Names live in namespaces, but that's not really important for the
matter at hand as the only namespace in play is the one associated
with the read-eval-print loop of the interpreter. In fact names are
only minor players in the current drama; bindings and objects are the
real stars.
...
I haven't done much Ruby coding this month (cause of the baby so I'm trying to use the break to brush up on my Python. So a nice article for that.
Names look like this:
,-----.
| foo |
`-----'
Names live in namespaces, but that's not really important for the
matter at hand as the only namespace in play is the one associated
with the read-eval-print loop of the interpreter. In fact names are
only minor players in the current drama; bindings and objects are the
real stars.
...
I haven't done much Ruby coding this month (cause of the baby so I'm trying to use the break to brush up on my Python. So a nice article for that.
Sunday, December 23, 2007
Subscribe to:
Posts (Atom)