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!

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Reply via email to