1.1 --- a/README.txt Sun Jan 18 19:23:20 2009 +0100
1.2 +++ b/README.txt Thu Jul 09 20:48:31 2009 +0200
1.3 @@ -14,6 +14,10 @@
1.4
1.5 From libxml2dom 0.5, some XML-RPC nodes employ different properties.
1.6
1.7 +From libxml2dom 0.5, the send method of libxml2dom.xmpp.Session instances no
1.8 +longer return responses. Such instances can also no longer be configured with
1.9 +an internal timeout value.
1.10 +
1.11 Contact, Copyright and Licence Information
1.12 ------------------------------------------
1.13
1.14 @@ -81,6 +85,9 @@
1.15 * Enabled prettyprinting support, finally.
1.16 * Added the hasChildNodes method, requested by Nick Galbreath.
1.17 * Fixed the Debian packaging to use python-central.
1.18 + * Changed the XMPP API to only return document fragments from receive method
1.19 + calls; added support for failure elements; removed the internal timeout
1.20 + interval; added a disconnect method.
1.21
1.22 New in libxml2dom 0.4.7 (Changes since libxml2dom 0.4.6)
1.23 --------------------------------------------------------
2.1 --- a/libxml2dom/macrolib/macrolib.py Sun Jan 18 19:23:20 2009 +0100
2.2 +++ b/libxml2dom/macrolib/macrolib.py Thu Jul 09 20:48:31 2009 +0200
2.3 @@ -736,7 +736,7 @@
2.4 def Parser_push():
2.5 return libxml2mod.xmlCreatePushParser(None, "", 0, None)
2.6
2.7 -def Parser_configure(context, validate, remote):
2.8 +def Parser_configure(context, validate=0, remote=0):
2.9 libxml2mod.xmlParserSetPedantic(context, 0)
2.10 #libxml2mod.xmlParserSetValidate(context, validate)
2.11 libxml2mod.xmlCtxtUseOptions(context,
3.1 --- a/libxml2dom/xmpp.py Sun Jan 18 19:23:20 2009 +0100
3.2 +++ b/libxml2dom/xmpp.py Thu Jul 09 20:48:31 2009 +0200
3.3 @@ -34,14 +34,16 @@
3.4 auth = s.createAuth() # provides access to the stanza
3.5 auth.mechanism = "PLAIN" # choose a supported mechanism
3.6 auth.setCredentials(jid, username, password) # for PLAIN authentication only
3.7 -d = s.send(auth) # hopefully a success response
3.8 +s.send(auth) # send the authentication request
3.9 +d = s.receive() # hopefully a success response
3.10 d = s.connect("host") # have to reconnect!
3.11 iq = s.createIq() # make an 'iq' stanza
3.12 iq.makeBind() # set up a binding operation
3.13 -d = s.send(iq) # hopefully a success response
3.14 +s.send(iq) # send the binding request
3.15 +d = s.receive() # hopefully a success response
3.16 iq = s.createIq() # make an 'iq' stanza
3.17 iq.makeSession() # set up a session
3.18 -d = s.send(iq) # hopefully a success response
3.19 +s.send(iq) # send the session request
3.20
3.21 See tests/xmpp_test.py for more details.
3.22 """
3.23 @@ -129,6 +131,8 @@
3.24 elif Node_namespaceURI(_node) == XMPP_SASL_NAMESPACE:
3.25 if Node_localName(_node) == "auth":
3.26 return XMPPAuthElement(_node, self, context_node.ownerDocument)
3.27 + elif Node_localName(_node) == "failure":
3.28 + return XMPPFailureElement(_node, self, context_node.ownerDocument)
3.29
3.30 # Make special stream elements.
3.31
3.32 @@ -267,6 +271,21 @@
3.33 to = property(_to, _setTo, _delTo)
3.34 type = property(_type, _setType, _delType)
3.35
3.36 +class XMPPFailureElement(XMPPElement):
3.37 +
3.38 + "An XMPP failure element."
3.39 +
3.40 + def _reason(self):
3.41 + return self.xpath("*")[0].localName
3.42 +
3.43 + def _setReason(self, reason_text):
3.44 + for reason in self.xpath("*"):
3.45 + self.removeChild(reason)
3.46 + element = self.ownerDocument.createElement(reason_text)
3.47 + self.appendChild(element)
3.48 +
3.49 + reason = property(_reason, _setReason)
3.50 +
3.51 class XMPPMessageElement(XMPPClientElement):
3.52
3.53 "An XMPP message element."
3.54 @@ -409,16 +428,14 @@
3.55 disconnect_str = """\
3.56 </stream:stream>"""
3.57
3.58 - def __init__(self, address, timeout=500, bufsize=1024, encoding="utf-8"):
3.59 + def __init__(self, address, bufsize=1024, encoding="utf-8"):
3.60
3.61 """
3.62 Initialise an XMPP session using the given 'address': a tuple of the
3.63 - form (hostname, port). The optional 'timeout' (in milliseconds) is used
3.64 - for polling the connection for new data, and the optional 'encoding'
3.65 - specifies the character encoding employed in the communications.
3.66 + form (hostname, port). The optional 'encoding' specifies the character
3.67 + encoding employed in the communications.
3.68 """
3.69
3.70 - self.timeout = timeout
3.71 self.bufsize = bufsize
3.72 self.encoding = encoding
3.73 self.poller = select.poll()
3.74 @@ -427,41 +444,29 @@
3.75 self.socket.connect(address)
3.76 self.poller.register(self.socket.fileno(), select.POLLIN | select.POLLHUP | select.POLLNVAL | select.POLLERR)
3.77
3.78 - def _ready(self, timeout):
3.79 + def read(self, timeout=None):
3.80
3.81 """
3.82 - Return whether data can be read from the server, waiting as long as the
3.83 - specified 'timeout' (forever if set to None).
3.84 + Read as much as possible from the server, waiting as long as the
3.85 + specified 'timeout' (forever if set to None) for a message to arrive.
3.86 """
3.87
3.88 - return self.poller.poll(timeout)
3.89 -
3.90 - def read(self):
3.91 -
3.92 - "Read as much as possible from the server."
3.93 -
3.94 context = Parser_push()
3.95 Parser_configure(context)
3.96
3.97 have_read = 0
3.98 - fds = self._ready(self.timeout)
3.99 - try:
3.100 - while fds:
3.101 - for fd, status in fds:
3.102 - if fd == self.socket.fileno():
3.103 - if status & (select.POLLHUP | select.POLLNVAL | select.POLLERR):
3.104 - raise SessionTerminated
3.105 - if status & select.POLLIN:
3.106 - have_read = 1
3.107 - c = self.socket.recv(self.bufsize)
3.108 - Parser_feed(context, c)
3.109 - if Parser_well_formed(context):
3.110 - return default_impl.adoptDocument(Parser_document(context))
3.111 + fds = self.poller.poll(timeout)
3.112
3.113 - fds = self.poller.poll(self.timeout)
3.114 -
3.115 - except SessionTerminated:
3.116 - pass
3.117 + for fd, status in fds:
3.118 + if fd == self.socket.fileno():
3.119 + if status & (select.POLLHUP | select.POLLNVAL | select.POLLERR):
3.120 + raise SessionTerminated
3.121 + if status & select.POLLIN:
3.122 + have_read = 1
3.123 + c = self.socket.recv(self.bufsize)
3.124 + Parser_feed(context, c)
3.125 + if Parser_well_formed(context):
3.126 + return default_impl.adoptDocument(Parser_document(context))
3.127
3.128 if have_read:
3.129 return default_impl.adoptDocument(Parser_document(context))
3.130 @@ -477,22 +482,10 @@
3.131 def send(self, stanza):
3.132
3.133 """
3.134 - Send the 'stanza' to the server, returning a response stanza if an
3.135 - immediate response was provided, or None otherwise.
3.136 + Send the 'stanza' to the server.
3.137 """
3.138
3.139 stanza.toStream(self, encoding=self.encoding)
3.140 - return self._receive()
3.141 -
3.142 - def _receive(self):
3.143 -
3.144 - "Return a stanza for data read from the server."
3.145 -
3.146 - doc = self.read()
3.147 - if doc is None:
3.148 - return doc
3.149 - else:
3.150 - return doc.documentElement
3.151
3.152 def receive(self, timeout=None):
3.153
3.154 @@ -502,10 +495,11 @@
3.155 stanza document (fragment) or None if nothing was received.
3.156 """
3.157
3.158 - if self._ready(timeout):
3.159 - return self._receive()
3.160 + doc = self.read(timeout)
3.161 + if doc is None:
3.162 + return None
3.163 else:
3.164 - return None
3.165 + return doc.documentElement
3.166
3.167 # Stanza creation.
3.168
3.169 @@ -532,7 +526,14 @@
3.170 # NOTE: tag.
3.171
3.172 self.write(self.connect_str % host)
3.173 - return self._receive()
3.174 + return self.receive()
3.175 +
3.176 + def disconnect(self):
3.177 +
3.178 + # NOTE: Nasty sending of the raw text because it involves only an end
3.179 + # NOTE: tag.
3.180 +
3.181 + self.write(self.disconnect_str)
3.182
3.183 # Utility functions.
3.184
4.1 --- a/packages/debian-etch/python-libxml2dom/debian/changelog Sun Jan 18 19:23:20 2009 +0100
4.2 +++ b/packages/debian-etch/python-libxml2dom/debian/changelog Thu Jul 09 20:48:31 2009 +0200
4.3 @@ -13,8 +13,12 @@
4.4 * Added the hasChildNodes method, requested by Nick
4.5 Galbreath.
4.6 * Fixed the Debian packaging to use python-central.
4.7 + * Changed the XMPP API to only return document fragments
4.8 + from receive method calls; added support for failure
4.9 + elements; removed the internal timeout interval; added a
4.10 + disconnect method.
4.11
4.12 - -- Paul Boddie <paul@boddie.org.uk> Sun, 18 Jan 2009 18:41:08 +0100
4.13 + -- Paul Boddie <paul@boddie.org.uk> Thu, 09 Jul 2009 20:42:16 +0200
4.14
4.15 libxml2dom (0.4.7-0ubuntu1) stable; urgency=low
4.16
5.1 --- a/packages/debian-lenny/python-libxml2dom/debian/changelog Sun Jan 18 19:23:20 2009 +0100
5.2 +++ b/packages/debian-lenny/python-libxml2dom/debian/changelog Thu Jul 09 20:48:31 2009 +0200
5.3 @@ -13,8 +13,12 @@
5.4 * Added the hasChildNodes method, requested by Nick
5.5 Galbreath.
5.6 * Fixed the Debian packaging to use python-central.
5.7 + * Changed the XMPP API to only return document fragments
5.8 + from receive method calls; added support for failure
5.9 + elements; removed the internal timeout interval; added a
5.10 + disconnect method.
5.11
5.12 - -- Paul Boddie <paul@boddie.org.uk> Sun, 18 Jan 2009 18:41:08 +0100
5.13 + -- Paul Boddie <paul@boddie.org.uk> Thu, 09 Jul 2009 20:42:41 +0200
5.14
5.15 libxml2dom (0.4.7-0ubuntu1) stable; urgency=low
5.16
6.1 --- a/packages/debian-sarge/python2.3-libxml2dom/debian/changelog Sun Jan 18 19:23:20 2009 +0100
6.2 +++ b/packages/debian-sarge/python2.3-libxml2dom/debian/changelog Thu Jul 09 20:48:31 2009 +0200
6.3 @@ -13,8 +13,12 @@
6.4 * Added the hasChildNodes method, requested by Nick
6.5 Galbreath.
6.6 * Fixed the Debian packaging to use python-central.
6.7 + * Changed the XMPP API to only return document fragments
6.8 + from receive method calls; added support for failure
6.9 + elements; removed the internal timeout interval; added a
6.10 + disconnect method.
6.11
6.12 - -- Paul Boddie <paul@boddie.org.uk> Sun, 18 Jan 2009 18:41:36 +0100
6.13 + -- Paul Boddie <paul@boddie.org.uk> Thu, 09 Jul 2009 20:42:52 +0200
6.14
6.15 libxml2dom (0.4.7-0ubuntu1) stable; urgency=low
6.16
7.1 --- a/packages/ubuntu-feisty/python-libxml2dom/debian/changelog Sun Jan 18 19:23:20 2009 +0100
7.2 +++ b/packages/ubuntu-feisty/python-libxml2dom/debian/changelog Thu Jul 09 20:48:31 2009 +0200
7.3 @@ -13,8 +13,12 @@
7.4 * Added the hasChildNodes method, requested by Nick
7.5 Galbreath.
7.6 * Fixed the Debian packaging to use python-central.
7.7 + * Changed the XMPP API to only return document fragments
7.8 + from receive method calls; added support for failure
7.9 + elements; removed the internal timeout interval; added a
7.10 + disconnect method.
7.11
7.12 - -- Paul Boddie <paul@boddie.org.uk> Sun, 18 Jan 2009 18:41:59 +0100
7.13 + -- Paul Boddie <paul@boddie.org.uk> Thu, 09 Jul 2009 20:43:04 +0200
7.14
7.15 libxml2dom (0.4.7-0ubuntu1) feisty; urgency=low
7.16
8.1 --- a/packages/ubuntu-gutsy/python-libxml2dom/debian/changelog Sun Jan 18 19:23:20 2009 +0100
8.2 +++ b/packages/ubuntu-gutsy/python-libxml2dom/debian/changelog Thu Jul 09 20:48:31 2009 +0200
8.3 @@ -13,8 +13,12 @@
8.4 * Added the hasChildNodes method, requested by Nick
8.5 Galbreath.
8.6 * Fixed the Debian packaging to use python-central.
8.7 + * Changed the XMPP API to only return document fragments
8.8 + from receive method calls; added support for failure
8.9 + elements; removed the internal timeout interval; added a
8.10 + disconnect method.
8.11
8.12 - -- Paul Boddie <paul@boddie.org.uk> Sun, 18 Jan 2009 18:42:07 +0100
8.13 + -- Paul Boddie <paul@boddie.org.uk> Thu, 09 Jul 2009 20:43:15 +0200
8.14
8.15 libxml2dom (0.4.7-0ubuntu1) feisty; urgency=low
8.16
9.1 --- a/packages/ubuntu-hoary/python2.4-libxml2dom/debian/changelog Sun Jan 18 19:23:20 2009 +0100
9.2 +++ b/packages/ubuntu-hoary/python2.4-libxml2dom/debian/changelog Thu Jul 09 20:48:31 2009 +0200
9.3 @@ -13,8 +13,12 @@
9.4 * Added the hasChildNodes method, requested by Nick
9.5 Galbreath.
9.6 * Fixed the Debian packaging to use python-central.
9.7 + * Changed the XMPP API to only return document fragments
9.8 + from receive method calls; added support for failure
9.9 + elements; removed the internal timeout interval; added a
9.10 + disconnect method.
9.11
9.12 - -- Paul Boddie <paul@boddie.org.uk> Sun, 18 Jan 2009 18:41:51 +0100
9.13 + -- Paul Boddie <paul@boddie.org.uk> Thu, 09 Jul 2009 20:43:25 +0200
9.14
9.15 libxml2dom (0.4.7-0ubuntu1) hoary; urgency=low
9.16
10.1 --- a/tests/xmpp_test.py Sun Jan 18 19:23:20 2009 +0100
10.2 +++ b/tests/xmpp_test.py Thu Jul 09 20:48:31 2009 +0200
10.3 @@ -12,22 +12,30 @@
10.4 if len(sys.argv) > 2:
10.5 peer = sys.argv[2]
10.6 elif sender:
10.7 - peer = "paulb@jeremy/receiver"
10.8 + peer = "paulb@localhost/receiver"
10.9
10.10 s = libxml2dom.xmpp.Session(("localhost", 5222))
10.11 -d = s.connect("jeremy")
10.12 +d = s.connect("localhost")
10.13 print "---- 1 ----"
10.14 print d.toString()
10.15
10.16 auth = s.createAuth()
10.17 auth.mechanism = "PLAIN"
10.18 -auth.setCredentials("paulb@jeremy", "paulb", "jabber")
10.19 -d = s.send(auth)
10.20 +auth.setCredentials("paulb@localhost", "paulb", "jabber")
10.21 +s.send(auth)
10.22 print "---- 2 ----"
10.23 +d = s.receive()
10.24 +print "---- 3 ----"
10.25 print d.toString()
10.26
10.27 -d = s.connect("jeremy")
10.28 -print "---- 3 ----"
10.29 +if d.localName == "failure":
10.30 + if d.reason == "not-authorized":
10.31 + print "Not authorized: must register first!"
10.32 + s.disconnect()
10.33 + sys.exit(1)
10.34 +
10.35 +d = s.connect("localhost")
10.36 +print "---- 4 ----"
10.37 print d.toString()
10.38
10.39 iq = s.createIq()
10.40 @@ -36,19 +44,23 @@
10.41 iq.bind.resource = "sender"
10.42 else:
10.43 iq.bind.resource = "receiver"
10.44 -d = s.send(iq)
10.45 -print "---- 4 ----"
10.46 +s.send(iq)
10.47 +print "---- 5 ----"
10.48 +d = s.receive()
10.49 +print "---- 6 ----"
10.50 print d.toString()
10.51
10.52 iq = s.createIq()
10.53 -iq.makeSession("jeremy")
10.54 -d = s.send(iq)
10.55 -print "---- 5 ----"
10.56 +iq.makeSession("localhost")
10.57 +s.send(iq)
10.58 +print "---- 7 ----"
10.59 +d = s.receive()
10.60 +print "---- 8 ----"
10.61 print d.toString()
10.62
10.63 if sender:
10.64 message = s.createMessage()
10.65 - message.from_ = "paulb@jeremy/sender"
10.66 + message.from_ = "paulb@localhost/sender"
10.67 message.to = peer
10.68 message.type = "chat"
10.69 message.body = message.createBody()
10.70 @@ -56,7 +68,8 @@
10.71 message.body.appendChild(text)
10.72 print "Sending..."
10.73 print message.toString()
10.74 - d = s.send(message)
10.75 + s.send(message)
10.76 + d = s.receive()
10.77
10.78 if receiver:
10.79 while 1:
10.80 @@ -87,7 +100,8 @@
10.81 presence.to = doc.from_
10.82 print "Sending..."
10.83 print presence.toString()
10.84 - d = s.send(presence)
10.85 + s.send(presence)
10.86 + d = s.receive()
10.87 print
10.88
10.89 # vim: tabstop=4 expandtab shiftwidth=4