# HG changeset patch # User paulb # Date 1175992954 0 # Node ID 1321d1eadde2b74ccf238174b54ad26b53f972f3 # Parent 0f30986e391ae522409f8e00927721d144b46d40 [project @ 2007-04-08 00:42:34 by paulb] Switched to using the push parser in libxml2 in order to better recognise situations where data is still expected. diff -r 0f30986e391a -r 1321d1eadde2 libxml2dom/xmpp.py --- a/libxml2dom/xmpp.py Sun Apr 08 00:01:55 2007 +0000 +++ b/libxml2dom/xmpp.py Sun Apr 08 00:42:34 2007 +0000 @@ -367,7 +367,10 @@ "Read as much as possible from the server." - l = [] + context = Parser_push() + Parser_configure(context) + + have_read = 0 fds = self._ready(self.timeout) try: while fds: @@ -376,15 +379,21 @@ if status & (select.POLLHUP | select.POLLNVAL | select.POLLERR): raise SessionTerminated if status & select.POLLIN: + have_read = 1 c = self.socket.recv(self.bufsize) - if c: - l.append(c) - else: - raise SessionTerminated + Parser_feed(context, c) + if Parser_well_formed(context): + return default_impl.adoptDocument(Parser_document(context)) + fds = self.poller.poll(self.timeout) + except SessionTerminated: pass - return "".join(l) + + if have_read: + return default_impl.adoptDocument(Parser_document(context)) + else: + return None def write(self, s): @@ -404,16 +413,13 @@ def _receive(self): - """ - Return either a stanza or None, depending on whether anything was read - from the server. - """ + "Return a stanza for data read from the server." - s = self.read() - if s: - return parseString(s).documentElement + doc = self.read() + if doc is None: + return doc else: - return None + return doc.documentElement def receive(self, timeout): @@ -450,7 +456,7 @@ # NOTE: tag. self.write(self.connect_str % host) - return parseString(self.read(), unfinished=1).documentElement + return self._receive() # Utility functions.