當前位置: 首頁>>代碼示例>>Python>>正文


Python xmlstream.StanzaBase類代碼示例

本文整理匯總了Python中slixmpp.xmlstream.StanzaBase的典型用法代碼示例。如果您正苦於以下問題:Python StanzaBase類的具體用法?Python StanzaBase怎麽用?Python StanzaBase使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了StanzaBase類的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

    def __init__(self, *args, **kwargs):
        """
        Initialize a new <presence /> stanza with an optional 'id' value.

        Overrides StanzaBase.__init__.
        """
        StanzaBase.__init__(self, *args, **kwargs)
        if self['id'] == '':
            if self.stream is not None and self.stream.use_presence_ids:
                self['id'] = self.stream.new_id()
開發者ID:mathieui,項目名稱:slixmpp,代碼行數:10,代碼來源:presence.py

示例2: __init__

    def __init__(self, *args, **kwargs):
        """
        Initialize a new <message /> stanza with an optional 'id' value.

        Overrides StanzaBase.__init__.
        """
        StanzaBase.__init__(self, *args, **kwargs)
        if self["id"] == "":
            if self.stream is not None and self.stream.use_message_ids:
                self["id"] = self.stream.new_id()
開發者ID:goutomroy,項目名稱:slixmpp,代碼行數:10,代碼來源:message.py

示例3: set_payload

    def set_payload(self, value):
        """
        Set the XML contents of the <iq> stanza.

        :param value: An XML object or a list of XML objects to use as the <iq>
                      stanza's contents
        :type value: list or XML object
        """
        self.clear()
        StanzaBase.set_payload(self, value)
        return self
開發者ID:poezio,項目名稱:slixmpp,代碼行數:11,代碼來源:iq.py

示例4: __init__

    def __init__(self, *args, **kwargs):
        """
        Initialize a new <iq> stanza with an 'id' value.

        Overrides StanzaBase.__init__.
        """
        StanzaBase.__init__(self, *args, **kwargs)
        if self["id"] == "":
            if self.stream is not None:
                self["id"] = self.stream.new_id()
            else:
                self["id"] = "0"
開發者ID:poezio,項目名稱:slixmpp,代碼行數:12,代碼來源:iq.py

示例5: reply

    def reply(self, body=None, clear=True):
        """
        Create a message reply.

        Overrides StanzaBase.reply.

        Sets proper 'to' attribute if the message is from a MUC, and
        adds a message body if one is given.

        :param str body:  Optional text content for the message.
        :param bool clear: Indicates if existing content should be removed
                           before replying. Defaults to True.

        :rtype: :class:`~.Message`
        """
        new_message = StanzaBase.reply(self, clear)

        if self['type'] == 'groupchat':
            new_message['to'] = new_message['to'].bare

        new_message['thread'] = self['thread']
        new_message['parent_thread'] = self['parent_thread']

        del new_message['id']

        if body is not None:
            new_message['body'] = body
        return new_message
開發者ID:mathieui,項目名稱:slixmpp,代碼行數:28,代碼來源:message.py

示例6: _set_stanza_values

    def _set_stanza_values(self, values):
        """
        Set multiple stanza interface values using a dictionary.

        Stanza plugin values may be set usind nested dictionaries.

        If the interface 'query' is given, then it will be set
        last to avoid duplication of the <query /> element.

        Overrides ElementBase._set_stanza_values.

        Arguments:
            values -- A dictionary mapping stanza interface with values.
                      Plugin interfaces may accept a nested dictionary that
                      will be used recursively.
        """
        query = values.get("query", "")
        if query:
            del values["query"]
            StanzaBase._set_stanza_values(self, values)
            self["query"] = query
        else:
            StanzaBase._set_stanza_values(self, values)
        return self
開發者ID:poezio,項目名稱:slixmpp,代碼行數:24,代碼來源:iq.py

示例7: reply

    def reply(self, clear=True):
        """
        Create a new <iq> stanza replying to ``self``.

        Overrides StanzaBase.reply

        Sets the 'type' to 'result' in addition to the default
        StanzaBase.reply behavior.

        :param bool clear: Indicates if existing content should be
                           removed before replying. Defaults to True.
        """
        new_iq = StanzaBase.reply(self, clear=clear)
        new_iq["type"] = "result"
        return new_iq
開發者ID:poezio,項目名稱:slixmpp,代碼行數:15,代碼來源:iq.py

示例8: reply

    def reply(self, clear=True):
        """
        Create a new reply <presence/> stanza from ``self``.

        Overrides StanzaBase.reply.

        :param bool clear: Indicates if the stanza contents should be removed
                           before replying. Defaults to True.
        """
        new_presence = StanzaBase.reply(self, clear)
        if self['type'] == 'unsubscribe':
            new_presence['type'] = 'unsubscribed'
        elif self['type'] == 'subscribe':
            new_presence['type'] = 'subscribed'
        return new_presence
開發者ID:mathieui,項目名稱:slixmpp,代碼行數:15,代碼來源:presence.py

示例9: setup

    def setup(self, xml=None):
        """
        Populate the stanza object using an optional XML object.

        Overrides ElementBase.setup.

        Sets a default error type and condition, and changes the
        parent stanza's type to 'error'.

        Arguments:
            xml -- Use an existing XML object for the stanza's values.
        """
        # StanzaBase overrides self.namespace
        self.namespace = Failure.namespace

        if StanzaBase.setup(self, xml):
            #If we had to generate XML then set default values.
            self['condition'] = 'not-authorized'

        self.xml.tag = self.tag_name()
開發者ID:budlight,項目名稱:slixmpp,代碼行數:20,代碼來源:failure.py

示例10: send

    def send(self, callback=None, timeout=None, timeout_callback=None):
        """Send an <iq> stanza over the XML stream.

        A callback handler can be provided that will be executed when the Iq
        stanza's result reply is received.

        Returns a future which result will be set to the result Iq if it is of type 'get' or 'set'
        (when it is received), or a future with the result set to None if it has another type.

        Overrides StanzaBase.send

        :param function callback: Optional reference to a stream handler
                                  function. Will be executed when a reply
                                  stanza is received.
        :param int timeout: The length of time (in seconds) to wait for a
                            response before the timeout_callback is called,
                            instead of the regular callback
        :param function timeout_callback: Optional reference to a stream handler
                                          function.  Will be executed when the
                                          timeout expires before a response has
                                          been received for the originally-sent
                                          IQ stanza.
        :rtype: asyncio.Future
        """
        if self.stream.session_bind_event.is_set():
            matcher = MatchIDSender({"id": self["id"], "self": self.stream.boundjid, "peer": self["to"]})
        else:
            matcher = MatcherId(self["id"])

        future = asyncio.Future()

        def callback_success(result):
            if result["type"] == "error":
                future.set_exception(IqError(result))
            else:
                future.set_result(result)

            if timeout is not None:
                self.stream.cancel_schedule("IqTimeout_%s" % self["id"])
            if callback is not None:
                callback(result)

        def callback_timeout():
            future.set_exception(IqTimeout(self))
            self.stream.remove_handler("IqCallback_%s" % self["id"])
            if timeout_callback is not None:
                timeout_callback(self)

        if self["type"] in ("get", "set"):
            handler_name = "IqCallback_%s" % self["id"]
            if asyncio.iscoroutinefunction(callback):
                constr = CoroutineCallback
            else:
                constr = Callback
            if timeout is not None:
                self.stream.schedule("IqTimeout_%s" % self["id"], timeout, callback_timeout, repeat=False)
            handler = constr(handler_name, matcher, callback_success, once=True)
            self.stream.register_handler(handler)
        else:
            future.set_result(None)
        StanzaBase.send(self)
        return future
開發者ID:poezio,項目名稱:slixmpp,代碼行數:62,代碼來源:iq.py

示例11: setup

 def setup(self, xml):
     StanzaBase.setup(self, xml)
     self.xml.tag = self.tag_name()
開發者ID:mathieui,項目名稱:slixmpp,代碼行數:3,代碼來源:stanza.py

示例12: setup

 def setup(self, xml):
     StanzaBase.setup(self, xml)
     self.values = self.values
開發者ID:budlight,項目名稱:slixmpp,代碼行數:3,代碼來源:stream_features.py

示例13: send

    def send(self, callback=None, timeout=None, timeout_callback=None):
        """Send an <iq> stanza over the XML stream.

        A callback handler can be provided that will be executed when the Iq
        stanza's result reply is received.

        Returns a future which result will be set to the result Iq if it is of type 'get' or 'set'
        (when it is received), or a future with the result set to None if it has another type.

        Overrides StanzaBase.send

        :param function callback: Optional reference to a stream handler
                                  function. Will be executed when a reply
                                  stanza is received.
        :param int timeout: The length of time (in seconds) to wait for a
                            response before the timeout_callback is called,
                            instead of the regular callback
        :param function timeout_callback: Optional reference to a stream handler
                                          function.  Will be executed when the
                                          timeout expires before a response has
                                          been received for the originally-sent
                                          IQ stanza.
        :rtype: asyncio.Future
        """
        if self.stream.session_bind_event.is_set():
            matcher = MatchIDSender({
                'id': self['id'],
                'self': self.stream.boundjid,
                'peer': self['to']
            })
        else:
            matcher = MatcherId(self['id'])

        future = asyncio.Future()

        # Prevents handlers from existing forever.
        if timeout is None:
            timeout = 120

        def callback_success(result):
            type_ = result['type']
            if type_ == 'result':
                future.set_result(result)
            elif type_ == 'error':
                future.set_exception(IqError(result))
            else:
                # Most likely an iq addressed to ourself, rearm the callback.
                handler = constr(handler_name,
                                 matcher,
                                 callback_success,
                                 once=True)
                self.stream.register_handler(handler)
                return

            if timeout is not None:
                self.stream.cancel_schedule('IqTimeout_%s' % self['id'])
            if callback is not None:
                callback(result)

        def callback_timeout():
            future.set_exception(IqTimeout(self))
            self.stream.remove_handler('IqCallback_%s' % self['id'])
            if timeout_callback is not None:
                timeout_callback(self)

        if self['type'] in ('get', 'set'):
            handler_name = 'IqCallback_%s' % self['id']
            if asyncio.iscoroutinefunction(callback):
                constr = CoroutineCallback
            else:
                constr = Callback
            if timeout is not None:
                self.stream.schedule('IqTimeout_%s' % self['id'],
                                     timeout,
                                     callback_timeout,
                                     repeat=False)
            handler = constr(handler_name,
                             matcher,
                             callback_success,
                             once=True)
            self.stream.register_handler(handler)
        else:
            future.set_result(None)
        StanzaBase.send(self)
        return future
開發者ID:mathieui,項目名稱:slixmpp,代碼行數:85,代碼來源:iq.py


注:本文中的slixmpp.xmlstream.StanzaBase類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。