[Telepathy-commits] [telepathy-salut/master] Add events for connection results of outgoing connections
Sjoerd Simons
sjoerd.simons at collabora.co.uk
Thu Sep 4 10:34:50 PDT 2008
---
tests/twisted/xmppstream.py | 16 ++++++++++++++--
1 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/tests/twisted/xmppstream.py b/tests/twisted/xmppstream.py
index 8d1cb92..4a4f7fc 100644
--- a/tests/twisted/xmppstream.py
+++ b/tests/twisted/xmppstream.py
@@ -7,7 +7,7 @@ import servicetest
from servicetest import Event, EventPattern
import twisted
from twisted.words.xish import domish, xpath, xmlstream
-from twisted.internet.protocol import Factory
+from twisted.internet.protocol import Factory, ClientFactory
from twisted.internet import reactor
NS_STREAMS = 'http://etherx.jabber.org/streams'
@@ -142,15 +142,27 @@ class OutgoingXmppStream(BaseXmlStream):
self.addObserver(xmlstream.STREAM_CONNECTED_EVENT, self.connected)
def connected (self, stream):
+ e = Event('connection-result', succeeded = True)
+ self.event(e)
+
self.send_header()
+class OutgoingXmppFactory(ClientFactory):
+ def __init__(self, event_function):
+ self.event_func = event_function
+
+ def clientConnectionFailed(self, connector, reason):
+ ClientFactory.clientConnectionFailed(self, connector, reason)
+ e = Event('connection-result', succeeded = False, reason = reason)
+ self.event_func(e)
+
def connect_to_stream(queue, name, remote_name, host, port, protocol = None):
if protocol == None:
protocol = OutgoingXmppStream
p = protocol(queue.append, name, remote_name)
- factory = twisted.internet.protocol.ClientFactory()
+ factory = OutgoingXmppFactory(queue.append)
factory.protocol = lambda *args: p
reactor.connectTCP(host, port, factory)
--
1.5.6.3
More information about the Telepathy-commits
mailing list