当前位置: 首页>>代码示例>>Python>>正文


Python xmlstream.StanzaBase类代码示例

本文整理汇总了Python中sleekxmpp.xmlstream.StanzaBase的典型用法代码示例。如果您正苦于以下问题:Python StanzaBase类的具体用法?Python StanzaBase怎么用?Python StanzaBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了StanzaBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: 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.

        Arguments:
            body  -- Optional text content for the message.
            clear -- Indicates if existing content should be removed
                     before replying. Defaults to True.
        """
        thread = self['thread']
        parent = self['parent_thread']

        StanzaBase.reply(self, clear)
        if self['type'] == 'groupchat':
            self['to'] = self['to'].bare

        self['thread'] = thread
        self['parent_thread'] = parent

        del self['id']

        if body is not None:
            self['body'] = body
        return self
开发者ID:2M1R,项目名称:SleekXMPP,代码行数:29,代码来源:message.py

示例2: set_payload

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

        Arguments:
            value -- An XML object to use as the <iq> stanza's contents
        """
        self.clear()
        StanzaBase.set_payload(self, value)
        return self
开发者ID:pnakos,项目名称:my_project,代码行数:10,代码来源:iq.py

示例3: __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:2M1R,项目名称:SleekXMPP,代码行数:10,代码来源:message.py

示例4: reply

    def reply(self):
        """
        Send a reply <iq> stanza.

        Overrides StanzaBase.reply

        Sets the 'type' to 'result' in addition to the default
        StanzaBase.reply behavior.
        """
        self['type'] = 'result'
        StanzaBase.reply(self)
        return self
开发者ID:andyhelp,项目名称:SleekXMPP,代码行数:12,代码来源:iq.py

示例5: __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:pnakos,项目名称:my_project,代码行数:12,代码来源:iq.py

示例6: send

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

        The send call can optionally block until a response is received or
        a timeout occurs. Be aware that using blocking in non-threaded event
        handlers can drastically impact performance. Otherwise, a callback
        handler can be provided that will be executed when the Iq stanza's
        result reply is received. Be aware though that that the callback
        handler will not be executed in its own thread.

        Using both block and callback is not recommended, and only the
        callback argument will be used in that case.

        Overrides StanzaBase.send

        Arguments:
            block    -- Specify if the send call will block until a response
                        is received, or a timeout occurs. Defaults to True.
            timeout  -- The length of time (in seconds) to wait for a response
                        before exiting the send call if blocking is used.
                        Defaults to sleekxmpp.xmlstream.RESPONSE_TIMEOUT
            callback -- Optional reference to a stream handler function. Will
                        be executed when a reply stanza is received.
            now      -- Indicates if the send queue should be skipped and send
                        the stanza immediately. Used during stream
                        initialization. Defaults to False.
        """
        if timeout is None:
            timeout = self.stream.response_timeout
        if callback is not None and self['type'] in ('get', 'set'):
            handler_name = 'IqCallback_%s' % self['id']
            handler = Callback(handler_name,
                               MatcherId(self['id']),
                               callback,
                               once=True)
            self.stream.register_handler(handler)
            StanzaBase.send(self, now=now)
            return handler_name
        elif block and self['type'] in ('get', 'set'):
            waitfor = Waiter('IqWait_%s' % self['id'], MatcherId(self['id']))
            self.stream.register_handler(waitfor)
            StanzaBase.send(self, now=now)
            result = waitfor.wait(timeout)
            if not result:
                raise IqTimeout(self)
            if result['type'] == 'error':
                raise IqError(result)
            return result
        else:
            return StanzaBase.send(self, now=now)
开发者ID:AmiZya,项目名称:emesene,代码行数:51,代码来源:iq.py

示例7: reply

    def reply(self, clear=True):
        """
        Send a reply <iq> stanza.

        Overrides StanzaBase.reply

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

        Arguments:
            clear -- Indicates if existing content should be
                     removed before replying. Defaults to True.
        """
        self['type'] = 'result'
        StanzaBase.reply(self, clear)
        return self
开发者ID:pnakos,项目名称:my_project,代码行数:16,代码来源:iq.py

示例8: __init__

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

        Overrides StanzaBase.__init__.
        """
        StanzaBase.__init__(self, *args, **kwargs)
        # To comply with PEP8, method names now use underscores.
        # Deprecated method names are re-mapped for backwards compatibility.
        self.setPayload = self.set_payload
        self.getQuery = self.get_query
        self.setQuery = self.set_query
        self.delQuery = self.del_query

        if self['id'] == '':
            if self.stream is not None:
                self['id'] = self.stream.getNewId()
            else:
                self['id'] = '0'
开发者ID:andyhelp,项目名称:SleekXMPP,代码行数:19,代码来源:iq.py

示例9: reply

    def reply(self):
        """
        Set the appropriate presence reply type.

        Overrides StanzaBase.reply.
        """
        if self['type'] == 'unsubscribe':
            self['type'] = 'unsubscribed'
        elif self['type'] == 'subscribe':
            self['type'] = 'subscribed'
        return StanzaBase.reply(self)
开发者ID:EnerNOC,项目名称:smallfoot-sleekxmpp,代码行数:11,代码来源:presence.py

示例10: reply

    def reply(self, body=None):
        """
        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.

        Arguments:
            body -- Optional text content for the message.
        """
        StanzaBase.reply(self)
        if self['type'] == 'groupchat':
            self['to'] = self['to'].bare

        del self['id']

        if body is not None:
            self['body'] = body
        return self
开发者ID:EnerNOC,项目名称:smallfoot-sleekxmpp,代码行数:21,代码来源:message.py

示例11: reply

    def reply(self, clear=True):
        """
        Set the appropriate presence reply type.

        Overrides StanzaBase.reply.

        Arguments:
            clear -- Indicates if the stanza contents should be removed
                     before replying. Defaults to True.
        """
        if self['type'] == 'unsubscribe':
            self['type'] = 'unsubscribed'
        elif self['type'] == 'subscribe':
            self['type'] = 'subscribed'
        return StanzaBase.reply(self, clear)
开发者ID:2M1R,项目名称:SleekXMPP,代码行数:15,代码来源:presence.py

示例12: _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:pnakos,项目名称:my_project,代码行数:24,代码来源:iq.py

示例13: send

    def send(self, block=True, timeout=RESPONSE_TIMEOUT, priority=5):
        """
        Send an <iq> stanza over the XML stream.

        The send call can optionally block until a response is received or
        a timeout occurs. Be aware that using blocking in non-threaded event
        handlers can drastically impact performance.

        Overrides StanzaBase.send

        Arguments:
            block   -- Specify if the send call will block until a response
                       is received, or a timeout occurs. Defaults to True.
            timeout -- The length of time (in seconds) to wait for a response
                       before exiting the send call if blocking is used.
                       Defaults to sleekxmpp.xmlstream.RESPONSE_TIMEOUT
        """
        if block and self['type'] in ('get', 'set'):
            waitfor = Waiter('IqWait_%s' % self['id'], MatcherId(self['id']))
            self.stream.registerHandler(waitfor)
            StanzaBase.send(self, priority)
            return waitfor.wait(timeout)
        else:
            return StanzaBase.send(self, priority)
开发者ID:EnerNOC,项目名称:smallfoot-sleekxmpp,代码行数:24,代码来源:iq.py

示例14: setup

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

        Overrides ElementBase.setup.

        Arguments:
            xml -- Use an existing XML object for the stanza's values.
        """
        # To comply with PEP8, method names now use underscores.
        # Deprecated method names are re-mapped for backwards compatibility.
        self.setShow = self.set_show
        self.getType = self.get_type
        self.setType = self.set_type
        self.delType = self.get_type
        self.getPriority = self.get_priority
        self.setPriority = self.set_priority

        return StanzaBase.setup(self, xml)
开发者ID:EnerNOC,项目名称:smallfoot-sleekxmpp,代码行数:19,代码来源:presence.py

示例15: 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:2M1R,项目名称:SleekXMPP,代码行数:20,代码来源:failure.py


注:本文中的sleekxmpp.xmlstream.StanzaBase类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。