How to use the slixmpp.xmlstream.ET function in slixmpp

To help you get started, we’ve selected a few slixmpp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github poezio / slixmpp / tests / test_stanza_gmail.py View on Github external
def testMailBox(self):
        """Testing reading from Gmail mailbox result"""

        # Use the example from Google's documentation at
        # http://code.google.com/apis/talk/jep_extensions/gmail.html#notifications
        xml = ET.fromstring("""
          
            
              
                
                  
                  
                  
github poezio / slixmpp / slixmpp / stanza / rootstanza.py View on Github external
reply.send()
        elif isinstance(e, IqTimeout):
            reply = self.reply()
            reply['error']['condition'] = 'remote-server-timeout'
            reply['error']['type'] = 'wait'
            log.warning('You should catch IqTimeout exceptions')
            reply.send()
        elif isinstance(e, XMPPError):
            # We raised this deliberately
            reply = self.reply(clear=e.clear)
            reply['error']['condition'] = e.condition
            reply['error']['text'] = e.text
            reply['error']['type'] = e.etype
            if e.extension is not None:
                # Extended error tag
                extxml = ET.Element("{%s}%s" % (e.extension_ns, e.extension),
                                    e.extension_args)
                reply['error'].append(extxml)
            reply.send()
        else:
            # We probably didn't raise this on purpose, so send an error stanza
            reply = self.reply()
            reply['error']['condition'] = 'undefined-condition'
            reply['error']['text'] = "Slixmpp got into trouble."
            reply['error']['type'] = 'cancel'
            reply.send()
            # log the error
            log.exception('Error handling {%s}%s stanza',
                          self.namespace, self.name)
            # Finally raise the exception to a global exception handler
            self.stream.exception(e)
github poezio / slixmpp / slixmpp / plugins / xep_0045 / stanza.py View on Github external
def set_item_attr(self, attr, value: str):
        item = self.xml.find(f'{{{NS_USER}}}item')
        if item is None:
            item = ET.Element(f'{{{NS_USER}}}item')
            self.xml.append(item)
        item.attrib[attr] = value
        return item
github poezio / slixmpp / slixmpp / features / feature_session / stanza.py View on Github external
def set_optional(self, value):
        if value:
            optional = ET.Element('{%s}optional' % self.namespace)
            self.xml.append(optional)
        else:
            self.del_optional()
github poezio / slixmpp / slixmpp / plugins / google / auth / stanza.py View on Github external
def setup(self, xml):
        """Don't create XML for the plugin."""
        self.xml = ET.Element('')
github poezio / slixmpp / slixmpp / plugins / xep_0071 / stanza.py View on Github external
def set_body(self, content, lang=None):
        if lang is None:
            lang = self.get_lang()
        self.del_body(lang)
        if lang == '*':
            for sublang, subcontent in content.items():
                self.set_body(subcontent, sublang)
        else:
            if isinstance(content, type(ET.Element('test'))):
                content = unicode(ET.tostring(content))
            else:
                content = unicode(content)
            header = '
github poezio / slixmpp / slixmpp / plugins / google / settings / stanza.py View on Github external
def set_display_name(self, value):
        self._del_setting(setting)
        if value:
            xml = ET.Element('{%s}%s' % (self.namespace, 'displayname'))
            xml.attrib['value'] = value
            self.xml.append(xml)
github poezio / slixmpp / slixmpp / plugins / xep_0108 / stanza.py View on Github external
def set_value(self, value):
        self.del_value()
        general = value
        specific = None
        if isinstance(value, tuple) or isinstance(value, list):
            general = value[0]
            specific = value[1]

        if general in self.general:
            gen_xml = ET.Element('{%s}%s' % (self.namespace, general))
            if specific:
                spec_xml = ET.Element('{%s}%s' % (self.namespace, specific))
                if specific in self.specific:
                    gen_xml.append(spec_xml)
                else:
                    raise ValueError('Unknown specific activity')
            self.xml.append(gen_xml)
        else:
            raise ValueError('Unknown general activity')
github poezio / slixmpp / slixmpp / plugins / xep_0257 / stanza.py View on Github external
def set_users(self, values):
        users = self.xml.find('{%s}users' % self.namespace)
        if users is None:
            users = ET.Element('{%s}users' % self.namespace)
            self.xml.append(users)
        for resource in values:
            res = ET.Element('{%s}resource' % self.namespace)
            res.text = resource
            users.append(res)
github poezio / slixmpp / slixmpp / plugins / xep_0313 / stanza.py View on Github external
def set_always(self, value):
        self._set_sub_text('always', '', keep=True)
        always = self.xml.find('{%s}always' % self.namespace)
        always.clear()

        if not isinstance(value, (list, set)):
            value = [value]

        for jid in value:
            jid_xml = ET.Element('{%s}jid' % self.namespace)
            jid_xml.text = str(jid)
            always.append(jid_xml)