Friday, February 19, 2010

Usage Python twisted

For new page usage:
from twisted.internet import reactor
from twisted.internet.defer import DeferredList

data = "some data for http body"

def responseData(result, factory)
print "Content Length=", len(result)
print "Cookies =", factory.cookies

def failurePage(error)
print 'msg=', error.getErrorMessage()
print 'err=', error

def finished(ign):
reactor.stop()

d1, factory = getNewPage(url, postdata=data)

dl = DeferredList([d1])
dl.addCallback(responseData, factory)
dl.addErrback(failurePage)
dl.addCallback(finished)

reactor.run()

1 comment: