コード例 #1
0
ファイル: register.py プロジェクト: lucasmbaia/python-xmpp
    def response_first_deploy(self,
                              ito=None,
                              ifrom=None,
                              iq_id=None,
                              success=None,
                              response=None,
                              error=None):
        iq = self.xmpp.Iq()
        iq['id'] = iq_id
        iq['to'] = ito
        iq['from'] = ifrom

        if success:
            query = ET.Element('{jabber:iq:docker}query')
            result = ET.Element('deploy')
            result.text = response
            query.append(result)

            iq['type'] = 'result'
            iq.append(query)
        else:
            iq['query'] = 'jabber:iq:docker'
            iq['type'] = 'error'
            iq['error'] = 'cancel'
            iq['error']['text'] = unicode(error)

        print(iq)
        iq.send(now=True)
コード例 #2
0
ファイル: register.py プロジェクト: lucasmbaia/python-xmpp
    def request_first_deploy(self,
                             ito=None,
                             ifrom=None,
                             name=None,
                             key=None,
                             user=None):
        iq = self.xmpp.Iq()
        iq['id'] = 'first-deploy-' + iq['id']
        iq['type'] = 'get'
        iq['to'] = ito
        iq['from'] = ifrom

        query = ET.Element('{jabber:iq:docker}query')
        req_name = ET.Element('name')
        req_name.text = name
        req_key = ET.Element('key')
        req_key.text = key
        req_user = ET.Element('user')
        req_user.text = user

        query.append(req_name)
        query.append(req_key)
        query.append(req_user)

        iq.append(query)

        return iq.send(now=True, timeout=120)
コード例 #3
0
ファイル: register.py プロジェクト: lucasmbaia/python-xmpp
    def response_get_name_pods(self,
                               ito=None,
                               ifrom=None,
                               success=None,
                               response=None,
                               error=None):
        iq = self.xmpp.Iq()
        iq['id'] = 'name-pods'
        iq['to'] = ito
        iq['from'] = ifrom

        if success:
            query = ET.Element('{jabber:iq:docker}query')
            result = ET.Element('name')
            result.text = response
            query.append(result)

            iq['type'] = 'result'
            iq.append(query)
        else:
            iq['query'] = 'jabber:iq:docker'
            iq['type'] = 'error'
            iq['error'] = 'cancel'
            iq['error']['text'] = unicode(error)

        iq.send(now=True)
コード例 #4
0
ファイル: register.py プロジェクト: lucasmbaia/python-xmpp
    def _send_request(self,
                      ito=None,
                      ifrom=None,
                      action=None,
                      timeout=None,
                      elements=None):
        logging.info('Send IQ to: %s, from: %s, action: %s, elements: %s' %
                     (ito, ifrom, action, elements))

        iq = self.xmpp.Iq()

        if action is not None:
            iq['id'] = action + '-' + iq['id']

        iq['type'] = 'get'
        iq['to'] = ito
        iq['from'] = ifrom

        if elements is not None:
            query = ET.Element('{jabber:iq:docker}query')

            for key in elements.keys():
                element = ET.Element(key)
                element.text = str(elements[key])

                query.append(element)

            iq.append(query)
        else:
            iq['query'] = 'jabber:iq:docker'

        return iq.send(now=True, timeout=timeout)
コード例 #5
0
 def testItemsEvent(self):
     """Testing multiple message/pubsub_event/items/item"""
     msg = self.Message()
     item = pubsub.EventItem()
     item2 = pubsub.EventItem()
     pl = ET.Element('{http://netflint.net/protocol/test}test', {
         'failed': '3',
         'passed': '24'
     })
     pl2 = ET.Element('{http://netflint.net/protocol/test-other}test', {
         'total': '27',
         'failed': '3'
     })
     item2['payload'] = pl2
     item['payload'] = pl
     item['id'] = 'abc123'
     item2['id'] = '123abc'
     msg['pubsub_event']['items'].append(item)
     msg['pubsub_event']['items'].append(item2)
     msg['pubsub_event']['items']['node'] = 'cheese'
     msg['type'] = 'normal'
     self.check(
         msg, """
       <message type="normal">
         <event xmlns="http://jabber.org/protocol/pubsub#event">
           <items node="cheese">
             <item id="abc123">
               <test xmlns="http://netflint.net/protocol/test" failed="3" passed="24" />
             </item>
             <item id="123abc">
               <test xmlns="http://netflint.net/protocol/test-other" failed="3" total="27" />
             </item>
           </items>
         </event>
       </message>""")
コード例 #6
0
ファイル: stanza.py プロジェクト: E-Tahta/sleekxmpp
 def set_receipt(self, value):
     self.del_receipt()
     if value:
         parent = self.parent()
         xml = ET.Element("{%s}received" % self.namespace)
         xml.attrib['id'] = value
         parent.append(xml)
コード例 #7
0
 def testPayload(self):
     """Test setting Iq stanza payload."""
     iq = self.Iq()
     iq.setPayload(ET.Element('{test}tester'))
     self.check(iq, """
       <iq id="0">
         <tester xmlns="test" />
       </iq>
     """, use_values=False)
コード例 #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
ファイル: test_stanza_base.py プロジェクト: E-Tahta/sleekxmpp
    def testReply(self):
        """Test creating a reply stanza."""
        stanza = StanzaBase()
        stanza['to'] = "*****@*****.**"
        stanza['from'] = "*****@*****.**"
        stanza['payload'] = ET.Element("{foo}foo")

        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.")
コード例 #10
0
    def testPayload(self):
        """Test the 'payload' interface of StanzaBase."""
        stanza = StanzaBase()
        self.failUnless(stanza['payload'] == [],
            "Empty stanza does not have an empty payload.")

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

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

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

        stanza['payload'] = [ET.Element('{foo}foo'),
                             ET.Element('{bar}bar')]
        self.failUnless(len(stanza['payload']) == 2,
            "Adding multiple elements to stanza's payload did not work.")
コード例 #11
0
ファイル: register.py プロジェクト: lucasmbaia/python-xmpp
    def _send_response(self,
                       ito=None,
                       ifrom=None,
                       success=None,
                       response=None,
                       error=None,
                       iq_response=None,
                       element=None):
        iq = self.xmpp.Iq()
        iq['id'] = iq_response
        iq['to'] = ito
        iq['from'] = ifrom

        if success:
            logging.info(
                'Send IQ response to: %s, from: %s, iq: %s, response: %s' %
                (ito, ifrom, iq_response, response))
            query = ET.Element('{jabber:iq:docker}query')

            if element is not None:
                result = ET.Element(element)
                result.text = response
                query.append(result)

            iq['type'] = 'result'
            iq.append(query)
        else:
            logging.error(
                'Send IQ response to: %s, from: %s, iq: %s, error: %s' %
                (ito, ifrom, iq_response, error))
            iq['query'] = 'jabber:iq:docker'
            iq['type'] = 'error'
            iq['error'] = 'cancel'
            iq['error']['text'] = unicode(error)

        iq.send(now=True)
コード例 #12
0
ファイル: xpath.py プロジェクト: stlcours/emesene
    def match(self, xml):
        """
        Compare a stanza's XML contents to an XPath expression.

        If the value of :data:`IGNORE_NS` is set to ``True``, then XPath
        expressions will be matched without using namespaces.

        .. warning::

            In Python 2.6 and 3.1 the ElementTree
            :meth:`~xml.etree.ElementTree.Element.find()` method does not
            support attribute selectors in the XPath expression.

        :param xml: The :class:`~sleekxmpp.xmlstream.stanzabase.ElementBase`
                    stanza to compare against.
        """
        if hasattr(xml, 'xml'):
            xml = xml.xml
        x = ET.Element('x')
        x.append(xml)

        if not IGNORE_NS:
            # Use builtin, namespace respecting, XPath matcher.
            if x.find(self._criteria) is not None:
                return True
            return False
        else:
            # Remove namespaces from the XPath expression.
            criteria = []
            for ns_block in self._criteria.split('{'):
                criteria.extend(ns_block.split('}')[-1].split('/'))

            # Walk the XPath expression.
            xml = x
            for tag in criteria:
                if not tag:
                    # Skip empty tag name artifacts from the cleanup phase.
                    continue

                children = [c.tag.split('}')[-1] for c in xml]
                try:
                    index = children.index(tag)
                except ValueError:
                    return False
                xml = list(xml)[index]
            return True
コード例 #13
0
    def match(self, xml):
        """
        Compare a stanza's XML contents to an XPath expression.

        If the value of IGNORE_NS is set to true, then XPath expressions
        will be matched without using namespaces.

        Note that in Python 2.6 and 3.1 the ElementTree find method does
        not support attribute selectors in the XPath expression.

        Arguments:
            xml -- The stanza object to compare against.
        """
        if hasattr(xml, 'xml'):
            xml = xml.xml
        x = ET.Element('x')
        x.append(xml)

        if not IGNORE_NS:
            # Use builtin, namespace respecting, XPath matcher.
            if x.find(self._criteria) is not None:
                return True
            return False
        else:
            # Remove namespaces from the XPath expression.
            criteria = []
            for ns_block in self._criteria.split('{'):
                criteria.extend(ns_block.split('}')[-1].split('/'))

            # Walk the XPath expression.
            xml = x
            for tag in criteria:
                if not tag:
                    # Skip empty tag name artifacts from the cleanup phase.
                    continue

                children = [c.tag.split('}')[-1] for c in xml.getchildren()]
                try:
                    index = children.index(tag)
                except ValueError:
                    return False
                xml = xml.getchildren()[index]
            return True
コード例 #14
0
    def match(self, xml):
        """
        Compare a stanza's XML contents to an XPath expression.

        If the value of :data:`IGNORE_NS` is set to ``True``, then XPath
        expressions will be matched without using namespaces.

        .. warning::

            In Python 2.6 and 3.1 the ElementTree
            :meth:`~xml.etree.ElementTree.Element.find()` method does not
            support attribute selectors in the XPath expression.

        :param xml: The :class:`~sleekxmpp.xmlstream.stanzabase.ElementBase`
                    stanza to compare against.
        """
        if hasattr(xml, 'xml'):
            xml = xml.xml
        x = ET.Element('x')
        x.append(xml)

        return x.find(self._criteria) is not None
コード例 #15
0
ファイル: stanza.py プロジェクト: PADGETS-EU/padgets-repo
 def set_request_reciept(self, val):
     self.del_request_reciept()
     parent = self.parent()
     if val:
         self.xml = ET.Element("{%s}%s" % (self.namespace, self.name))
         parent.append(self.xml)
コード例 #16
0
ファイル: stanza.py プロジェクト: E-Tahta/sleekxmpp
 def setup(self, xml=None):
     self.xml = ET.Element('')
     return True
コード例 #17
0
 def setup(self, xml):
     # Don't create XML for the plugin
     self.xml = ET.Element('')
コード例 #18
0
 def setBar(self, value):
     wrapper = ET.Element("{foo}wrapper")
     bar = ET.Element("{foo}bar")
     bar.text = value
     wrapper.append(bar)
     self.xml.append(wrapper)
コード例 #19
0
ファイル: stanza.py プロジェクト: PADGETS-EU/padgets-repo
 def del_request_reciept(self):
     self.xml = ET.Element('')