Exemplo n.º 1
0
    def testSetItem(self):
        """Test assigning to stanza interfaces."""

        class TestStanza(ElementBase):
            name = "foo"
            namespace = "foo"
            interfaces = set(('bar', 'baz', 'qux'))
            sub_interfaces = set(('baz',))

            def setQux(self, value):
                pass

        class TestStanzaPlugin(ElementBase):
            name = "foobar"
            namespace = "foo"
            plugin_attrib = "foobar"
            interfaces = set(('foobar',))

        register_stanza_plugin(TestStanza, TestStanzaPlugin)

        stanza = TestStanza()

        stanza['bar'] = 'attribute!'
        stanza['baz'] = 'element!'
        stanza['qux'] = 'overridden'
        stanza['foobar'] = 'plugin'

        self.check(stanza, """
          <foo xmlns="foo" bar="attribute!">
            <baz>element!</baz>
            <foobar foobar="plugin" />
          </foo>
        """)
Exemplo n.º 2
0
    def testSubStanzas(self):
        """Test manipulating substanzas of a stanza object."""

        class TestSubStanza(ElementBase):
            name = "foobar"
            namespace = "foo"
            interfaces = set(('qux',))

        class TestStanza(ElementBase):
            name = "foo"
            namespace = "foo"
            interfaces = set(('bar', 'baz'))

        register_stanza_plugin(TestStanza, TestSubStanza, iterable=True)

        stanza = TestStanza()
        substanza1 = TestSubStanza()
        substanza2 = TestSubStanza()
        substanza1['qux'] = 'a'
        substanza2['qux'] = 'b'

        # Test appending substanzas
        self.failUnless(len(stanza) == 0,
            "Incorrect empty stanza size.")

        stanza.append(substanza1)
        self.check(stanza, """
          <foo xmlns="foo">
            <foobar qux="a" />
          </foo>
        """, use_values=False)
        self.failUnless(len(stanza) == 1,
            "Incorrect stanza size with 1 substanza.")

        stanza.append(substanza2)
        self.check(stanza, """
          <foo xmlns="foo">
            <foobar qux="a" />
            <foobar qux="b" />
          </foo>
        """, use_values=False)
        self.failUnless(len(stanza) == 2,
            "Incorrect stanza size with 2 substanzas.")

        # Test popping substanzas
        stanza.pop(0)
        self.check(stanza, """
          <foo xmlns="foo">
            <foobar qux="b" />
          </foo>
        """, use_values=False)

        # Test iterating over substanzas
        stanza.append(substanza1)
        results = []
        for substanza in stanza:
            results.append(substanza['qux'])
        self.failUnless(results == ['b', 'a'],
            "Iteration over substanzas failed: %s." % str(results))
Exemplo n.º 3
0
    def testGetMultiAttrib(self):
        """Test retrieving multi_attrib substanzas."""

        class TestStanza(ElementBase):
            name = 'foo'
            namespace = 'foo'
            interfaces = set()

        class TestMultiStanza1(ElementBase):
            name = 'bar'
            namespace = 'bar'
            plugin_attrib = name
            plugin_multi_attrib = 'bars'

        class TestMultiStanza2(ElementBase):
            name = 'baz'
            namespace = 'baz'
            plugin_attrib = name
            plugin_multi_attrib = 'bazs'

        register_stanza_plugin(TestStanza, TestMultiStanza1, iterable=True)
        register_stanza_plugin(TestStanza, TestMultiStanza2, iterable=True)

        stanza = TestStanza()
        stanza.append(TestMultiStanza1())
        stanza.append(TestMultiStanza2())
        stanza.append(TestMultiStanza1())
        stanza.append(TestMultiStanza2())

        self.check(stanza, """
          <foo xmlns="foo">
            <bar xmlns="bar" />
            <baz xmlns="baz" />
            <bar xmlns="bar" />
            <baz xmlns="baz" />
          </foo>
        """, use_values=False)

        bars = stanza['bars']
        bazs = stanza['bazs']

        for bar in bars:
            self.check(bar, """
              <bar xmlns="bar" />
            """)

        for baz in bazs:
            self.check(baz, """
              <baz xmlns="baz" />
            """)

        self.assertEqual(len(bars), 2,
                "Wrong number of <bar /> stanzas: %s" % len(bars))
        self.assertEqual(len(bazs), 2,
                "Wrong number of <baz /> stanzas: %s" % len(bazs))
Exemplo n.º 4
0
 def connect(self, jid, password):
     if self.connection == None:
         self.connection = ClientXMPP(jid, password)
     register_stanza_plugin(Message, WylioStanza)
     self.connection.add_event_handler("connected", self.connected)
     self.connection.add_event_handler("disconnected", self.disconnected)
     self.connection.add_event_handler("failed_auth", self.failed_auth)
     self.connection.add_event_handler("session_start", self.start)
     self.connection.add_event_handler("message", self.message)
     print "connect"
     self.connection.connect()
     self.connection.process(block=True)
     print "connected"
Exemplo n.º 5
0
 def connect(self, jid, password):
     self.jid = jid
     if self.connection == None:
         self.connection = ClientXMPP(jid, password)
     register_stanza_plugin(Message, WylioStanza)
     register_stanza_plugin(WylioStanza, ValueStanza)
     self.connection.add_event_handler("connected", self.connected)
     self.connection.add_event_handler("session_start", self.start)
     self.connection.add_event_handler("failed_auth", self.failed)
     self.connection.add_event_handler("disconnected", self.disconnected)
     self.connection.add_event_handler("message", self.message)
     self.connection.connect(("talk.google.com", 5222))
     self.connection.process()
Exemplo n.º 6
0
	def connect(self,jid,password):
		if self.connection == None:
			self.connection = ClientXMPP(jid, password)
		register_stanza_plugin (Message, WylioStanza)
		self.connection.add_event_handler("connected", self.connected)
		self.connection.add_event_handler("disconnected", self.disconnected)
		self.connection.add_event_handler("failed_auth", self.failed_auth)
		self.connection.add_event_handler("session_start", self.start)
		self.connection.add_event_handler("message", self.message)
		print "connect"
		self.connection.connect()
		self.connection.process(block=True)
		print "connected"
Exemplo n.º 7
0
 def connect(self, jid, password):
     self.jid = jid
     if self.connection == None:
         self.connection = ClientXMPP(jid, password)
     register_stanza_plugin(Message, WylioStanza)
     register_stanza_plugin(WylioStanza, ValueStanza)
     self.connection.add_event_handler("connected", self.connected)
     self.connection.add_event_handler("session_start", self.start)
     self.connection.add_event_handler("failed_auth", self.failed)
     self.connection.add_event_handler("disconnected", self.disconnected)
     self.connection.add_event_handler("message", self.message)
     self.connection.connect(('talk.google.com', 5222))
     self.connection.process()
Exemplo n.º 8
0
    def testSetMultiAttrib(self):
        """Test setting multi_attrib substanzas."""

        class TestStanza(ElementBase):
            name = 'foo'
            namespace = 'foo'
            interfaces = set()

        class TestMultiStanza1(ElementBase):
            name = 'bar'
            namespace = 'bar'
            plugin_attrib = name
            plugin_multi_attrib = 'bars'

        class TestMultiStanza2(ElementBase):
            name = 'baz'
            namespace = 'baz'
            plugin_attrib = name
            plugin_multi_attrib = 'bazs'

        register_stanza_plugin(TestStanza, TestMultiStanza1, iterable=True)
        register_stanza_plugin(TestStanza, TestMultiStanza2, iterable=True)

        stanza = TestStanza()
        stanza['bars'] = [TestMultiStanza1(), TestMultiStanza1()]
        stanza['bazs'] = [TestMultiStanza2(), TestMultiStanza2()]

        self.check(stanza, """
          <foo xmlns="foo">
            <bar xmlns="bar" />
            <bar xmlns="bar" />
            <baz xmlns="baz" />
            <baz xmlns="baz" />
          </foo>
        """, use_values=False)

        self.assertEqual(len(stanza['substanzas']), 4,
            "Wrong number of substanzas: %s" % len(stanza['substanzas']))

        stanza['bars'] = [TestMultiStanza1()]

        self.check(stanza, """
          <foo xmlns="foo">
            <baz xmlns="baz" />
            <baz xmlns="baz" />
            <bar xmlns="bar" />
          </foo>
        """, use_values=False)

        self.assertEqual(len(stanza['substanzas']), 3,
            "Wrong number of substanzas: %s" % len(stanza['substanzas']))
Exemplo n.º 9
0
    def plugin_init(self):
        register_stanza_plugin(RPCQuery, stanza.MethodTimeout)

        self.xmpp.register_handler(
            Callback(
                "RPC Call",
                MatchXPath(
                    "{%s}iq/{%s}query/{%s}methodTimeout"
                    % (self.xmpp.default_ns, RPCQuery.namespace, RPCQuery.namespace)
                ),
                self._handle_method_timeout,
            )
        )

        self.xmpp.add_event_handler("jabber_rpc_method_timeout", self._on_jabber_rpc_method_timeout, threaded=True)
Exemplo n.º 10
0
    def testGetItem(self):
        """Test accessing stanza interfaces."""

        class TestStanza(ElementBase):
            name = "foo"
            namespace = "foo"
            interfaces = set(('bar', 'baz', 'qux'))
            sub_interfaces = set(('baz',))

            def getQux(self):
              return 'qux'

        class TestStanzaPlugin(ElementBase):
            name = "foobar"
            namespace = "foo"
            plugin_attrib = "foobar"
            interfaces = set(('fizz',))

        register_stanza_plugin(TestStanza, TestStanza, iterable=True)
        register_stanza_plugin(TestStanza, TestStanzaPlugin)

        stanza = TestStanza()
        substanza = TestStanza()
        stanza.append(substanza)
        stanza.setStanzaValues({'bar': 'a',
                                'baz': 'b',
                                'qux': 42,
                                'foobar': {'fizz': 'c'}})

        # Test non-plugin interfaces
        expected = {'substanzas': [substanza],
                    'bar': 'a',
                    'baz': 'b',
                    'qux': 'qux',
                    'meh': ''}
        for interface, value in expected.items():
            result = stanza[interface]
            self.failUnless(result == value,
                "Incorrect stanza interface access result: %s" % result)

        # Test plugin interfaces
        self.failUnless(isinstance(stanza['foobar'], TestStanzaPlugin),
                        "Incorrect plugin object result.")
        self.failUnless(stanza['foobar']['fizz'] == 'c',
                        "Incorrect plugin subvalue result.")
Exemplo n.º 11
0
    def testGetStanzaValues(self):
        """Test getStanzaValues using plugins and substanzas."""

        class TestStanzaPlugin(ElementBase):
            name = "foo2"
            namespace = "foo"
            interfaces = set(('bar', 'baz'))
            plugin_attrib = "foo2"

        class TestSubStanza(ElementBase):
            name = "subfoo"
            namespace = "foo"
            interfaces = set(('bar', 'baz'))

        class TestStanza(ElementBase):
            name = "foo"
            namespace = "foo"
            interfaces = set(('bar', 'baz'))

        register_stanza_plugin(TestStanza, TestStanzaPlugin, iterable=True)

        stanza = TestStanza()
        stanza['bar'] = 'a'
        stanza['foo2']['baz'] = 'b'
        substanza = TestSubStanza()
        substanza['bar'] = 'c'
        stanza.append(substanza)

        values = stanza.getStanzaValues()
        expected = {'lang': '',
                    'bar': 'a',
                    'baz': '',
                    'foo2': {'lang': '',
                             'bar': '',
                             'baz': 'b'},
                    'substanzas': [{'__childtag__': '{foo}foo2',
                                    'lang': '',
                                    'bar': '',
                                    'baz': 'b'},
                                   {'__childtag__': '{foo}subfoo',
                                    'lang': '',
                                    'bar': 'c',
                                    'baz': ''}]}
        self.failUnless(values == expected,
            "Unexpected stanza values:\n%s\n%s" % (str(expected), str(values)))
Exemplo n.º 12
0
    def __init__(self, jid, password, room, nick, OI_URL):
        sleekxmpp.ClientXMPP.__init__(self, jid, password)
        #sleekxmpp.ssl_version = ssl.PROTOCOL_SSLv3

        self.jid
        self.room = room
        self.nick = "OPPSD.SEIT.OIMONITOR-{}/v1.0(http://n.a;[email protected])".format(nick)
        self.url = OI_URL
        
        register_stanza_plugin(Message, Stanza)
        self.registerHandler(Callback('NWWS-OI/X Message', StanzaPath('{%s}message/{%s}x' % (self.default_ns,self.default_ns)),self.onX))

        
        # The session_start event will be triggered when
        # the bot establishes its connection with the server
        # and the XML streams are ready for use. We want to
        # listen for this event so that we we can initialize
        # our roster.
        self.add_event_handler("session_start", self.start, threaded=True)

        # The groupchat_message event is triggered whenever a message
        # stanza is received from any chat room. If you also also
        # register a handler for the 'message' event, MUC messages
        # will be processed by both handlers.
        #self.add_event_handler("groupchat_message", self.muc_message)
        self.add_event_handler("custom_action", self.muc_message)
        
        self.add_event_handler("presence_available", self.muc_online)
        
        self.add_event_handler("presence_unavailable", self.muc_offline)
        self.add_event_handler("presence_unsubscribed", self.muc_offline)
        
        self.add_event_handler("roster_update", self.muc_roster_update)
        
        self.add_event_handler("connected", self.muc_connected)
        self.add_event_handler("disconnected", self.muc_disconnected)
        
        self.add_event_handler("Ping", self.ping_xmpp)
        
        self.member_list = []
        self.member_list_prev = []
        self.member_list_complete = False
        self.product_count = 0
Exemplo n.º 13
0
    def testExtension(self):
        """Testing using is_extension."""

        class TestStanza(ElementBase):
            name = "foo"
            namespace = "foo"
            interfaces = set(('bar', 'baz'))

        class TestExtension(ElementBase):
            name = 'extended'
            namespace = 'foo'
            plugin_attrib = name
            interfaces = set((name,))
            is_extension = True

            def set_extended(self, value):
                self.xml.text = value

            def get_extended(self):
                return self.xml.text

            def del_extended(self):
                self.parent().xml.remove(self.xml)

        register_stanza_plugin(TestStanza, TestExtension)

        stanza = TestStanza()
        stanza['extended'] = 'testing'

        self.check(stanza, """
          <foo xmlns="foo">
            <extended>testing</extended>
          </foo>
        """)

        self.failUnless(stanza['extended'] == 'testing',
                "Could not retrieve stanza extension value.")

        del stanza['extended']
        self.check(stanza, """
          <foo xmlns="foo" />
        """)
Exemplo n.º 14
0
    def testKeys(self):
        """Test extracting interface names from a stanza object."""

        class TestStanza(ElementBase):
            name = "foo"
            namespace = "foo"
            interfaces = set(('bar', 'baz'))
            plugin_attrib = 'qux'

        register_stanza_plugin(TestStanza, TestStanza)

        stanza = TestStanza()

        self.failUnless(set(stanza.keys()) == set(('lang', 'bar', 'baz')),
            "Returned set of interface keys does not match expected.")

        stanza.enable('qux')

        self.failUnless(set(stanza.keys()) == set(('lang', 'bar', 'baz', 'qux')),
            "Incorrect set of interface and plugin keys.")
Exemplo n.º 15
0
    def testDelItem(self):
        """Test deleting stanza interface values."""

        class TestStanza(ElementBase):
            name = "foo"
            namespace = "foo"
            interfaces = set(('bar', 'baz', 'qux'))
            sub_interfaces = set(('bar',))

            def delQux(self):
                pass

        class TestStanzaPlugin(ElementBase):
            name = "foobar"
            namespace = "foo"
            plugin_attrib = "foobar"
            interfaces = set(('foobar',))

        register_stanza_plugin(TestStanza, TestStanzaPlugin)

        stanza = TestStanza()
        stanza['bar'] = 'a'
        stanza['baz'] = 'b'
        stanza['qux'] = 'c'
        stanza['foobar']['foobar'] = 'd'

        self.check(stanza, """
          <foo xmlns="foo" baz="b" qux="c">
            <bar>a</bar>
            <foobar foobar="d" />
          </foo>
        """)

        del stanza['bar']
        del stanza['baz']
        del stanza['qux']
        del stanza['foobar']

        self.check(stanza, """
          <foo xmlns="foo" qux="c" />
        """)
Exemplo n.º 16
0
    def __init__(self, sjid, password, room, nick, leaderboard):
        """Initialize EcheLOn."""
        sleekxmpp.ClientXMPP.__init__(self, sjid, password)
        self.whitespace_keepalive = False

        self.sjid = sleekxmpp.jid.JID(sjid)
        self.room = room
        self.nick = nick

        self.leaderboard = leaderboard
        self.report_manager = ReportManager(self.leaderboard)

        register_stanza_plugin(Iq, BoardListXmppPlugin)
        register_stanza_plugin(Iq, GameReportXmppPlugin)
        register_stanza_plugin(Iq, ProfileXmppPlugin)

        self.register_handler(
            Callback('Iq Boardlist', StanzaPath('iq@type=get/boardlist'),
                     self._iq_board_list_handler))
        self.register_handler(
            Callback('Iq GameReport', StanzaPath('iq@type=set/gamereport'),
                     self._iq_game_report_handler))
        self.register_handler(
            Callback('Iq Profile', StanzaPath('iq@type=get/profile'),
                     self._iq_profile_handler))

        self.add_event_handler('session_start', self._session_start)
        self.add_event_handler('muc::%s::got_online' % self.room,
                               self._muc_online)
        self.add_event_handler('muc::%s::got_offline' % self.room,
                               self._muc_offline)
        self.add_event_handler('groupchat_message', self._muc_message)
Exemplo n.º 17
0
    def plugin_init(self):
        self.xep = '0009'
        self.description = 'Jabber-RPC'
        #self.stanza = sleekxmpp.plugins.xep_0009.stanza

        register_stanza_plugin(Iq, RPCQuery)
        register_stanza_plugin(RPCQuery, MethodCall)
        register_stanza_plugin(RPCQuery, MethodResponse)

        self.xmpp.registerHandler(
            Callback('RPC Call', MatchXPath('{%s}iq/{%s}query/{%s}methodCall' % (self.xmpp.default_ns, RPCQuery.namespace, RPCQuery.namespace)),
            self._handle_method_call)
        )
        self.xmpp.registerHandler(
            Callback('RPC Call', MatchXPath('{%s}iq/{%s}query/{%s}methodResponse' % (self.xmpp.default_ns, RPCQuery.namespace, RPCQuery.namespace)),
            self._handle_method_response)
        )
        self.xmpp.registerHandler(
            Callback('RPC Call', MatchXPath('{%s}iq/{%s}error' % (self.xmpp.default_ns, self.xmpp.default_ns)),
            self._handle_error)
        )
        self.xmpp.add_event_handler('jabber_rpc_method_call', self._on_jabber_rpc_method_call)
        self.xmpp.add_event_handler('jabber_rpc_method_response', self._on_jabber_rpc_method_response)
        self.xmpp.add_event_handler('jabber_rpc_method_fault', self._on_jabber_rpc_method_fault)
        self.xmpp.add_event_handler('jabber_rpc_error', self._on_jabber_rpc_error)
        self.xmpp.add_event_handler('error', self._handle_error)
Exemplo n.º 18
0
    def testOverrides(self):
        """Test using interface overrides."""

        class TestStanza(ElementBase):
            name = "foo"
            namespace = "foo"
            interfaces = set(('bar', 'baz'))

        class TestOverride(ElementBase):
            name = 'overrider'
            namespace = 'foo'
            plugin_attrib = name
            interfaces = set(('bar',))
            overrides = ['set_bar']

            def setup(self, xml):
                # Don't create XML for the plugin
                self.xml = ET.Element('')

            def set_bar(self, value):
                if not value.startswith('override-'):
                    self.parent()._set_attr('bar', 'override-%s' % value)
                else:
                    self.parent()._set_attr('bar', value)

        stanza = TestStanza()
        stanza['bar'] = 'foo'
        self.check(stanza, """
          <foo xmlns="foo" bar="foo" />
        """)

        register_stanza_plugin(TestStanza, TestOverride, overrides=True)

        stanza = TestStanza()
        stanza['bar'] = 'foo'
        self.check(stanza, """
          <foo xmlns="foo" bar="override-foo" />
        """)
Exemplo n.º 19
0
    def testSetStanzaValues(self):
        """Test using setStanzaValues with substanzas and plugins."""

        class TestStanzaPlugin(ElementBase):
            name = "pluginfoo"
            namespace = "foo"
            interfaces = set(('bar', 'baz'))
            plugin_attrib = "plugin_foo"

        class TestStanzaPlugin2(ElementBase):
            name = "pluginfoo2"
            namespace = "foo"
            interfaces = set(('bar', 'baz'))
            plugin_attrib = "plugin_foo2"

        class TestSubStanza(ElementBase):
            name = "subfoo"
            namespace = "foo"
            interfaces = set(('bar', 'baz'))

        class TestStanza(ElementBase):
            name = "foo"
            namespace = "foo"
            interfaces = set(('bar', 'baz'))

        register_stanza_plugin(TestStanza, TestSubStanza, iterable=True)
        register_stanza_plugin(TestStanza, TestStanzaPlugin)
        register_stanza_plugin(TestStanza, TestStanzaPlugin2)

        stanza = TestStanza()
        values = {'bar': 'a',
                  'baz': '',
                  'plugin_foo': {'bar': '',
                                 'baz': 'b'},
                  'plugin_foo2': {'bar': 'd',
                                  'baz': 'e'},
                  'substanzas': [{'__childtag__': '{foo}subfoo',
                                  'bar': 'c',
                                  'baz': ''}]}
        stanza.values = values

        self.check(stanza, """
          <foo xmlns="foo" bar="a">
            <pluginfoo baz="b" />
            <pluginfoo2 bar="d" baz="e" />
            <subfoo bar="c" />
          </foo>
        """)
Exemplo n.º 20
0
    def plugin_init(self):
        self.xep = '0009'
        self.description = 'Jabber-RPC'
        #self.stanza = sleekxmpp.plugins.xep_0009.stanza

        register_stanza_plugin(Iq, RPCQuery)
        register_stanza_plugin(RPCQuery, MethodCall)
        register_stanza_plugin(RPCQuery, MethodResponse)

        self.xmpp.registerHandler(
            Callback(
                'RPC Call',
                MatchXPath('{%s}iq/{%s}query/{%s}methodCall' %
                           (self.xmpp.default_ns, RPCQuery.namespace,
                            RPCQuery.namespace)), self._handle_method_call))
        self.xmpp.registerHandler(
            Callback(
                'RPC Call',
                MatchXPath('{%s}iq/{%s}query/{%s}methodResponse' %
                           (self.xmpp.default_ns, RPCQuery.namespace,
                            RPCQuery.namespace)),
                self._handle_method_response))
        self.xmpp.registerHandler(
            Callback(
                'RPC Call',
                MatchXPath('{%s}iq/{%s}error' %
                           (self.xmpp.default_ns, self.xmpp.default_ns)),
                self._handle_error))
        self.xmpp.add_event_handler('jabber_rpc_method_call',
                                    self._on_jabber_rpc_method_call)
        self.xmpp.add_event_handler('jabber_rpc_method_response',
                                    self._on_jabber_rpc_method_response)
        self.xmpp.add_event_handler('jabber_rpc_method_fault',
                                    self._on_jabber_rpc_method_fault)
        self.xmpp.add_event_handler('jabber_rpc_error',
                                    self._on_jabber_rpc_error)
        self.xmpp.add_event_handler('error', self._handle_error)
Exemplo n.º 21
0
    def __init__(self, config):
        """
        Create a ConfigComponent.

        Arguments:
            config      -- The XML contents of the config file.
            config_file -- The XML config file object itself.
        """
        ComponentXMPP.__init__(self, config['jid'],
                                     config['secret'],
                                     config['server'],
                                     config['port'], use_jc_ns=False)

        custom_stanzas = {
            DeviceInfo: self.intamac_device_info,
            IntamacStream: self.intamac_stream,
            IntamacFirmwareUpgrade: self.intamac_firmware_upgrade,
            IntamacAPI: self.intamac_api,
            IntamacEvent: self.intamac_event
        }

        for custom_stanza, handler in custom_stanzas.items():
            register_stanza_plugin(Iq, custom_stanza)
            self.register_handler(
                Callback(custom_stanza.plugin_attrib,
                    StanzaPath('iq@type=set/{}'.format(custom_stanza.plugin_attrib)),
                    handler)
                )

        # The lines of code below configure support for the xep-0203
        # to be able to receive and process specific presence delayed
        # stanzas. I don't think this is the right way to do this,
        # as just registering the plugin should be enough to accomplish
        # the expected behavior. Something to look at later on. 
        from sleekxmpp.plugins.xep_0203 import Delay

        register_stanza_plugin(Presence, Delay)

        self.register_handler(
            Callback(Delay.name,
                StanzaPath('presence/{}'.format(Delay.plugin_attrib)),
                self.delay)
            )

        # The following piece of code shows how a normal registration
        # process for a single stanza plugin takes place: 
        '''
        self.register_handler(
            Callback('iq_api',
                StanzaPath('iq@type=set/iq_intamacapi'),
                self.intamac_device_info))
        
        '''

        # The following lines of code take care of registering 
        # specific listener methods for every kind of stanza that
        # we want to process. The code will be cleaned once a final
        # decision regarding the best way to deal with this is 
        # rechaed. 

        self.add_event_handler("session_start", self.start, threaded=True)
        #self.add_event_handler('presence', self.presence, threaded=threaded)
        #self.add_event_handler('iq_intamacdeviceinfo', self.intamac_device_info, threaded=True)
        self.add_event_handler('presence_subscribe', self.subscribe, threaded=threaded)
        self.add_event_handler('presence_subscribed', self.subscribed, threaded=threaded)  
        self.add_event_handler('delay', self.delay, threaded=threaded)  
Exemplo n.º 22
0
from sleekxmpp.xmlstream.handler.callback import Callback
from sleekxmpp.xmlstream.matcher.xpath import MatchXPath
from sleekxmpp.xmlstream.matcher import StanzaPath

from sleek.custom_stanzas import (DeviceInfo, 
                                IntamacStream, 
                                IntamacFirmwareUpgrade, 
                                IntamacAPI, 
                                IntamacEvent, 
                                Config
                                )

import atexit 


register_stanza_plugin(Config, Roster)

# The three lines of code below serve testing purposes. They should
# not be present in production code. 

threaded = True

messages = []

connections = ['c42f90b752dd@use-xmpp-01/camera', 
                'c42f90b752dd@use-xmpp-01', 
                'user0@use-xmpp-01']


class ConfigComponent(ComponentXMPP):
Exemplo n.º 23
0
 def setUp(self):
     register_stanza_plugin(Iq, RPCQuery)
     register_stanza_plugin(RPCQuery, MethodCall)
     register_stanza_plugin(RPCQuery, MethodResponse)
Exemplo n.º 24
0
 def setUp(self):
     register_stanza_plugin(Iq, RPCQuery)
     register_stanza_plugin(RPCQuery, MethodCall)
     register_stanza_plugin(RPCQuery, MethodResponse)
Exemplo n.º 25
0
    def testMatch(self):
        """Test matching a stanza against an XPath expression."""

        class TestSubStanza(ElementBase):
            name = "sub"
            namespace = "baz"
            interfaces = set(('attrib',))

        class TestStanza(ElementBase):
            name = "foo"
            namespace = "foo"
            interfaces = set(('bar','baz', 'qux'))
            sub_interfaces = set(('qux',))

            def setQux(self, value):
                self._set_sub_text('qux', text=value)

            def getQux(self):
                return self._get_sub_text('qux')

        class TestStanzaPlugin(ElementBase):
            name = "plugin"
            namespace = "http://test/slash/bar"
            interfaces = set(('attrib',))

        register_stanza_plugin(TestStanza, TestSubStanza, iterable=True)
        register_stanza_plugin(TestStanza, TestStanzaPlugin)

        stanza = TestStanza()
        self.failUnless(stanza.match("foo"),
            "Stanza did not match its own tag name.")

        self.failUnless(stanza.match("{foo}foo"),
            "Stanza did not match its own namespaced name.")

        stanza['bar'] = 'a'
        self.failUnless(stanza.match("foo@bar=a"),
            "Stanza did not match its own name with attribute value check.")

        stanza['baz'] = 'b'
        self.failUnless(stanza.match("foo@bar=a@baz=b"),
            "Stanza did not match its own name with multiple attributes.")

        stanza['qux'] = 'c'
        self.failUnless(stanza.match("foo/qux"),
            "Stanza did not match with subelements.")

        stanza['qux'] = ''
        self.failUnless(stanza.match("foo/qux") == False,
            "Stanza matched missing subinterface element.")

        self.failUnless(stanza.match("foo/bar") == False,
            "Stanza matched nonexistent element.")

        stanza['plugin']['attrib'] = 'c'
        self.failUnless(stanza.match("foo/plugin@attrib=c"),
            "Stanza did not match with plugin and attribute.")

        self.failUnless(stanza.match("foo/{http://test/slash/bar}plugin"),
            "Stanza did not match with namespaced plugin.")

        substanza = TestSubStanza()
        substanza['attrib'] = 'd'
        stanza.append(substanza)
        self.failUnless(stanza.match("foo/sub@attrib=d"),
            "Stanza did not match with substanzas and attribute.")

        self.failUnless(stanza.match("foo/{baz}sub"),
            "Stanza did not match with namespaced substanza.")
Exemplo n.º 26
0
import sleekxmpp
from sleekxmpp import roster
from sleekxmpp.componentxmpp import ComponentXMPP
from sleekxmpp.stanza.roster import Roster
from sleekxmpp.xmlstream import ElementBase
from sleekxmpp.xmlstream.stanzabase import ET, registerStanzaPlugin, register_stanza_plugin
from sleekxmpp.jid import JID
from sleekxmpp.stanza.iq import Iq
from sleekxmpp.xmlstream.handler.callback import Callback
from sleekxmpp.xmlstream.matcher.xpath import MatchXPath
from sleekxmpp.xmlstream.matcher import StanzaPath

from custom_stanzas import IntamacHandler, Config


register_stanza_plugin(Config, Roster)
register_stanza_plugin(Iq, IntamacHandler)



class ConfigComponent(ComponentXMPP):

    """
    A simple SleekXMPP component that uses an external XML
    file to store its configuration data. To make testing
    that the component works, it will also echo messages sent
    to it.
    """

    def __init__(self, config):
        """