Пример #1
0
    def __init__(self, host, port, jid, password):
        self.host = host
        self.port = port

        factory = component.componentFactory(jid, password)

        StreamManager.__init__(self, factory)
Пример #2
0
    def __init__(self, host, port, jid, password):
        self.host = host
        self.port = port

        factory = component.componentFactory(jid, password)

        StreamManager.__init__(self, factory)
Пример #3
0
class DeferredClientFactory(XmlStreamFactoryMixin, protocol.ClientFactory):
    protocol = xmlstream.XmlStream

    def __init__(self, jid, password):
        self.authenticator = client.XMPPAuthenticator(jid, password)
        XmlStreamFactoryMixin.__init__(self, self.authenticator)

        deferred = defer.Deferred()
        self.deferred = deferred

        self.addBootstrap(xmlstream.INIT_FAILED_EVENT, deferred.errback)

        class ConnectionInitializedHandler(XMPPHandler):
            def connectionInitialized(self):
                deferred.callback(None)

        self.streamManager = StreamManager(self)
        self.addHandler(ConnectionInitializedHandler())

    def clientConnectionFailed(self, connector, reason):
        self.deferred.errback(reason)

    def addHandler(self, handler):
        """
        Add a subprotocol handler to the stream manager.
        """
        self.streamManager.addHandler(handler)

    def removeHandler(self, handler):
        """
        Add a subprotocol handler to the stream manager.
        """
        self.streamManager.removeHandler(handler)
Пример #4
0
    def __init__(self, jid, password, host=None, port=5222):
        self.domain = jid.host
        self.host = host
        self.port = port

        factory = HybridClientFactory(jid, password)

        StreamManager.__init__(self, factory)
Пример #5
0
    def __init__(self, jid, password, host=None, port=5222):
        self.jid = jid
        self.domain = generic.prepareIDNName(jid.host)
        self.host = host
        self.port = port

        factory = HybridClientFactory(jid, password)

        StreamManager.__init__(self, factory)
Пример #6
0
    def __init__(self, jid, password, host=None, port=5222, requireTLS=True):
        self.jid = jid
        self.domain = jid.host.encode('idna')
        self.host = host
        self.port = port

        factory = HybridClientFactory(jid, password, requireTLS)

        StreamManager.__init__(self, factory)
Пример #7
0
    def __init__(self, reactor=None):
        class DummyFactory(object):
            def addBootstrap(self, event, fn):
                pass

        factory = DummyFactory()
        StreamManager.__init__(self, factory, reactor)
        self.stub = XmlStreamStub()
        self._connected(self.stub.xmlstream)
        self._authd(self.stub.xmlstream)
Пример #8
0
    def __init__(self, reactor=None):
        class DummyFactory(object):
            def addBootstrap(self, event, fn):
                pass

        factory = DummyFactory()
        StreamManager.__init__(self, factory, reactor)
        self.stub = XmlStreamStub()
        self._connected(self.stub.xmlstream)
        self._authd(self.stub.xmlstream)
Пример #9
0
    def _authd(self, xs):
        """
        Called when the stream has been initialized.

        Save the JID that we were assigned by the server, as the resource might
        differ from the JID we asked for. This is stored on the authenticator
        by its constituent initializers.
        """
        self.jid = self.factory.authenticator.jid
        StreamManager._authd(self, xs)
Пример #10
0
    def _authd(self, xs):
        """
        Called when the stream has been initialized.

        Save the JID that we were assigned by the server, as the resource might
        differ from the JID we asked for. This is stored on the authenticator
        by its constituent initializers.
        """
        self.jid = self.factory.authenticator.jid
        StreamManager._authd(self, xs)
Пример #11
0
    def _authd(self, xs):
        old_send = xs.send

        def send(obj):
            if domish.IElement.providedBy(obj) and not obj.getAttribute("from"):
                obj["from"] = self.xmlstream.thisEntity.full()
            old_send(obj)

        xs.send = send
        StreamManager._authd(self, xs)
Пример #12
0
    def _authd(self, xs):
        old_send = xs.send

        def send(obj):
            if domish.IElement.providedBy(obj) and \
                    not obj.getAttribute('from'):
                obj['from'] = self.xmlstream.thisEntity.full()
            old_send(obj)

        xs.send = send
        StreamManager._authd(self, xs)
Пример #13
0
    def __init__(self, host, port, domain, password, extra_handlers=[]):
        self.host = host
        self.port = port
        self._state = None
        factory = component.componentFactory(domain, password)

        StreamManager.__init__(self, factory)
        for handler in extra_handlers:
            handler.setHandlerParent(self)

        self._state = u'connecting'
        zr = getUtility(IZopeReactor)
        zr.reactor.callFromThread(self.connect)
Пример #14
0
    def __init__(self, host, port, domain, password, extra_handlers=[]):
        self.host = host
        self.port = port
        self._state = None
        factory = component.componentFactory(domain, password)

        StreamManager.__init__(self, factory)
        for handler in extra_handlers:
            handler.setHandlerParent(self)

        self._state = u'connecting'
        zr = getUtility(IZopeReactor)
        zr.reactor.callFromThread(self.connect)
Пример #15
0
    def __init__(self, jid, password):
        self.authenticator = client.XMPPAuthenticator(jid, password)
        XmlStreamFactoryMixin.__init__(self, self.authenticator)

        deferred = defer.Deferred()
        self.deferred = deferred

        self.addBootstrap(xmlstream.INIT_FAILED_EVENT, deferred.errback)

        class ConnectionInitializedHandler(XMPPHandler):
            def connectionInitialized(self):
                deferred.callback(None)

        self.streamManager = StreamManager(self)
        self.addHandler(ConnectionInitializedHandler())
Пример #16
0
class DeferredClientFactory(generic.DeferredXmlStreamFactory):
    def __init__(self, jid, password):
        authenticator = client.XMPPAuthenticator(jid, password)
        generic.DeferredXmlStreamFactory.__init__(self, authenticator)
        self.streamManager = StreamManager(self)

    def addHandler(self, handler):
        """
        Add a subprotocol handler to the stream manager.
        """
        self.streamManager.addHandler(handler)

    def removeHandler(self, handler):
        """
        Add a subprotocol handler to the stream manager.
        """
        self.streamManager.removeHandler(handler)
Пример #17
0
class DeferredClientFactory(generic.DeferredXmlStreamFactory):
    def __init__(self, jid, password):
        authenticator = client.XMPPAuthenticator(jid, password)
        generic.DeferredXmlStreamFactory.__init__(self, authenticator)
        self.streamManager = StreamManager(self)

    def addHandler(self, handler):
        """
        Add a subprotocol handler to the stream manager.
        """
        self.streamManager.addHandler(handler)

    def removeHandler(self, handler):
        """
        Add a subprotocol handler to the stream manager.
        """
        self.streamManager.removeHandler(handler)
Пример #18
0
    def _authd(self, xs):
        #Set JID
        self.jid = self.xmlstream.thisEntity

        #Patch send to always include from.
        old_send = xs.send

        def send(obj):
            if domish.IElement.providedBy(obj) and \
                    not obj.getAttribute('from'):
                obj['from'] = self.jid.full()
            old_send(obj)

        xs.send = send

        StreamManager._authd(self, xs)
        self._state = u'authenticated'
Пример #19
0
    def _authd(self, xs):
        #Set JID
        self.jid = self.xmlstream.thisEntity

        #Patch send to always include from.
        old_send = xs.send

        def send(obj):
            if domish.IElement.providedBy(obj) and \
                    not obj.getAttribute('from'):
                obj['from'] = self.jid.full()
            old_send(obj)

        xs.send = send

        StreamManager._authd(self, xs)
        self._state = u'authenticated'
Пример #20
0
    def _authd(self, xs):
        """
        Called when stream initialization has completed.

        This replaces the C{send} method of the C{XmlStream} instance
        that represents the current connection so that outgoing stanzas
        always have a from attribute set to the JID of the component.
        """
        old_send = xs.send

        def send(obj):
            if domish.IElement.providedBy(obj) and \
                    not obj.getAttribute('from'):
                obj['from'] = self.xmlstream.thisEntity.full()
            old_send(obj)

        xs.send = send
        StreamManager._authd(self, xs)
Пример #21
0
    def _authd(self, xs):
        """
        Called when stream initialization has completed.

        This replaces the C{send} method of the C{XmlStream} instance
        that represents the current connection so that outgoing stanzas
        always have a from attribute set to the JID of the component.
        """
        old_send = xs.send

        def send(obj):
            if domish.IElement.providedBy(obj) and \
                    not obj.getAttribute('from'):
                obj['from'] = self.xmlstream.thisEntity.full()
            old_send(obj)

        xs.send = send
        StreamManager._authd(self, xs)
Пример #22
0
    def __init__(self, jid, password, extra_handlers=[],
                 host='localhost', port=5222):
        jid.resource = randomResource()
        self.jid = jid
        self.domain = jid.host
        self.host = host
        self.port = port
        self._state = None
        self._connector = None

        factory = client.HybridClientFactory(jid, password)

        # Setup StreamManager
        StreamManager.__init__(self, factory)
        for handler in extra_handlers:
            handler.setHandlerParent(self)

        self._state = u'connecting'
        zr = getUtility(IZopeReactor)
        zr.reactor.callFromThread(self.connect)
Пример #23
0
 def test_DiscoInfo(self):
     factory = XmlStreamFactory()
     sm = StreamManager(factory)
     disco.DiscoHandler().setHandlerParent(sm)
     DiscoResponder().setHandlerParent(sm)
     xs = factory.buildProtocol(None)
     output = []
     xs.send = output.append
     xs.connectionMade()
     xs.dispatch(xs, "//event/stream/authd")
     xs.dataReceived("<stream>")
     xs.dataReceived("""<iq from='*****@*****.**' to='example.com'
                            type='get'>
                          <query xmlns='%s'/>
                        </iq>""" % NS_DISCO_INFO)
     reply = output[0]
     self.assertEqual(NS_DISCO_INFO, reply.query.uri)
     self.assertEqual(NS_DISCO_INFO, reply.query.identity.uri)
     self.assertEqual('dummy', reply.query.identity['category'])
     self.assertEqual('generic', reply.query.identity['type'])
     self.assertEqual('Generic Dummy Entity', reply.query.identity['name'])
     self.assertEqual(NS_DISCO_INFO, reply.query.feature.uri)
     self.assertEqual('jabber:iq:version', reply.query.feature['var'])
Пример #24
0
 def __init__(self, jid, password):
     authenticator = client.XMPPAuthenticator(jid, password)
     generic.DeferredXmlStreamFactory.__init__(self, authenticator)
     self.streamManager = StreamManager(self)
Пример #25
0
 def _authd(self, xs):
     #Save the JID that we were assigned by the server, as the resource
     # might differ from the JID we asked for.
     self.jid = self.factory.authenticator.jid
     StreamManager._authd(self, xs)
     self._state = u'authenticated'
Пример #26
0
 def __init__(self, jid, password):
     authenticator = client.XMPPAuthenticator(jid, password)
     generic.DeferredXmlStreamFactory.__init__(self, authenticator)
     self.streamManager = StreamManager(self)