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


Python IQ.addChild方法代码示例

本文整理汇总了Python中twisted.words.protocols.jabber.client.IQ.addChild方法的典型用法代码示例。如果您正苦于以下问题:Python IQ.addChild方法的具体用法?Python IQ.addChild怎么用?Python IQ.addChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.words.protocols.jabber.client.IQ的用法示例。


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

示例1: on_presence

# 需要导入模块: from twisted.words.protocols.jabber.client import IQ [as 别名]
# 或者: from twisted.words.protocols.jabber.client.IQ import addChild [as 别名]
 def on_presence(self, presence):
     print('received presence: %s' % presence.toXml().encode('utf-8'))
     user, host, res = parse(presence['from'])
     jid = '@'.join((user, host))
     if presence.hasAttribute('type'):
         if presence['type'] == 'subscribe':
             if jid in self.users:
                 print('received subscription')
                 if self.users[jid] is False:
                     iq = IQ(self.xmlstream, 'set')
                     query = domish.Element(('jabber:iq:roster', 'query'))
                     item = domish.Element((None, 'item'))
                     item['jid'] = jid
                     item['name'] = jid
                     item.addElement('group', content='controllers')
                     query.addChild(item)
                     iq.addChild(query)
                     iq.addCallback(self.subscribed, jid)
                     self.xmlstream.send(iq)
                     pres = domish.Element((None, 'presence'))
                     pres['type'] = 'subscribed'
                     pres['to'] = jid
                     self.xmlstream.send(pres)
                     
             else:
                 presence = domish.Element((None, 'presence'))
                 presence['type'] = 'unsubscribed'
                 presence['to'] = presence['from']
                 self.xmlstream.send(presence)
开发者ID:bverdu,项目名称:onDemand,代码行数:31,代码来源:xmpp.py

示例2: on_description

# 需要导入模块: from twisted.words.protocols.jabber.client import IQ [as 别名]
# 或者: from twisted.words.protocols.jabber.client.IQ import addChild [as 别名]
    def on_description(self, iq):
#         print(
#             'Received description from %s: %s'
#             % (iq['from'], iq.toXml().encode('utf-8')))
        pause = IQ(self.xmlstream, 'set')
        pause['to'] = iq['from']
#         enveloppe = domish.Element(
#             ('http://schemas.xmlsoap.org/soap/envelope/', 'Envelope'))
        enveloppe = domish.Element(
            ('http://schemas.xmlsoap.org/soap/envelope/', 'Envelope'), localPrefixes={'s': 'http://schemas.xmlsoap.org/soap/envelope/'})
        enveloppe['s:encodingStyle'] = "http://schemas.xmlsoap.org/soap/encoding/"
        header = domish.Element((None, 's:Header'))
#         header = domish.Element(('http://schemas.xmlsoap.org/soap/envelope/', 'Header'))
        header['mustUnderstand'] = "1"
        uc = domish.Element(('urn:schemas-upnp-org:cloud-1-0', 'uc'))
        uc['serviceId'] = 'urn:av-openhome-org:serviceId:Playlist'
        header.addChild(uc)
        enveloppe.addChild(header)
        body = domish.Element((None, 's:Body'))
#         body = domish.Element(('http://schemas.xmlsoap.org/soap/envelope/', 'Body'))
        action = domish.Element(
            ('urn:av-openhome-org:service:Playlist:1', 'Read'), localPrefixes={'u': 'urn:av-openhome-org:service:Playlist:1'})
#         action = domish.Element(
#             ('urn:av-openhome-org:service:Playlist:1', 'Pause'))
        body.addChild(action)
        enveloppe.addChild(body)
        pause.addChild(enveloppe)
        pause.addCallback(self.paused)
        print('send pause')
        print(pause.toXml())
        pause.send()
开发者ID:bverdu,项目名称:onDemand,代码行数:33,代码来源:xmpp.py

示例3: _gtalk_stanza

# 需要导入模块: from twisted.words.protocols.jabber.client import IQ [as 别名]
# 或者: from twisted.words.protocols.jabber.client.IQ import addChild [as 别名]
    def _gtalk_stanza(self, action):
        iq = IQ(self.stream, 'set')
        iq['from'] = self.remote_jid
        iq['to'] = self.local_jid
        sess = domish.Element(("http://www.google.com/session", 'session'))
        if self.direction == 'incoming':
            sess['initiator'] = self.remote_jid
        elif self.direction == 'outgoing':
            sess['initiator'] = self.local_jid

        sess['type'] = action
        sess['id'] = self.session_id
        iq.addChild(sess)
        return (iq, sess)
开发者ID:dfghj44444,项目名称:realxtend-naali-deps,代码行数:16,代码来源:jingletest.py

示例4: _jingle_stanza

# 需要导入模块: from twisted.words.protocols.jabber.client import IQ [as 别名]
# 或者: from twisted.words.protocols.jabber.client.IQ import addChild [as 别名]
    def _jingle_stanza(self, action):
        iq = IQ(self.stream, 'set')
        iq['from'] = self.remote_jid
        iq['to'] = self.local_jid
        jingle = domish.Element(("http://jabber.org/protocol/jingle", 'jingle'))
        if self.direction == 'incoming':
            jingle['initiator'] = self.remote_jid
        elif self.direction == 'outgoing':
            jingle['initiator'] = self.local_jid

        jingle['action'] = action
        jingle['sid'] = self.session_id
        iq.addChild(jingle)
        return (iq, jingle)
开发者ID:dfghj44444,项目名称:realxtend-naali-deps,代码行数:16,代码来源:jingletest.py

示例5: check_users

# 需要导入模块: from twisted.words.protocols.jabber.client import IQ [as 别名]
# 或者: from twisted.words.protocols.jabber.client.IQ import addChild [as 别名]
    def check_users(self):
        for user, value in self.users.items():
            if value['state'] is False:
                iq = IQ(self.xmlstream, 'set')
                query = domish.Element(('jabber:iq:roster', 'query'))
                item = domish.Element((None, 'item'))
                item['name'] = user
                item['jid'] = user
                item.addElement('group', content='hosts')
                query.addChild(item)
                iq.addChild(query)
                iq.addCallback(self.cloud_subscribe, user)
#                 print('send IQ: %s' % (iq.toXml().encode('utf-8')))
                iq.send()
开发者ID:bverdu,项目名称:onDemand,代码行数:16,代码来源:controller.py

示例6: send_error_reply

# 需要导入模块: from twisted.words.protocols.jabber.client import IQ [as 别名]
# 或者: from twisted.words.protocols.jabber.client.IQ import addChild [as 别名]
def send_error_reply(stream, iq, error_stanza=None):
    result = IQ(stream, "error")
    result["id"] = iq["id"]
    query = iq.firstChildElement()
    to = iq.getAttribute('to')
    if to is not None:
        result["from"] = to

    if query:
        result.addElement((query.uri, query.name))

    if error_stanza:
        result.addChild(error_stanza)

    stream.send(result)
开发者ID:Thaodan,项目名称:telepathy-gabble,代码行数:17,代码来源:gabbletest.py

示例7: unsubscribe_cloud

# 需要导入模块: from twisted.words.protocols.jabber.client import IQ [as 别名]
# 或者: from twisted.words.protocols.jabber.client.IQ import addChild [as 别名]
    def unsubscribe_cloud(self, name):

        def unsubscribed(name, d, res):
            if res['type'] == 'result':
                #                 print('unsubscribed: %s' % name)
                del self.subscriptions_cloud[name]
                print('ok')
                d.callback(None)
            else:
                d.errback(Exception(res.toXml()))

        d = defer.Deferred()
        iq = IQ(self.xmlstream, 'set')
        ps = domish.Element(('http://jabber.org/protocol/pubsub', 'pubsub'))
        unsubscribe = domish.Element((None, 'unsubscribe'))
        unsubscribe['node'] = name
        unsubscribe['jid'] = self.jid.full()
        ps.addChild(unsubscribe)
        iq.addChild(ps)
        iq.addCallback(unsubscribed, name, d)
        iq.send(to='pubsub.' + self.jid.host)
        return d
开发者ID:bverdu,项目名称:onDemand,代码行数:24,代码来源:controller.py

示例8: subscribe_cloud

# 需要导入模块: from twisted.words.protocols.jabber.client import IQ [as 别名]
# 或者: from twisted.words.protocols.jabber.client.IQ import addChild [as 别名]
    def subscribe_cloud(
            self, device, svc, var, callback_fct=None, callback_args=()):
        #         print('suscribe to %s' % var)
        name = device.keys()[0]
        dev = device[name]
        if not callback_fct:
            callback_fct = self.log.debug
        d = defer.Deferred()

        def subscribe_failed(err, name):
            self.parent.remove_device(name.split('_')[0])

        def subscribed(node_name, deferred, iq):
            if iq['type'] == 'result':
                self.subscriptions_cloud[str(node_name)] = True
#                 print('%s suscribed !' % str(node_name))
#                 iq = IQ(self.xmlstream, 'get')
#                 ps = domish.Element(
#                     ('http://jabber.org/protocol/pubsub', 'pubsub'))
#                 items = domish.Element((None, 'items'))
#                 items['node'] = node_name
#                 items['max_items'] = '1'
#                 ps.addChild(items)
#                 iq.addChild(ps)
#                 iq.addCallback(self.on_event)
#                 iq.send(to='pubsub.' + self.jid.host)
#                 print(iq.toXml())
                deferred.callback(str(node_name))
            else:
                deferred.errback(Exception('subscription to %s failed: %s'
                                           % (node_name, iq.toXml())))

        if svc in dev['services']:
            #             print('service %s ok' % svc)
            #             print('subscriptions :%s' % self.subscriptions_cloud)
            if not self.cloud_event_catcher:
                self.cloud_event_catcher = CloudEventCatcher(
                    {}, {}, logger=self.log)
            subscription_name = '/'.join((dev['location'], svc, var))
            #  subscription_service = svc
            if subscription_name in self.cloud_event_catcher.callbacks:
                self.cloud_event_catcher.callbacks[subscription_name].update(
                    {var: (callback_fct, callback_args,)})
            else:
                self.cloud_event_catcher.callbacks.update(
                    {subscription_name: {var: (callback_fct, callback_args,)}})
#             if var in self.cloud_event_catcher.callbacks:
#                 self.cloud_event_catcher.callbacks[var].update(
#                     {var: (callback_fct, callback_args,)})
#             else:
#                 self.cloud_event_catcher.callbacks.update(
#                     {var: {var: (callback_fct, callback_args,)}})
    #         log.error(self.event_catcher.catcher.childs)
            if subscription_name in self.subscriptions_cloud:
                if self.subscriptions_cloud[subscription_name]:
                    #                     print('already subscribed: %s' % subscription_name)
                    for k, value in\
                            self.cloud_event_catcher.unfiltered_dict.items():
                        #                         print('is %s == %s ?' % (k, var))
                        if k == var:
                            if value == 'False':
                                value = False
                            elif value == 'True':
                                value = True
                            if isinstance(callback_args, str)\
                                    or isinstance(callback_args, bool):
                                callback_fct(value, callback_args)
                            else:
                                callback_fct(value, *callback_args)
                            del self.cloud_event_catcher.unfiltered_dict[k]
                    return defer.succeed(None)
            self.subscriptions_cloud.update({str(subscription_name): False})
#             print(subscription_name)
#             print(subscription_service)
            iq = IQ(self.xmlstream, 'set')
            ps = domish.Element(
                ('http://jabber.org/protocol/pubsub', 'pubsub'))
            subscribe = domish.Element((None, 'subscribe'))
            subscribe['node'] = subscription_name
            subscribe['jid'] = self.jid.full()
            ps.addChild(subscribe)
            iq.addChild(ps)
            iq.addCallback(subscribed, subscription_name, d)
            iq.send(to='pubsub.' + self.jid.host)
            return d
        return defer.fail(Exception('Service unknow'))
开发者ID:bverdu,项目名称:onDemand,代码行数:88,代码来源:controller.py

示例9: publish

# 需要导入模块: from twisted.words.protocols.jabber.client import IQ [as 别名]
# 或者: from twisted.words.protocols.jabber.client.IQ import addChild [as 别名]
    def publish(self, event):

        if len(self.parent.active_controllers) == 0:
            #             self.log.debug('event cancelled')
            self.parent.registrations = []
            return

        def success(res):
            #             print('event sent')
            if res['type'] == 'error':
                self.log.error('Publish Event failed :%s' % res.toXml())
            else:
                if 'Id' in res.children[0].children[0]['node']:
                    self.log.debug('Event Published: %s' % res.toXml())
        name, data = event
        if name == 'Seconds':
            return
        iq = IQ(self.parent.xmlstream, 'set')
        ps = domish.Element(('http://jabber.org/protocol/pubsub', 'pubsub'))
        publish = domish.Element((None, 'publish'))
        publish['node'] = '/'.join((self.nodeId, name))
        item = domish.Element((None, 'item'))
        propertyset = domish.Element(
            ('urn:schemas-upnp-org:event-1-0', 'propertyset'),
            localPrefixes={'e': 'urn:schemas-upnp-org:event-1-0'})
        prop = domish.Element((None, 'e:property'))
        evt = domish.Element((None, name))
        if isinstance(data.value, dict):
            ev = domish.Element((data.namespace, 'Event'))
            inst = domish.Element((None, 'InstanceID'))
            inst['val'] = '0'
            for k, v in data.value.items:
                if 'namespace' in v:
                    var = domish.Element((v['namespace'], k))
                else:
                    var = domish.Element((None, k))
                if 'attrib' in v:
                    attr = v['attrib']
                else:
                    attr = {}
                value = v['value']
                if isinstance(value, bool):
                    value = int(value)
                attr.update(
                    {'val': str(value)
                     .decode('utf-8')})
                for attname, attval in attr:
                    var[attname] = attval
                inst.addChild(var)
            ev.addChild(inst)
            evt.addChild(ev)
        else:
            #             print(str(data.value).decode('utf-8'))
            if isinstance(data.value, bool):
                data.value = int(data.value)
            evt.addContent(str(data.value).decode('utf-8'))
        prop.addChild(evt)
        propertyset.addChild(prop)
        item.addChild(propertyset)
        publish.addChild(item)
        ps.addChild(publish)
        iq.addChild(ps)
        iq.addCallback(success)
        iq.send(to=self.addr)
开发者ID:lazytech-org,项目名称:onDemand,代码行数:66,代码来源:event.py


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