[Twisted-Python] Noob Question
Peter Sabaini
peter at sabaini.at
Sat Mar 14 16:29:44 MDT 2009
On Saturday 14 March 2009 22:12:49 Shelby Ramsey wrote:
> Peter,
>
> Thanks for the help. Yes I get a header and then am looking to extract the
> body.
>
> So to make sure I understand:
>
> p = compile('Content-Length:\s(\d+)')
Of course I dont know anything about your protocol, but anyways:
> class SomeClient(basic.LineReceiver):
> def connectionMade(self):
> self.transport.write('login: info\r\n\r\n') # log in ... then
> device starts sending events
>
> def lineReceived(self, line):
> m = p.findall(line)
> if m:
> self.body_length = m[0]
> self.setRawMode()
If Content-Length is the last header
> def rawDataReceived(self, data):
> self.get_rest -= len(data)
> set.lineMode()
Mhm rather something like, since you don't know the chunk size:
def rawDataReceived(self, data):
datalen = len(data)
if self.body_length > datalen:
self.body_length -= datalen
do_something_with(data)
else:
part = data[:self.body_length]
extra = data[self.body_length:]
do_something_with(part)
self.setLineMode(extra=extra)
cheers,
peter.
> Should something along those lines work?
>
> David / Peter ... thanks again for the assistance!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
URL: </pipermail/twisted-python/attachments/20090314/62f06ce4/attachment.sig>
More information about the Twisted-Python
mailing list