Ejemplo n.º 1
0
    def fetch(self, e):
        stanza_id = generate_unique()
        iq = Stanza.get_iq(self.client.jid,
                           u"firehoser.superfeedr.com",
                           stanza_id=stanza_id)

        pubsub = E(u"pubsub", namespace=XMPP_PUBSUB_NS, parent=iq)
        A(u"superfeedr",
          prefix=u"xmlns",
          namespace=XMLNS_NS,
          parent=pubsub,
          value=u"http://superfeedr.com/xmpp-pubsub-ext")
        sub = E(u"subscriptions",
                attributes={u"jid": unicode(self.client.jid)},
                parent=pubsub,
                namespace=XMPP_PUBSUB_NS)
        A(u"page",
          value=u"1",
          prefix=u"superfeedr",
          parent=sub,
          namespace=u"http://superfeedr.com/xmpp-pubsub-ext")

        self.client.register_on_iq(self.subscriptions,
                                   type="result",
                                   id=stanza_id,
                                   once=True)
        self.client.send_stanza(iq)
Ejemplo n.º 2
0
 def subscription(self, e):
     iq = Stanza.get_iq(self.client.jid, u"firehoser.superfeedr.com")
     E(u"query",
       namespace=XMPP_DISCO_ITEMS_NS,
       parent=iq,
       attributes={u'node': e.get_attribute_value('node')})
     self.client.send_stanza(iq)
Ejemplo n.º 3
0
    def unsubscribe(self, url=URL):
        stanza_id = generate_unique()
        iq = Stanza.set_iq(self.client.jid,
                           u"firehoser.superfeedr.com",
                           stanza_id=stanza_id)

        pubsub = E(u"pubsub", namespace=XMPP_PUBSUB_NS, parent=iq)
        A(u"superfeedr",
          prefix=u"xmlns",
          namespace=XMLNS_NS,
          parent=pubsub,
          value=u"http://superfeedr.com/xmpp-pubsub-ext")
        E(u"unsubscribe",
          attributes={
              u"jid": self.client.jid.nodeid(),
              u"node": url
          },
          parent=pubsub,
          namespace=XMPP_PUBSUB_NS)

        self.client.register_on_iq(self.subscribe,
                                   type="result",
                                   id=stanza_id,
                                   once=True)
        self.client.send_stanza(iq)
Ejemplo n.º 4
0
 def unregister(self):
     stanza_id = generate_unique()
     iq = Stanza.set_iq(stanza_id=stanza_id)
     query = E(u'query', namespace=XMPP_IBR_NS, parent=iq)
     E(u'remove', namespace=XMPP_IBR_NS, parent=query)
     self.client.register_on_iq(self.unregistered, type=u'result',
                                id=stanza_id, once=True)
     self.client.send_stanza(iq)
Ejemplo n.º 5
0
    def ask_roster(self):
        """
        Creates and returns the IQ stanza to query the entity's roster.
        """
        iq = Stanza.get_iq(from_jid=unicode(self.jid), stanza_id=generate_unique())
        E(u'query', namespace=XMPP_ROSTER_NS, parent=iq)   

        return iq
Ejemplo n.º 6
0
    def ask_roster(self):
        """
        Creates and returns the IQ stanza to query the entity's roster.
        """
        iq = Stanza.get_iq(from_jid=unicode(self.jid),
                           stanza_id=generate_unique())
        E(u'query', namespace=XMPP_ROSTER_NS, parent=iq)

        return iq
Ejemplo n.º 7
0
 def unregister(self):
     stanza_id = generate_unique()
     iq = Stanza.set_iq(stanza_id=stanza_id)
     query = E(u'query', namespace=XMPP_IBR_NS, parent=iq)
     E(u'remove', namespace=XMPP_IBR_NS, parent=query)
     self.client.register_on_iq(self.unregistered,
                                type=u'result',
                                id=stanza_id,
                                once=True)
     self.client.send_stanza(iq)
Ejemplo n.º 8
0
    def handle_registration(self, e):
        iq = Stanza.set_iq(stanza_id=e.xml_parent.get_attribute_value('id'))
        query = E(u'query', namespace=XMPP_IBR_NS, parent=iq)
        E(u'username', content=self.settings.username, namespace=XMPP_IBR_NS, parent=query)
        E(u'password', content=self.settings.password, namespace=XMPP_IBR_NS, parent=query)

        self.client.register_on_iq(self.registered, type=u'result',
                                   id=e.xml_parent.get_attribute_value('id'), once=True)
        
        self.client.send_stanza(iq)
Ejemplo n.º 9
0
    def handle_binding(self, e):
        """
        Handle the JID binding request by returning
        the full JID.
        """
        iq = Stanza.set_iq(stanza_id=generate_unique())
        bind = E(u'bind', namespace=XMPP_BIND_NS, parent=iq)
        if self.jid.resource != None:
            E(u'resource', content=self.jid.resource,
              namespace=XMPP_BIND_NS, parent=bind)

        return iq
Ejemplo n.º 10
0
    def register(self, e):
        """
        Handler called when the `<register xmlns="http://jabber.org/features/iq-register" />`
        stanza is received and the client required the registration process.

        Returns a stanza indicating the client is indeed requesting the
        registration process from the server.

        ``e`` :class:`bridge.Element` instance representing the dispatched stanza
        """
        iq = Stanza.get_iq(stanza_id=generate_unique())
        E(u'register', namespace=XMPP_IBR_NS, parent=iq)
        return iq
Ejemplo n.º 11
0
    def handle_binding(self, e):
        """
        Handle the JID binding request by returning
        the full JID.
        """
        iq = Stanza.set_iq(stanza_id=generate_unique())
        bind = E(u'bind', namespace=XMPP_BIND_NS, parent=iq)
        if self.jid.resource != None:
            E(u'resource',
              content=self.jid.resource,
              namespace=XMPP_BIND_NS,
              parent=bind)

        return iq
Ejemplo n.º 12
0
    def test_to_element(self):
        stanza = Stanza(name="iq", from_jid="bob", to_jid="alice", type="get", stanza_id="i")
        xml = """<?xml version="1.0" encoding="UTF-8"?>
<iq xmlns="jabber:client" to="alice" type="get" id="i" from="bob" />"""
        self.assertEqual(Stanza.to_element(stanza).xml(), xml)
        stanza.swap_jids()
        xml_swapped = """<?xml version="1.0" encoding="UTF-8"?>
<iq xmlns="jabber:client" to="bob" type="get" id="i" from="alice" />"""
        self.assertEqual(Stanza.to_element(stanza).xml(), xml_swapped)
Ejemplo n.º 13
0
    def unsubscribe(self, url=URL):
        stanza_id = generate_unique()
        iq = Stanza.set_iq(self.client.jid, u"firehoser.superfeedr.com",
                           stanza_id=stanza_id)
        
        pubsub = E(u"pubsub", namespace=XMPP_PUBSUB_NS, parent=iq)
        A(u"superfeedr", prefix=u"xmlns", namespace=XMLNS_NS, parent=pubsub,
          value=u"http://superfeedr.com/xmpp-pubsub-ext")
        E(u"unsubscribe", attributes={u"jid": self.client.jid.nodeid(),
                                      u"node": url},
          parent=pubsub, namespace=XMPP_PUBSUB_NS)

        self.client.register_on_iq(self.subscribe, type="result",
                                   id=stanza_id, once=True)
        self.client.send_stanza(iq)
Ejemplo n.º 14
0
    def fetch(self, e):
        stanza_id = generate_unique()
        iq = Stanza.get_iq(self.client.jid, u"firehoser.superfeedr.com",
                           stanza_id=stanza_id)
        
        pubsub = E(u"pubsub", namespace=XMPP_PUBSUB_NS, parent=iq)
        A(u"superfeedr", prefix=u"xmlns", namespace=XMLNS_NS, parent=pubsub,
          value=u"http://superfeedr.com/xmpp-pubsub-ext")
        sub = E(u"subscriptions", attributes={u"jid": unicode(self.client.jid)},
                parent=pubsub, namespace=XMPP_PUBSUB_NS)
        A(u"page", value=u"1", prefix=u"superfeedr", parent=sub,
          namespace=u"http://superfeedr.com/xmpp-pubsub-ext")

        self.client.register_on_iq(self.subscriptions, type="result", id=stanza_id, once=True)
        self.client.send_stanza(iq)
Ejemplo n.º 15
0
    def handle_session(self, e):
        """
        Handles the session elements received by the server.

        If the type of the response is `result` it raises
        :class:`headstock.error.HeadstockAuthenticationSuccess` instance
        handled by the client indicating the session is ready.

        Otherwise returns the session stanza indicating the
        client wishes to start a session.
        """
        if e.xml_parent and e.xml_parent.get_attribute_value('type') == 'result':
            raise HeadstockSessionBound()
        
        iq = Stanza.set_iq(stanza_id=generate_unique())
        E(u'session', namespace=XMPP_SESSION_NS, parent=iq)
        
        return iq
Ejemplo n.º 16
0
    def handle_registration(self, e):
        """
        Handler called when the server sends the registration form and returns the
        same form filled with at least the username and password.
        
        ``e`` :class:`bridge.Element` instance representing the dispatched stanza
        """
        iq = Stanza.set_iq(stanza_id=e.xml_parent.get_attribute_value('id'))
        query = E(u'query', namespace=XMPP_IBR_NS, parent=iq)
        E(u'username', content=self.username, namespace=XMPP_IBR_NS, parent=query)
        E(u'password', content=self.password, namespace=XMPP_IBR_NS, parent=query)
        if self.email:
            E(u'email', content=self.email, namespace=XMPP_IBR_NS, parent=query)

        self.client.register_on_iq(self.handle_register_success, type=u'result',
                                   id=e.xml_parent.get_attribute_value('id'), once=True)
        
        return iq
Ejemplo n.º 17
0
    def handle_registration(self, e):
        iq = Stanza.set_iq(stanza_id=e.xml_parent.get_attribute_value('id'))
        query = E(u'query', namespace=XMPP_IBR_NS, parent=iq)
        E(u'username',
          content=self.settings.username,
          namespace=XMPP_IBR_NS,
          parent=query)
        E(u'password',
          content=self.settings.password,
          namespace=XMPP_IBR_NS,
          parent=query)

        self.client.register_on_iq(self.registered,
                                   type=u'result',
                                   id=e.xml_parent.get_attribute_value('id'),
                                   once=True)

        self.client.send_stanza(iq)
Ejemplo n.º 18
0
    def handle_session(self, e):
        """
        Handles the session elements received by the server.

        If the type of the response is `result` it raises
        :class:`headstock.error.HeadstockAuthenticationSuccess` instance
        handled by the client indicating the session is ready.

        Otherwise returns the session stanza indicating the
        client wishes to start a session.
        """
        if e.xml_parent and e.xml_parent.get_attribute_value(
                'type') == 'result':
            raise HeadstockSessionBound()

        iq = Stanza.set_iq(stanza_id=generate_unique())
        E(u'session', namespace=XMPP_SESSION_NS, parent=iq)

        return iq
Ejemplo n.º 19
0
 def subscriptions(self, e):
     iq = Stanza.get_iq(self.client.jid, u"firehoser.superfeedr.com")
     E(u"query", namespace=XMPP_DISCO_ITEMS_NS, parent=iq)
     self.client.send_stanza(iq)
Ejemplo n.º 20
0
 def notify_presence(self):
     """
     Creates and returns a presence stanza as a
     :class:`bridge.Element` instance.
     """
     return Stanza.to_element(Stanza(u'presence'))
Ejemplo n.º 21
0
    def test_error_iq(self):
        stanza = Stanza.error_iq(from_jid="bob", to_jid="alice", stanza_id="i")
        xml = """<?xml version="1.0" encoding="UTF-8"?>
<iq xmlns="jabber:client" to="alice" type="error" id="i" from="bob" />"""
        self.assertEqual(stanza.xml(), xml)
Ejemplo n.º 22
0
 def subscriptions(self, e):
     iq = Stanza.get_iq(self.client.jid, u"firehoser.superfeedr.com")
     E(u"query", namespace=XMPP_DISCO_ITEMS_NS, parent=iq)
     self.client.send_stanza(iq)
Ejemplo n.º 23
0
 def test_uniq_id(self):
     xml1 = Stanza.get_iq().xml()
     xml2 = Stanza.get_iq().xml()
     self.assertNotEqual(xml1, xml2)
Ejemplo n.º 24
0
 def notify_presence(self):
     """
     Creates and returns a presence stanza as a
     :class:`bridge.Element` instance.
     """
     return Stanza.to_element(Stanza(u'presence'))
Ejemplo n.º 25
0
 def register(self, e):
     iq = Stanza.get_iq(stanza_id=generate_unique())
     E(u'register', namespace=XMPP_IBR_NS, parent=iq)
     self.client.send_stanza(iq)
Ejemplo n.º 26
0
 def subscription(self, e):
     iq = Stanza.get_iq(self.client.jid, u"firehoser.superfeedr.com")
     E(u"query", namespace=XMPP_DISCO_ITEMS_NS, parent=iq,
       attributes={u'node': e.get_attribute_value('node')})
     self.client.send_stanza(iq)
Ejemplo n.º 27
0
 def register(self, e):
     iq = Stanza.get_iq(stanza_id=generate_unique())
     E(u'register', namespace=XMPP_IBR_NS, parent=iq)
     self.client.send_stanza(iq)