예제 #1
0
파일: commands.py 프로젝트: louiz/poezio
    def rawxml(self, args):
        """
        /rawxml <xml stanza>
        """

        if not args:
            return

        stanza = args
        try:
            stanza = StanzaBase(self.core.xmpp, xml=ET.fromstring(stanza))
            if stanza.xml.tag == 'iq' and stanza.xml.attrib.get('type') in (
                    'get', 'set'):
                iq_id = stanza.xml.attrib.get('id')
                if not iq_id:
                    iq_id = self.core.xmpp.new_id()
                    stanza['id'] = iq_id

                def iqfunc(iq):
                    "handler for an iq reply"
                    self.core.information(str(iq), 'Iq')
                    self.core.xmpp.remove_handler('Iq %s' % iq_id)

                self.core.xmpp.register_handler(
                    Callback('Iq %s' % iq_id, StanzaPath('iq@id=%s' % iq_id),
                             iqfunc))
            stanza.send()
        except:
            self.core.information('Could not send custom stanza', 'Error')
            log.debug(
                '/rawxml: Could not send custom stanza (%s)',
                repr(stanza),
                exc_info=True)
예제 #2
0
    def rawxml(self, args):
        """
        /rawxml <xml stanza>
        """

        if not args:
            return

        stanza = args
        try:
            stanza = StanzaBase(self.core.xmpp, xml=ET.fromstring(stanza))
            if stanza.xml.tag == 'iq' and stanza.xml.attrib.get('type') in (
                    'get', 'set'):
                iq_id = stanza.xml.attrib.get('id')
                if not iq_id:
                    iq_id = self.core.xmpp.new_id()
                    stanza['id'] = iq_id

                def iqfunc(iq):
                    "handler for an iq reply"
                    self.core.information('%s' % iq, 'Iq')
                    self.core.xmpp.remove_handler('Iq %s' % iq_id)

                self.core.xmpp.register_handler(
                    Callback('Iq %s' % iq_id, StanzaPath('iq@id=%s' % iq_id),
                             iqfunc))
            stanza.send()
        except:
            self.core.information('Could not send custom stanza', 'Error')
            log.debug('/rawxml: Could not send custom stanza (%s)',
                      repr(stanza),
                      exc_info=True)
예제 #3
0
 def testError(self):
     """Test marking a stanza as an error."""
     stanza = StanzaBase()
     stanza['type'] = 'get'
     stanza.error()
     self.assertTrue(stanza['type'] == 'error',
                     "Stanza type is not 'error' after calling error()")
예제 #4
0
 def testError(self):
     """Test marking a stanza as an error."""
     stanza = StanzaBase()
     stanza['type'] = 'get'
     stanza.error()
     self.assertTrue(stanza['type'] == 'error',
         "Stanza type is not 'error' after calling error()")
예제 #5
0
    def testClear(self):
        """Test clearing a stanza."""
        stanza = StanzaBase()
        stanza['to'] = '*****@*****.**'
        stanza['payload'] = ET.Element("{foo}foo")
        stanza.clear()

        self.assertTrue(stanza['payload'] == [],
            "Stanza payload was not cleared after calling .clear()")
        self.assertTrue(str(stanza['to']) == "*****@*****.**",
            "Stanza attributes were not preserved after calling .clear()")
예제 #6
0
    def testClear(self):
        """Test clearing a stanza."""
        stanza = StanzaBase()
        stanza['to'] = '*****@*****.**'
        stanza['payload'] = ET.Element("{foo}foo")
        stanza.clear()

        self.assertTrue(stanza['payload'] == [],
            "Stanza payload was not cleared after calling .clear()")
        self.assertTrue(str(stanza['to']) == "*****@*****.**",
            "Stanza attributes were not preserved after calling .clear()")
예제 #7
0
    def testReply(self):
        """Test creating a reply stanza."""
        stanza = StanzaBase()
        stanza["to"] = "*****@*****.**"
        stanza["from"] = "*****@*****.**"
        stanza["payload"] = ET.Element("{foo}foo")

        stanza = stanza.reply()

        self.failUnless(str(stanza["to"] == "*****@*****.**"), "Stanza reply did not change 'to' attribute.")
        self.failUnless(stanza["payload"] == [], "Stanza reply did not empty stanza payload.")
예제 #8
0
    def testClear(self):
        """Test clearing a stanza."""
        stanza = StanzaBase()
        stanza["to"] = "*****@*****.**"
        stanza["payload"] = ET.Element("{foo}foo")
        stanza.clear()

        self.failUnless(stanza["payload"] == [], "Stanza payload was not cleared after calling .clear()")
        self.failUnless(
            str(stanza["to"]) == "*****@*****.**", "Stanza attributes were not preserved after calling .clear()"
        )
예제 #9
0
    def testReply(self):
        """Test creating a reply stanza."""
        stanza = StanzaBase()
        stanza['to'] = "*****@*****.**"
        stanza['from'] = "*****@*****.**"
        stanza['payload'] = ET.Element("{foo}foo")

        stanza = stanza.reply()

        self.assertTrue(str(stanza['to'] == "*****@*****.**"),
            "Stanza reply did not change 'to' attribute.")
        self.assertTrue(stanza['payload'] == [],
            "Stanza reply did not empty stanza payload.")
예제 #10
0
    def testReply(self):
        """Test creating a reply stanza."""
        stanza = StanzaBase()
        stanza['to'] = "*****@*****.**"
        stanza['from'] = "*****@*****.**"
        stanza['payload'] = ET.Element("{foo}foo")

        stanza = stanza.reply()

        self.assertTrue(str(stanza['to'] == "*****@*****.**"),
            "Stanza reply did not change 'to' attribute.")
        self.assertTrue(stanza['payload'] == [],
            "Stanza reply did not empty stanza payload.")
예제 #11
0
 def testTo(self):
     """Test the 'to' interface of StanzaBase."""
     stanza = StanzaBase()
     stanza['to'] = '*****@*****.**'
     self.assertTrue(
         str(stanza['to']) == '*****@*****.**',
         "Setting and retrieving stanza 'to' attribute did not work.")
예제 #12
0
 def testFrom(self):
     """Test the 'from' interface of StanzaBase."""
     stanza = StanzaBase()
     stanza['from'] = '*****@*****.**'
     self.failUnless(
         str(stanza['from']) == '*****@*****.**',
         "Setting and retrieving stanza 'from' attribute did not work.")
예제 #13
0
    def testPayload(self):
        """Test the 'payload' interface of StanzaBase."""
        stanza = StanzaBase()
        self.assertTrue(stanza['payload'] == [],
            "Empty stanza does not have an empty payload.")

        stanza['payload'] = ET.Element("{foo}foo")
        self.assertTrue(len(stanza['payload']) == 1,
            "Stanza contents and payload do not match.")

        stanza['payload'] = ET.Element('{bar}bar')
        self.assertTrue(len(stanza['payload']) == 2,
            "Stanza payload was not appended.")

        del stanza['payload']
        self.assertTrue(stanza['payload'] == [],
            "Stanza payload not cleared after deletion.")

        stanza['payload'] = [ET.Element('{foo}foo'),
                             ET.Element('{bar}bar')]
        self.assertTrue(len(stanza['payload']) == 2,
            "Adding multiple elements to stanza's payload did not work.")
예제 #14
0
파일: handlers.py 프로젝트: Perdu/poezio
def on_groupchat_invitation(self, message):
    """
    Mediated invitation received
    """
    jid = message['from']
    if jid.bare in self.pending_invites:
        return
    # there are 2 'x' tags in the messages, making message['x'] useless
    invite = StanzaBase(self.xmpp, xml=message.find('{http://jabber.org/protocol/muc#user}x/{http://jabber.org/protocol/muc#user}invite'))
    inviter = invite['from']
    reason = invite['reason']
    password = invite['password']
    msg = "You are invited to the room %s by %s" % (jid.full, inviter.full)
    if reason:
        msg += "because: %s" % reason
    if password:
        msg += ". The password is \"%s\"." % password
    self.information(msg, 'Info')
    if 'invite' in config.get('beep_on').split():
        curses.beep()
    logger.log_roster_change(inviter.full, 'invited you to %s' % jid.full)
    self.pending_invites[jid.bare] = inviter.full
예제 #15
0
 def testError(self):
     """Test marking a stanza as an error."""
     stanza = StanzaBase()
     stanza["type"] = "get"
     stanza.error()
     self.failUnless(stanza["type"] == "error", "Stanza type is not 'error' after calling error()")