def setUp(self): factory = xmlstream.XmlStreamFactory(xmlstream.Authenticator()) self.clock = task.Clock() self.streamManager = subprotocols.StreamManager(factory, self.clock) self.xmlstream = factory.buildProtocol(None) self.transport = proto_helpers.StringTransport() self.xmlstream.transport = self.transport self.request = IQGetStanza()
def HybridClientFactory(jid, password): """ Client factory for XMPP 1.0. This is similar to L{client.XMPPClientFactory} but also tries non-SASL autentication. """ a = HybridAuthenticator(jid, password) return xmlstream.XmlStreamFactory(a)
def __init__(self, network, token, peer=None): a = KontalkXMPPAuthenticator(network, token) f = xmlstream.XmlStreamFactory(a) f.addBootstrap(xmlstream.STREAM_CONNECTED_EVENT, self.connected) f.addBootstrap(xmlstream.STREAM_END_EVENT, self.disconnected) f.addBootstrap(xmlstream.STREAM_AUTHD_EVENT, self.authenticated) f.addBootstrap(xmlstream.INIT_FAILED_EVENT, self.init_failed) reactor.connectTCP('localhost', 5222, f) self.network = network self.peer = peer
def componentFactory(componentid, password): """ XML stream factory for external server-side components. @param componentid: JID of the component. @type componentid: L{unicode} @param password: password used to authenticate to the server. @type password: C{str} """ a = ConnectComponentAuthenticator(componentid, password) return xmlstream.XmlStreamFactory(a)
def test_sendNotInitialized(self): """ Test send when the stream is connected but not yet initialized. The data should be cached until the XML stream has been initialized. """ factory = xmlstream.XmlStreamFactory(xmlstream.Authenticator()) sm = xmlstream.StreamManager(factory) xs = factory.buildProtocol(None) xs.transport = proto_helpers.StringTransport() xs.connectionMade() xs.dataReceived("<stream:stream xmlns='jabber:client' " "xmlns:stream='http://etherx.jabber.org/streams' " "from='example.com' id='12345'>") sm.send("<presence/>") self.assertEqual(b"", xs.transport.value()) self.assertEqual("<presence/>", sm._packetQueue[0])
def test_sendInitialized(self): """ Test send when the stream has been initialized. The data should be sent directly over the XML stream. """ factory = xmlstream.XmlStreamFactory(xmlstream.Authenticator()) sm = xmlstream.StreamManager(factory) xs = factory.buildProtocol(None) xs.transport = proto_helpers.StringTransport() xs.connectionMade() xs.dataReceived("<stream:stream xmlns='jabber:client' " "xmlns:stream='http://etherx.jabber.org/streams' " "from='example.com' id='12345'>") xs.dispatch(xs, "//event/stream/authd") sm.send("<presence/>") self.assertEqual(b"<presence/>", xs.transport.value())
def XMPPClientFactory(jid, password): """ Client factory for XMPP 1.0 (only). This returns a L{xmlstream.XmlStreamFactory} with an L{XMPPAuthenticator} object to perform the stream initialization steps (such as authentication). @see: The notes at L{XMPPAuthenticator} describe how the L{jid} and L{password} parameters are to be used. @param jid: Jabber ID to connect with. @type jid: L{jid.JID} @param password: password to authenticate with. @type password: C{unicode} @return: XML stream factory. @rtype: L{xmlstream.XmlStreamFactory} """ a = XMPPAuthenticator(jid, password) return xmlstream.XmlStreamFactory(a)
def test_sendDisconnected(self): """ Test send after XML stream disconnection. The data should be cached until a new XML stream has been established and initialized. """ factory = xmlstream.XmlStreamFactory(xmlstream.Authenticator()) sm = xmlstream.StreamManager(factory) handler = DummyXMPPHandler() sm.addHandler(handler) xs = factory.buildProtocol(None) xs.connectionMade() xs.transport = proto_helpers.StringTransport() xs.connectionLost(None) sm.send("<presence/>") self.assertEqual(b"", xs.transport.value()) self.assertEqual("<presence/>", sm._packetQueue[0])
def register_account(self, server): reactor.callLater(10, self._failed, "timeout") username = utils.generate_username() self._jid = "%s@%s" % (username, server) self._password = utils.generate_password() jid_obj = jid.JID(self._jid) if self._verbose: print "Connecting to", jid_obj.host a = RegisterAuthenticator(jid_obj, self._password) factory = xmlstream.XmlStreamFactory(a) factory.maxRetries = 0 factory.clientConnectionFailed = self._failed factory.addBootstrap(STREAM_CONNECTED_EVENT, self._connected) factory.addBootstrap(xmlstream.INIT_FAILED_EVENT, self._failed) factory.addBootstrap(RegisterInitializer.REGISTER_SUCCEEDED_EVENT, self._registered) factory.addBootstrap(RegisterInitializer.REGISTER_FAILED_EVENT, self._failed) reactor.connectTCP(jid_obj.host, 5222, factory, timeout=4) return self._deferred
def basicClientFactory(jid, secret): a = BasicAuthenticator(jid, secret) return xmlstream.XmlStreamFactory(a)
def componentFactory(componentid, password): a = ConnectComponentAuthenticator(componentid, password) return xmlstream.XmlStreamFactory(a)