Пример #1
0
 def testStaticMethods(self):
     self.assertEquals(xpath.matches("/foo/bar", self.e), True)
     self.assertEquals(xpath.queryForNodes("/foo/bar", self.e),
                       [self.bar1, self.bar2, self.bar4])
     self.assertEquals(xpath.queryForString("/foo", self.e), "somecontent")
     self.assertEquals(xpath.queryForStringList("/foo", self.e),
                       ["somecontent", "somemorecontent"])
Пример #2
0
    def on_invite(self, element):
        """
        Handler that responds to channel invites from other users. This will acknowledge
        the request by joining the room indicated in the xml payload.

        :param element: A <message/> element, instance of `twisted.words.xish.domish.Element`
        """
        channel = ''
        password = ''

        # NOTE: check for either http://xmpp.org/extensions/xep-0045.html#invite
        # or direct invites http://xmpp.org/extensions/xep-0249.html
        if xpath.matches('/message/x/invite', element):
            from_jid = jid.JID(element['from'])
            to_jid = jid.JID(element['to'])

            if from_jid.host == self.conference_host:
                channel = from_jid.userhost()
            else:
                channel = to_jid.userhost()

            # This is a hack around a unicode bug in twisted queryForString
            strings = xpath.queryForStringList('/message/x/password', element)
            if strings:
                password = strings[0]
        elif xpath.matches('/message/x[@xmlns="jabber:x:conference"]', element):
            # Direct invite
            x = xpath.queryForNodes('/message/x', element)[0]
            channel = x['jid']
            password = x.attributes.get('password', '')
        else:
            # Probably not an invite, but the overly greedy xpath matched it. Ignore.
            return

        self.join(channel, password=password)
 def testStaticMethods(self):
     self.assertEquals(xpath.matches("/foo/bar", self.e),
                       True)
     self.assertEquals(xpath.queryForNodes("/foo/bar", self.e),
                       [self.bar1, self.bar2, self.bar4])
     self.assertEquals(xpath.queryForString("/foo", self.e),
                       "somecontent")
     self.assertEquals(xpath.queryForStringList("/foo", self.e),
                       ["somecontent", "somemorecontent"])
 def test_staticMethods(self):
     """
     Test basic operation of the static methods.
     """
     self.assertEquals(xpath.matches("/foo/bar", self.e), True)
     self.assertEquals(
         xpath.queryForNodes("/foo/bar", self.e), [self.bar1, self.bar2, self.bar4, self.bar5, self.bar6, self.bar7]
     )
     self.assertEquals(xpath.queryForString("/foo", self.e), "somecontent")
     self.assertEquals(xpath.queryForStringList("/foo", self.e), ["somecontent", "somemorecontent"])
Пример #5
0
 def test_staticMethods(self):
     """
     Test basic operation of the static methods.
     """
     self.assertEqual(xpath.matches("/foo/bar", self.e), True)
     self.assertEqual(
         xpath.queryForNodes("/foo/bar", self.e),
         [self.bar1, self.bar2, self.bar4, self.bar5, self.bar6, self.bar7])
     self.assertEqual(xpath.queryForString("/foo", self.e), "somecontent")
     self.assertEqual(xpath.queryForStringList("/foo", self.e),
                      ["somecontent", "somemorecontent"])
Пример #6
0
    def parse_message(self, message):
        """
        Parses the message body from a <message/> element, ignoring any delayed messages.
        If a message is indeed a delayed message, an empty string is returned

        :param message: A <message/> element, instance of `twisted.words.xish.domish.Element`
        :returns: The contents of the message, empty string if the message is delayed
        """
        if xpath.matches('/message/delay', message):
            return u''

        # This is a hack around a unicode bug in twisted queryForString
        strings = xpath.queryForStringList('/message/body', message)
        if strings:
            return strings[0]
        return u''
Пример #7
0
    def parse_message(self, message):
        """
        Parses the message body from a <message/> element, ignoring any delayed messages.
        If a message is indeed a delayed message, an empty string is returned

        :param message: A <message/> element, instance of `twisted.words.xish.domish.Element`
        :returns: The contents of the message, empty string if the message is delayed
        """
        if xpath.matches('/message/delay', message):
            return u''

        # This is a hack around a unicode bug in twisted queryForString
        strings = xpath.queryForStringList('/message/body', message)
        if strings:
            return strings[0]
        return u''