Re: parsing xml coming from a socket

Glyph Lefkowitz <[email protected]>
Newsgroups gmane.comp.python.twisted.web
Message-ID <[email protected]>
Hello, Antonis!

On Jun 1, 2010, at 9:46 AM, Antonis Kaklis wrote:

> Hi to all, and since this is my first post, congratulations for the perfect framework.

Thank you :).

> i have the following code

This code has two major, obvious problems:

> class SimpleServer(LineReceiver):  
> 
>     def dataReceived(self, line): 
> 
Here you say "dataReceived" receives a "line" parameter.  But dataReceived does not receive lines, it receives *data*, i.e. arbitrary chunks of bytes.  What you want to do is write a *line*Received method; you are already using LineReceiver, so I assume that's what you were trying to do.

If you fix that, the second problem is that you are creating a new XML parser for every line received.  Is that actually what you want to do?  Your message has some headers, which you will want to skip, and then the body of the message spans multiple lines.

Your "XML message" looks a lot like an HTTP POST (I am assuming the lack of spaces after the headers in your example is a typo).  Perhaps you would be better off using the built-in HTTP server in twisted.web, rather than trying to implement your own wire-level protocol?

Good luck,

-glyph

_______________________________________________
Twisted-web mailing list
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.