On Saturday 14 March 2009 18:33:02 Shelby Ramsey wrote: > Hello: > > I've been playing with twisted (to take advantage of deferreds) and trying > to accomplish this: > -- log into a machine as a client > -- send auth > -- receive "events" from the machine > > The events have a Content-Length: \d+ as the protocol for determining the > length of the message. What I'm struggling with is how to parse that and > then receive just that length as an individual message ...
Not really sure if I interpret this correctly. Is your protocol text or
binary? "Content-Length: \d+" seems to imply ASCII; if thats the case I guess
you can just do something along the line of:
>>> import re
>>> p = re.compile(r'^Content-Length: (\d+)')
>>> m = p.search("Content-Length: 123")
>>> int(m.group(1))
123
No?
If its a binary protocol, look at the struct module and the functions pack()
and unpack()
hth,
peter.
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ Twisted-Python mailing list [email protected] http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
