Here are the examples of the python api twisted.words.protocols.jabber.xmlstream.Authenticator taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
35 Examples
3
Example 1
Project: wokkel Source File: test_server.py
def setUp(self):
self.output = []
self.xmlstream = xmlstream.XmlStream(xmlstream.Authenticator())
self.xmlstream.thisEntity = jid.JID('example.org')
self.xmlstream.otherEntity = jid.JID('example.com')
self.xmlstream.send = self.output.append
self.router = component.Router()
self.service = server.ServerService(self.router,
secret='mysecret',
domain='example.org')
self.service.xmlstream = self.xmlstream
3
Example 2
Project: wokkel Source File: test_subprotocols.py
def test_makeConnection(self):
"""
Test that makeConnection saves the XML stream and calls connectionMade.
"""
class TestXMPPHandler(subprotocols.XMPPHandler):
def connectionMade(self):
self.doneMade = True
handler = TestXMPPHandler()
xs = xmlstream.XmlStream(xmlstream.Authenticator())
handler.makeConnection(xs)
self.assertTrue(handler.doneMade)
self.assertIdentical(xs, handler.xmlstream)
3
Example 3
Project: wokkel Source File: test_subprotocols.py
def test_connectionLost(self):
"""
Test that connectionLost forgets the XML stream.
"""
handler = subprotocols.XMPPHandler()
xs = xmlstream.XmlStream(xmlstream.Authenticator())
handler.makeConnection(xs)
handler.connectionLost(Exception())
self.assertIdentical(None, handler.xmlstream)
3
Example 4
Project: wokkel Source File: test_subprotocols.py
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()
3
Example 5
def test_connected(self):
"""
Test that protocol handlers have their connectionMade method called
when the XML stream is connected.
"""
sm = self.streamManager
handler = DummyXMPPHandler()
handler.setHandlerParent(sm)
xs = xmlstream.XmlStream(xmlstream.Authenticator())
sm._connected(xs)
self.assertEquals(1, handler.doneMade)
self.assertEquals(0, handler.doneInitialized)
self.assertEquals(0, handler.doneLost)
3
Example 6
Project: wokkel Source File: test_subprotocols.py
def test_connectedLogTrafficFalse(self):
"""
Test raw data functions unset when logTraffic is set to False.
"""
sm = self.streamManager
handler = DummyXMPPHandler()
handler.setHandlerParent(sm)
xs = xmlstream.XmlStream(xmlstream.Authenticator())
sm._connected(xs)
self.assertIdentical(None, xs.rawDataInFn)
self.assertIdentical(None, xs.rawDataOutFn)
3
Example 7
Project: wokkel Source File: test_subprotocols.py
def test_connectedLogTrafficTrue(self):
"""
Test raw data functions set when logTraffic is set to True.
"""
sm = self.streamManager
sm.logTraffic = True
handler = DummyXMPPHandler()
handler.setHandlerParent(sm)
xs = xmlstream.XmlStream(xmlstream.Authenticator())
sm._connected(xs)
self.assertNotIdentical(None, xs.rawDataInFn)
self.assertNotIdentical(None, xs.rawDataOutFn)
3
Example 8
def test_authd(self):
"""
Test that protocol handlers have their connectionInitialized method
called when the XML stream is initialized.
"""
sm = self.streamManager
handler = DummyXMPPHandler()
handler.setHandlerParent(sm)
xs = xmlstream.XmlStream(xmlstream.Authenticator())
sm._authd(xs)
self.assertEquals(0, handler.doneMade)
self.assertEquals(1, handler.doneInitialized)
self.assertEquals(0, handler.doneLost)
3
Example 9
def test_disconnectedReason(self):
"""
A L{STREAM_END_EVENT} results in L{StreamManager} firing the handlers
L{connectionLost} methods, passing a L{failure.Failure} reason.
"""
sm = self.streamManager
handler = FailureReasonXMPPHandler()
handler.setHandlerParent(sm)
xmlstream.XmlStream(xmlstream.Authenticator())
sm._disconnected(failure.Failure(Exception("no reason")))
self.assertEquals(True, handler.gotFailureReason)
3
Example 10
Project: wokkel Source File: test_subprotocols.py
def test_addHandlerConnected(self):
"""
Adding a handler when connected doesn't call connectionInitialized.
"""
sm = self.streamManager
xs = xmlstream.XmlStream(xmlstream.Authenticator())
sm._connected(xs)
handler = DummyXMPPHandler()
handler.setHandlerParent(sm)
self.assertEquals(1, handler.doneMade)
self.assertEquals(0, handler.doneInitialized)
self.assertEquals(0, handler.doneLost)
3
Example 11
def test_addHandlerInitialized(self):
"""
Test the addition of a protocol handler after the stream
have been initialized.
Make sure that the handler will have the connected stream
passed via C{makeConnection} and have C{connectionInitialized}
called.
"""
sm = self.streamManager
xs = xmlstream.XmlStream(xmlstream.Authenticator())
sm._connected(xs)
sm._authd(xs)
handler = DummyXMPPHandler()
handler.setHandlerParent(sm)
self.assertEquals(1, handler.doneMade)
self.assertEquals(1, handler.doneInitialized)
self.assertEquals(0, handler.doneLost)
3
Example 12
Project: wokkel Source File: test_subprotocols.py
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 = subprotocols.StreamManager(factory)
xs = factory.buildProtocol(None)
xs.transport = proto_helpers.StringTransport()
xs.connectionMade()
xs.dataReceived(b"<stream:stream xmlns='jabber:client' "
b"xmlns:stream='http://etherx.jabber.org/streams' "
b"from='example.com' id='12345'>")
xs.dispatch(xs, "//event/stream/authd")
sm.send("<presence/>")
self.assertEquals(b"<presence/>", xs.transport.value())
3
Example 13
Project: wokkel Source File: test_subprotocols.py
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 = subprotocols.StreamManager(factory)
xs = factory.buildProtocol(None)
xs.transport = proto_helpers.StringTransport()
xs.connectionMade()
xs.dataReceived(b"<stream:stream xmlns='jabber:client' "
b"xmlns:stream='http://etherx.jabber.org/streams' "
b"from='example.com' id='12345'>")
sm.send("<presence/>")
self.assertEquals(b"", xs.transport.value())
self.assertEquals("<presence/>", sm._packetQueue[0])
3
Example 14
def setUp(self):
self.output = []
self.authenticator = xmlstream.Authenticator()
self.authenticator.password = 'secret'
self.xmlstream = xmlstream.XmlStream(self.authenticator)
self.xmlstream.namespace = 'test:component'
self.xmlstream.send = self.output.append
self.xmlstream.connectionMade()
self.xmlstream.dataReceived(
"<stream:stream xmlns='test:component' "
"xmlns:stream='http://etherx.jabber.org/streams' "
"from='example.com' id='12345' version='1.0'>")
self.xmlstream.sid = u'12345'
self.init = component.ComponentInitiatingInitializer(self.xmlstream)
3
Example 15
def setUp(self):
self.output = []
self.authenticator = xmlstream.Authenticator()
self.xmlstream = xmlstream.XmlStream(self.authenticator)
self.xmlstream.send = self.output.append
self.xmlstream.connectionMade()
self.xmlstream.dataReceived("<stream:stream xmlns='jabber:client' "
"xmlns:stream='http://etherx.jabber.org/streams' "
"from='example.com' id='12345' version='1.0'>")
self.init = DummySASLInitiatingInitializer(self.xmlstream)
3
Example 16
Project: SubliminalCollaborator Source File: test_jabbersasl.py
def setUp(self):
self.output = []
self.authenticator = xmlstream.Authenticator()
self.xmlstream = xmlstream.XmlStream(self.authenticator)
self.xmlstream.send = self.output.append
self.xmlstream.connectionMade()
self.xmlstream.dataReceived("<stream:stream xmlns='jabber:client' "
"xmlns:stream='http://etherx.jabber.org/streams' "
"from='example.com' id='12345' version='1.0'>")
self.init = sasl.SASLInitiatingInitializer(self.xmlstream)
3
Example 17
Project: SubliminalCollaborator Source File: test_jabberxmlstream.py
def setUp(self):
"""
Set up XmlStream and several observers.
"""
self.gotStreamStart = False
self.gotStreamEnd = False
self.gotStreamError = False
xs = xmlstream.XmlStream(xmlstream.Authenticator())
xs.addObserver('//event/stream/start', self.onStreamStart)
xs.addObserver('//event/stream/end', self.onStreamEnd)
xs.addObserver('//event/stream/error', self.onStreamError)
xs.makeConnection(proto_helpers.StringTransportWithDisconnection())
xs.transport.protocol = xs
xs.namespace = 'testns'
xs.version = (1, 0)
self.xmlstream = xs
3
Example 18
def test_connected(self):
"""
Test that protocol handlers have their connectionMade method called
when the XML stream is connected.
"""
sm = self.streamManager
handler = DummyXMPPHandler()
handler.setHandlerParent(sm)
xs = xmlstream.XmlStream(xmlstream.Authenticator())
sm._connected(xs)
self.assertEqual(1, handler.doneMade)
self.assertEqual(0, handler.doneInitialized)
self.assertEqual(0, handler.doneLost)
3
Example 19
def test_authd(self):
"""
Test that protocol handlers have their connectionInitialized method
called when the XML stream is initialized.
"""
sm = self.streamManager
handler = DummyXMPPHandler()
handler.setHandlerParent(sm)
xs = xmlstream.XmlStream(xmlstream.Authenticator())
sm._authd(xs)
self.assertEqual(0, handler.doneMade)
self.assertEqual(1, handler.doneInitialized)
self.assertEqual(0, handler.doneLost)
3
Example 20
def test_disconnected(self):
"""
Test that protocol handlers have their connectionLost method
called when the XML stream is disconnected.
"""
sm = self.streamManager
handler = DummyXMPPHandler()
handler.setHandlerParent(sm)
xs = xmlstream.XmlStream(xmlstream.Authenticator())
sm._disconnected(xs)
self.assertEqual(0, handler.doneMade)
self.assertEqual(0, handler.doneInitialized)
self.assertEqual(1, handler.doneLost)
3
Example 21
Project: SubliminalCollaborator Source File: test_jabberxmlstream.py
Function: test_disconnectedreason
Function: test_disconnectedreason
def test_disconnectedReason(self):
"""
A L{STREAM_END_EVENT} results in L{StreamManager} firing the handlers
L{connectionLost} methods, passing a L{failure.Failure} reason.
"""
sm = self.streamManager
handler = FailureReasonXMPPHandler()
handler.setHandlerParent(sm)
xs = xmlstream.XmlStream(xmlstream.Authenticator())
sm._disconnected(failure.Failure(Exception("no reason")))
self.assertEqual(True, handler.gotFailureReason)
3
Example 22
Project: SubliminalCollaborator Source File: test_jabberxmlstream.py
Function: test_addhandlerinitialized
Function: test_addhandlerinitialized
def test_addHandlerInitialized(self):
"""
Test the addition of a protocol handler after the stream
have been initialized.
Make sure that the handler will have the connected stream
passed via C{makeConnection} and have C{connectionInitialized}
called.
"""
sm = self.streamManager
xs = xmlstream.XmlStream(xmlstream.Authenticator())
sm._connected(xs)
sm._authd(xs)
handler = DummyXMPPHandler()
handler.setHandlerParent(sm)
self.assertEqual(1, handler.doneMade)
self.assertEqual(1, handler.doneInitialized)
self.assertEqual(0, handler.doneLost)
3
Example 23
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("<presence/>", xs.transport.value())
3
Example 24
Project: SubliminalCollaborator Source File: test_jabberxmlstream.py
Function: test_sendnotinitialized
Function: test_sendnotinitialized
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("", xs.transport.value())
self.assertEqual("<presence/>", sm._packetQueue[0])
0
Example 25
Project: wokkel Source File: test_subprotocols.py
def test_addHandlerConnectedNested(self):
"""
Adding a handler in connectionMade doesn't cause 2nd call.
"""
class NestingHandler(DummyXMPPHandler):
nestedHandler = None
def connectionMade(self):
DummyXMPPHandler.connectionMade(self)
self.nestedHandler = DummyXMPPHandler()
self.nestedHandler.setHandlerParent(self.parent)
sm = self.streamManager
xs = xmlstream.XmlStream(xmlstream.Authenticator())
handler = NestingHandler()
handler.setHandlerParent(sm)
sm._connected(xs)
self.assertEquals(1, handler.doneMade)
self.assertEquals(0, handler.doneInitialized)
self.assertEquals(0, handler.doneLost)
self.assertEquals(1, handler.nestedHandler.doneMade)
self.assertEquals(0, handler.nestedHandler.doneInitialized)
self.assertEquals(0, handler.nestedHandler.doneLost)
0
Example 26
Project: wokkel Source File: test_subprotocols.py
def test_addHandlerInitializedNested(self):
"""
Adding a handler in connectionInitialized doesn't cause 2nd call.
"""
class NestingHandler(DummyXMPPHandler):
nestedHandler = None
def connectionInitialized(self):
DummyXMPPHandler.connectionInitialized(self)
self.nestedHandler = DummyXMPPHandler()
self.nestedHandler.setHandlerParent(self.parent)
sm = self.streamManager
xs = xmlstream.XmlStream(xmlstream.Authenticator())
handler = NestingHandler()
handler.setHandlerParent(sm)
sm._connected(xs)
sm._authd(xs)
self.assertEquals(1, handler.doneMade)
self.assertEquals(1, handler.doneInitialized)
self.assertEquals(0, handler.doneLost)
self.assertEquals(1, handler.nestedHandler.doneMade)
self.assertEquals(1, handler.nestedHandler.doneInitialized)
self.assertEquals(0, handler.nestedHandler.doneLost)
0
Example 27
Project: wokkel Source File: test_subprotocols.py
def test_addHandlerConnectionLostNested(self):
"""
Adding a handler in connectionLost doesn't call connectionLost there.
"""
class NestingHandler(DummyXMPPHandler):
nestedHandler = None
def connectionLost(self, reason):
DummyXMPPHandler.connectionLost(self, reason)
self.nestedHandler = DummyXMPPHandler()
self.nestedHandler.setHandlerParent(self.parent)
sm = self.streamManager
xs = xmlstream.XmlStream(xmlstream.Authenticator())
handler = NestingHandler()
handler.setHandlerParent(sm)
sm._connected(xs)
sm._authd(xs)
sm._disconnected(xs)
self.assertEquals(1, handler.doneMade)
self.assertEquals(1, handler.doneInitialized)
self.assertEquals(1, handler.doneLost)
self.assertEquals(0, handler.nestedHandler.doneMade)
self.assertEquals(0, handler.nestedHandler.doneInitialized)
self.assertEquals(0, handler.nestedHandler.doneLost)
0
Example 28
Project: wokkel Source File: test_subprotocols.py
def test_sendNotConnected(self):
"""
Test send when there is no established XML stream.
The data should be cached until an XML stream has been established and
initialized.
"""
factory = xmlstream.XmlStreamFactory(xmlstream.Authenticator())
sm = subprotocols.StreamManager(factory)
handler = DummyXMPPHandler()
sm.addHandler(handler)
xs = factory.buildProtocol(None)
xs.transport = proto_helpers.StringTransport()
sm.send("<presence/>")
self.assertEquals(b"", xs.transport.value())
self.assertEquals("<presence/>", sm._packetQueue[0])
xs.connectionMade()
self.assertEquals(b"", xs.transport.value())
self.assertEquals("<presence/>", sm._packetQueue[0])
xs.dataReceived(b"<stream:stream xmlns='jabber:client' "
b"xmlns:stream='http://etherx.jabber.org/streams' "
b"from='example.com' id='12345'>")
xs.dispatch(xs, "//event/stream/authd")
self.assertEquals(b"<presence/>", xs.transport.value())
self.assertFalse(sm._packetQueue)
0
Example 29
Project: wokkel Source File: test_subprotocols.py
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 = subprotocols.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.assertEquals(b"", xs.transport.value())
self.assertEquals("<presence/>", sm._packetQueue[0])
0
Example 30
def __init__(self):
self.output = []
self.xmlstream = xmlstream.XmlStream(xmlstream.Authenticator())
self.xmlstream.send = self.output.append
0
Example 31
def setUp(self):
a = xmlstream.Authenticator()
xs = xmlstream.XmlStream(a)
self.init = client.CheckVersionInitializer(xs)
0
Example 32
def setUp(self):
self.authenticator = xmlstream.Authenticator()
self.xmlstream = xmlstream.XmlStream(self.authenticator)
0
Example 33
def setUp(self):
self.xmlstream = xmlstream.XmlStream(xmlstream.Authenticator())
self.init = TestFeatureInitializer(self.xmlstream)
0
Example 34
def test_sendNotConnected(self):
"""
Test send when there is no established XML stream.
The data should be cached until an 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.transport = proto_helpers.StringTransport()
sm.send("<presence/>")
self.assertEqual("", xs.transport.value())
self.assertEqual("<presence/>", sm._packetQueue[0])
xs.connectionMade()
self.assertEqual("", xs.transport.value())
self.assertEqual("<presence/>", sm._packetQueue[0])
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")
self.assertEqual("<presence/>", xs.transport.value())
self.assertFalse(sm._packetQueue)
0
Example 35
Project: SubliminalCollaborator Source File: test_jabberxmlstream.py
Function: test_send_disconnected
Function: test_send_disconnected
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("", xs.transport.value())
self.assertEqual("<presence/>", sm._packetQueue[0])