1.1 --- a/libxml2dom/xmpp.py Sun Apr 08 00:01:55 2007 +0000
1.2 +++ b/libxml2dom/xmpp.py Sun Apr 08 00:42:34 2007 +0000
1.3 @@ -367,7 +367,10 @@
1.4
1.5 "Read as much as possible from the server."
1.6
1.7 - l = []
1.8 + context = Parser_push()
1.9 + Parser_configure(context)
1.10 +
1.11 + have_read = 0
1.12 fds = self._ready(self.timeout)
1.13 try:
1.14 while fds:
1.15 @@ -376,15 +379,21 @@
1.16 if status & (select.POLLHUP | select.POLLNVAL | select.POLLERR):
1.17 raise SessionTerminated
1.18 if status & select.POLLIN:
1.19 + have_read = 1
1.20 c = self.socket.recv(self.bufsize)
1.21 - if c:
1.22 - l.append(c)
1.23 - else:
1.24 - raise SessionTerminated
1.25 + Parser_feed(context, c)
1.26 + if Parser_well_formed(context):
1.27 + return default_impl.adoptDocument(Parser_document(context))
1.28 +
1.29 fds = self.poller.poll(self.timeout)
1.30 +
1.31 except SessionTerminated:
1.32 pass
1.33 - return "".join(l)
1.34 +
1.35 + if have_read:
1.36 + return default_impl.adoptDocument(Parser_document(context))
1.37 + else:
1.38 + return None
1.39
1.40 def write(self, s):
1.41
1.42 @@ -404,16 +413,13 @@
1.43
1.44 def _receive(self):
1.45
1.46 - """
1.47 - Return either a stanza or None, depending on whether anything was read
1.48 - from the server.
1.49 - """
1.50 + "Return a stanza for data read from the server."
1.51
1.52 - s = self.read()
1.53 - if s:
1.54 - return parseString(s).documentElement
1.55 + doc = self.read()
1.56 + if doc is None:
1.57 + return doc
1.58 else:
1.59 - return None
1.60 + return doc.documentElement
1.61
1.62 def receive(self, timeout):
1.63
1.64 @@ -450,7 +456,7 @@
1.65 # NOTE: tag.
1.66
1.67 self.write(self.connect_str % host)
1.68 - return parseString(self.read(), unfinished=1).documentElement
1.69 + return self._receive()
1.70
1.71 # Utility functions.
1.72