[Twisted-Python] Noob Question
sicfslist at gmail.com
Sun Mar 15 09:55:25 EDT 2009
Thanks for the assistance. I think you and David have me on the right
path. Just to clarify the protocol looks like this:
Where the body (and the content length) start and stop with the <event> ...
Here is what I've done so far:
from twisted.internet import reactor, protocol
from twisted.protocols import basic
from re import compile, findall
bl_p = compile('Content-Length:\s(\d+)')
self.body_length = None
def lineReceived(self, line):
bl_m = bl_p.findall(line)
self.body_length = int(bl_m) - len(line) # this doesn't
really work because it doesn't factor in the len of the next line
def rawDataReceived(self, data):
datalen = len(data)
if self.body_length > datalen:
self.body_length -= datalen
part = data[:self.body_length]
extra = data[self.body_length:]
print 'Left Over\n:'
def connectionLost(self, reason):
print "%s" % (reason)
protocol = My_Client
def clientConnectionFailed(self, connector, reason):
print "Connection failed - goodbye!"
def clientConnectionLost(self, connector, reason):
print "Connection lost - goodbye!"
f = FS_Factory()
reactor.connectTCP("$IP", $PORT, f)
# this only runs if the module was *not* imported
if __name__ == '__main__':
To me ... this looks somewhat correct ... but it doesn't seem to actually
ever use the line received method (note the print statement ...). For
instance upon logging in it should respond with a +OK Logged In ... but it
never prints that.
And then when it receives an "<event>..." it actually dies with this error:
[Failure instance: Traceback (failure with no frames): <class
'twisted.internet.error.ConnectionDone'>: Connection was closed cleanly.
Connection lost - goodbye!
So I'm a bit lost as to what the impact of adding the rawDataReceived method
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Twisted-Python