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


Python Element.toXml方法代码示例

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


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

示例1: test_toElement

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import toXml [as 别名]
    def test_toElement(self):
        p = simulation.Progress(100)
        el = p.toElement()

        expected = Element((collab.COLLAB_NS, 'progress'))
        expected.addElement('runs', content='100')

        self.assertEquals(el.toXml(), expected.toXml())
开发者ID:wyn,项目名称:collab,代码行数:10,代码来源:simulationTests.py

示例2: test_toElement

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import toXml [as 别名]
    def test_toElement(self):
        n = Note('bla', 'error')

        el = Element((None, 'note'))
        el['type'] = 'error'
        el.addContent('bla')

        self.assertEquals(n.toElement().toXml(), el.toXml())
开发者ID:wyn,项目名称:collab,代码行数:10,代码来源:commandTests.py

示例3: leaveChatRoom

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import toXml [as 别名]
 def leaveChatRoom(self, jid):
     if '/' not in jid:
         jid += '/' + self.SERVICECONFIG.JABBER_CHAT_NICK
     presence = Element( (None,'presence') )
     presence['from'] = self.jid.userhost()
     presence['to'] = jid
     presence['type'] = 'unavailable'
     log('sending leave: %s' % presence.toXml())
     self.xmlstream.send(presence)
开发者ID:cbrinley,项目名称:droned,代码行数:11,代码来源:jabber.py

示例4: test_toElement

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import toXml [as 别名]
    def test_toElement(self):
        f = portfolio.Factor('fac', 0.5)
        el = f.toElement()
        
        expected = Element((collabNs, 'factor'))
        expected.addElement('name', content='fac')
        expected.addElement('weight', content='0.5')

        self.assertEquals(el.toXml(), expected.toXml())
        self.assertEquals(el.uri, collabNs)
开发者ID:wyn,项目名称:collab,代码行数:12,代码来源:portfolioTests.py

示例5: test_toElement_noIssuer

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import toXml [as 别名]
    def test_toElement_noIssuer(self):
        a = portfolio.Asset('ass')
        el = a.toElement()

        expected = Element((collabNs, 'asset'))
        expected.addElement('name', content='ass')
        expected.addElement('dp', content='1.0')
        expected.addElement('recovery', content='1.0')
        expected.addElement('notional', content='100.0')

        self.assertEquals(el.toXml(), expected.toXml())
        self.assertEquals(el.uri, collabNs)
开发者ID:wyn,项目名称:collab,代码行数:14,代码来源:portfolioTests.py

示例6: joinChatRoom

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import toXml [as 别名]
 def joinChatRoom(self, room):
     presence = Element( (None,'presence') )
     presence['from'] = self.jid.userhost()
     jid = '%[email protected]%s/%s' % (room,self.SERVICECONFIG.JABBER_CHAT_SERVICE,self.SERVICECONFIG.JABBER_CHAT_NICK)
     presence['to'] = jid
     x = Element( ('http://jabber.org/protocol/muc','x') )
     history = Element( (None,'history') )
     history['maxchars'] = '0'
     x.addChild(history)
     presence.addChild(x)
     log('sending join: %s' % presence.toXml())
     self.xmlstream.send(presence)
开发者ID:cbrinley,项目名称:droned,代码行数:14,代码来源:jabber.py

示例7: requestAuthorization

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import toXml [as 别名]
 def requestAuthorization(self, to):
     request = Element( (None,'iq') )
     request['type'] = 'set'
     request['id'] = 'auth-request:%s' % to
     query = Element( (None,'query') )
     query['xmlns'] = 'jabber:iq:roster'
     item = Element( (None,'item') )
     item['jid'] = to
     item['name'] = to.split('@')[0]
     query.addChild(item)
     request.addChild(query)
     log('sending auth request: %s' % request.toXml())
     self.xmlstream.send(request)
开发者ID:cbrinley,项目名称:droned,代码行数:15,代码来源:jabber.py

示例8: send

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import toXml [as 别名]
	def send(self, obj):
		if self.routewrap == 1 and type(obj) == Element:
			to = obj.getAttribute("to")
			route = Element((None,"route"))
			route.attributes["from"] = config.jid
			route.attributes["to"] = internJID(to).host
			route.addChild(obj)
			obj.attributes["xmlns"] = "jabber:client"
			component.Service.send(self,route.toXml())
		else:
			if type(obj) == Element:
				obj = obj.toXml()
			component.Service.send(self,obj)
开发者ID:anton-ryzhov,项目名称:pyicqt_auto_reconnect,代码行数:15,代码来源:main.py

示例9: incoming_reply

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import toXml [as 别名]
def incoming_reply(q, bus, conn, stream):
    chan, bare_jid, full_jid, self_handle_name = \
        setup_incoming_tests(q, bus, conn, stream)

    moar = Element((ycs.MESSAGE_NS, 'message'))
    moar['ninety-nine-problems'] = 'but a sauvignon blanc aint one'
    moar['also'] = 'my mum said hi'
    trollface = moar.addElement('trollface', content='problem?')

    call_async(q, chan, 'Reply',
               {'ninety-nine-problems': 'but a sauvignon blanc aint one',
                'also': 'my mum said hi'},
               moar.toXml())

    _, e = q.expect_many(EventPattern('dbus-return', method='Reply'),
                         EventPattern('stream-message'))

    iq = e.stanza
    assertEquals('le-loldongs', iq['id'])
    assertEquals('result', iq['type'])
    assertEquals(self_handle_name, iq['from'])
    assertEquals(full_jid, iq['to'])
    assertEquals(1, len(iq.children))

    message = iq.children[0]

    assertEquals('message', message.name)
    assertEquals(ycs.MESSAGE_NS, message.uri)
    assertEquals('my mum said hi', message['also'])
    assertEquals('but a sauvignon blanc aint one', message['ninety-nine-problems'])
    assertEquals('the.from.service', message['to-service'])
    assertEquals('the.to.service', message['from-service'])
    assertEquals(1, len(message.children))

    trollface = message.children[0]

    assertEquals('trollface', trollface.name)
    assertEquals(1, len(trollface.children))

    assertEquals('problem?', trollface.children[0])

    # check we can't call anything any more
    call_async(q, chan, 'Fail', ycs.ERROR_TYPE_CANCEL, 'lol', 'whut', 'pear')
    q.expect('dbus-error', method='Fail')

    call_async(q, chan, 'Reply', {'lol':'whut'}, '')
    q.expect('dbus-error', method='Reply')

    call_async(q, chan, 'Request')
    q.expect('dbus-error', method='Request')
开发者ID:freedesktop-unofficial-mirror,项目名称:ytstenut__ytstenut-plugins,代码行数:52,代码来源:message.py

示例10: test_Issuer_toElement

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import toXml [as 别名]
    def test_Issuer_toElement(self):
        fs = set([portfolio.Factor('f1', 0.1)])
        i = portfolio.Issuer('iss', fs)
        el = i.toElement()

        expected = Element((collabNs, 'issuer'))
        expected.addElement('name', content='iss')
        fs_el = expected.addElement('factors')
        f1_el = fs_el.addElement('factor')
        f1_el.addElement('name', content='f1')
        f1_el.addElement('weight', content='0.1')

        self.assertEquals(el.toXml(), expected.toXml())
        self.assertEquals(el.uri, collabNs)
开发者ID:wyn,项目名称:collab,代码行数:16,代码来源:portfolioTests.py

示例11: test_onOutput_toLog

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import toXml [as 别名]
    def test_onOutput_toLog(self):
        outputs = ['log']
        node = nodes.PSOutputNode(testJid, self.mockPSClient)
        node.outputChannels = Mock(side_effect=utils.good_side_effect(outputs))
        
        el = Element(('top', 'ns'))
        el.addContent('im covered in bees')
        el.toXml = Mock()
        d = node.onOutput(el)

        def cb(msg):
            self.assertFalse(self.mockPSClient.publish.called)
            self.assertEquals(el.toXml.call_count, 1)

        d.addCallback(cb)
        return d
开发者ID:wyn,项目名称:collab,代码行数:18,代码来源:nodesTests.py

示例12: test_onError_toPublishOnly

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import toXml [as 别名]
    def test_onError_toPublishOnly(self):
        errors = ['errornode1', 'errornode2']
        node = nodes.PSErrorNode(testJid, self.mockPSClient)
        node.errorChannels = Mock(side_effect=utils.good_side_effect(errors))
        
        el = Element(('top', 'ns'))
        el.addContent('im covered in bees')
        el.toXml = Mock()
        d = node.onError(el)

        def cb(msg):
            self.assertEquals(self.mockPSClient.publish.call_count, 2)
            self.assertEquals(el.toXml.call_count, 0)

        d.addCallback(cb)
        return d 
开发者ID:wyn,项目名称:collab,代码行数:18,代码来源:nodesTests.py

示例13: test_onError_toPublishErrored

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import toXml [as 别名]
    def test_onError_toPublishErrored(self):
        self.mockPSClient.publish = Mock(side_effect=utils.bad_side_effect(error.StanzaError('DISAPPOINTED')))
        errors = ['errornode1', 'errornode2', 'log']
        node = nodes.PSErrorNode(testJid, self.mockPSClient)
        node.errorChannels = Mock(side_effect=utils.good_side_effect(errors))
        
        el = Element(('top', 'ns'))
        el.addContent('im covered in bees')
        el.toXml = Mock()
        d = node.onError(el)

        def cb(msg):
            self.assertEquals(self.mockPSClient.publish.call_count, 2)
            self.assertEquals(el.toXml.call_count, 1)

        d.addCallback(cb)
        return self.assertFailure(d, error.StanzaError)
开发者ID:wyn,项目名称:collab,代码行数:19,代码来源:nodesTests.py

示例14: set

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import toXml [as 别名]
	def set(self, file, xdbns, element):
		""" Sets a specific xdb namespace in the XDB 'file' to element """
		try:
			element.attributes["xdbns"] = xdbns
			document = None
			try:
				document = self.__getFile(file)
			except IOError:
				pass
			if not document:
				document = Element((None, "xdb"))
			
			# Remove the existing node (if any)
			for child in document.elements():
				if child.getAttribute("xdbns") == xdbns:
					document.children.remove(child)
			# Add the new one
			document.addChild(element)
			
			self.__writeFile(file, document.toXml())
		except:
			LogEvent(INFO, msg="XDB error writing entry %s to file %s" % (xdbns, file))
			raise
开发者ID:fritteli,项目名称:pyicqt,代码行数:25,代码来源:legacyjittransport.py

示例15: receivedPresence

# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import toXml [as 别名]
 def receivedPresence(self, e):
     log('received presence: %s' % e.toXml())
     if e.getAttribute('type') == 'subscribe':
         log('received authorization request from %s' % e['from'])
         response = Element( ('','presence') )
         response['to'] = e['from']
         response['type'] = 'subscribed'
         log('sending auth response: %s' % response.toXml())
         self.xmlstream.send(response)
         buddy = str(e['from'])
         if not Conversation.exists(buddy):
             self.requestAuthorization(buddy)
     elif e.getAttribute('type') == 'unavailable':
         #fix for openfire jabber server randomly kicking clients out and prevent kicks
         CHAT = '@%s/%s' % (self.SERVICECONFIG.JABBER_CHAT_SERVICE,self.SERVICECONFIG.JABBER_CHAT_NICK)
         if e['to'] == self.jid.full() and e['from'].endswith(CHAT) and \
                 "status code='307'" in e.toXml():
             try:
                 log('%s has kicked me' % (e['from'],))
                 self.joinChatRoom(e['from'].split(CHAT)[0])
                 log('successfully rejoined room')
             except:
                 err('Failed to recover from /kick')
开发者ID:cbrinley,项目名称:droned,代码行数:25,代码来源:jabber.py


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