本文整理汇总了Python中twisted.words.xish.domish.Element.addChild方法的典型用法代码示例。如果您正苦于以下问题:Python Element.addChild方法的具体用法?Python Element.addChild怎么用?Python Element.addChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.words.xish.domish.Element
的用法示例。
在下文中一共展示了Element.addChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_onGotDistribution
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import addChild [as 别名]
def test_onGotDistribution(self):
self.dm.broadcastLogs = Mock()
self.dm.handleDistribution = Mock(side_effect=utils.good_side_effect('lush'))
self.dm._errback = Mock(side_effect=utils.good_side_effect('err logged'))
item = Element((pubsub.NS_PUBSUB_EVENT, 'item'))
item['id'] = str(1)
params = sim.Parameters(run_id='1', cmd='results')
params_el = params.toElement()
progress = sim.Progress(200)
params_el.addChild(progress.toElement())
dist = sim.Distributions()
hist = defaultdict(int)
hist[1] = 1
hist[2] = 2
dist.combine('a', hist)
params_el.addChild(dist.toElement())
item.addChild(params_el)
lg = sim.Logger()
d = self.dm.onGotDistribution(params, item, lg)
def check(data):
self.assertFalse(self.dm.broadcastLogs.called)
self.assertEquals(self.dm.handleDistribution.call_count, 1)
self.assertFalse(self.dm._errback.called)
d.addCallback(check)
self.sch.clock.pump([1,1,1])
return d
示例2: toElement
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import addChild [as 别名]
def toElement(self):
el = Element((collab.COLLAB_NS, 'asset'))
el.addElement('name', content=self.name)
el.addElement('dp', content=str(self.dp))
el.addElement('recovery', content=str(self.recovery))
el.addElement('notional', content=str(self.notional))
if self.issuer:
el.addChild(self.issuer.toElement())
return el
示例3: sendPresence
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import addChild [as 别名]
def sendPresence(pytrans, to, fro, show=None, status=None, priority=None, ptype=None, avatarHash=None, nickname=None, payload=[], url=None):
if ptype in ["subscribe", "subscribed", "unsubscribe", "unsubscribed"]:
to = internJID(to).userhost()
fro = internJID(fro).userhost()
el = Element((None, "presence"))
el.attributes["to"] = to
el.attributes["from"] = fro
if ptype:
el.attributes["type"] = ptype
if show:
s = el.addElement("show")
s.addContent(utils.xmlify(show))
if status:
s = el.addElement("status")
s.addContent(utils.xmlify(status))
if priority:
s = el.addElement("priority")
s.addContent(priority)
if url:
s = el.addElement("x")
s.attributes["xmlns"] = globals.XOOB
s = el.addElement("url")
s.addContent(url)
if not ptype:
if avatarHash and not config.disableAvatars and not config.disableVCardAvatars:
x = el.addElement("x")
x.attributes["xmlns"] = globals.VCARDUPDATE
p = x.addElement("photo")
p.addContent(avatarHash)
if nickname:
x = el.addElement("x")
x.attributes["xmlns"] = globals.VCARDUPDATE
n = x.addElement("nickname")
n.addContent(nickname)
if avatarHash and not config.disableAvatars and not config.disableIQAvatars:
x = el.addElement("x")
x.attributes["xmlns"] = globals.XAVATAR
h = x.addElement("hash")
h.addContent(avatarHash)
if nickname and ptype == "subscribe":
n = el.addElement("nick")
n.attributes["xmlns"] = globals.NICK
n.addContent(nickname)
if payload:
for p in payload:
el.addChild(p)
pytrans.send(el)
示例4: joinChatRoom
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import addChild [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)
示例5: requestAuthorization
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import addChild [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)
示例6: _dictToPubSubItem
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import addChild [as 别名]
def _dictToPubSubItem(self, adict):
item = Element((None, 'item'))
item['id'] = adict['id']
entry = Element(('http://www.w3.org/2005/Atom', 'entry'))
for key in ['author', 'updated', 'published', 'content']:
entry.addElement(key, content=adict[key])
geolocation = adict.get('geolocation')
if geolocation:
entry.addElement('geolocation')
entry.geolocation['latitude'] = geolocation['latitude']
entry.geolocation['longitude'] = geolocation['longitude']
item.addChild(entry)
return item
示例7: send
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import addChild [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)
示例8: sendMessage
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import addChild [as 别名]
def sendMessage(pytrans, to, fro, body=None, mtype=None, delay=None,
xhtml=None, nickname=None, receipt=None, mID=None):
""" Sends a Jabber message """
LogEvent(INFO)
el = Element((None, "message"))
el.attributes["to"] = to
el.attributes["from"] = fro
if mID:
el.attributes["id"] = mID
else:
el.attributes["id"] = pytrans.makeMessageID()
if mtype:
el.attributes["type"] = mtype
if delay:
x = el.addElement("x")
x.attributes["xmlns"] = globals.XDELAY
x.attributes["from"] = fro
x.attributes["stamp"] = delay
if nickname:
n = el.addElement("nick")
n.attributes["xmlns"] = globals.NICK
n.addContent(nickname)
if receipt:
r = el.addElement("received")
r.attributes["xmlns"] = globals.RECEIPTS
else: # do not send state info in message receipt
x = el.addElement("x")
x.attributes["xmlns"] = globals.XEVENT
composing = x.addElement("composing")
xx = el.addElement("active")
xx.attributes["xmlns"] = globals.CHATSTATES
if body:
b = el.addElement("body")
b.addContent(utils.xmlify(body))
if xhtml and not config.disableXHTML:
try:
el.addChild(utils.parseText(xhtml))
except:
# Hrm, didn't add, we're not going to end the world
# because of it.
pass
pytrans.send(el)
sendArchive(pytrans, to, fro, body)
示例9: test_onGotStartSimulation_noPortfolio
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import addChild [as 别名]
def test_onGotStartSimulation_noPortfolio(self):
run_id = '1'
item = Element((pubsub.NS_PUBSUB_EVENT, 'item'))
item['id'] = str(run_id)
params = sim.Parameters(run_id=run_id, cmd='info')
params_el = item.addChild(params.toElement())
logger = sim.Logger()
self.cds.broadcastLogs = Mock(side_effect=utils.good_side_effect('done'))
self.cds.broadcastResults = Mock()
self.cds.simulatorFactory = MagicMock()
self.cds._errback = Mock()
gen = self.cds.onGotStartSimulation(params, item, logger)
d = gen.next()
def check(data):
self.cds.broadcastLogs.assert_called_once_with(logger, params)
self.assertFalse(self.cds.broadcastResults.called)
self.assertFalse(self.cds.simulatorFactory.__getitem__.called)
self.assertFalse(self.cds._errback.called)
d.addCallback(check)
self.assertRaises(StopIteration, gen.next)
return d
示例10: test_onGotItem_info
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import addChild [as 别名]
def test_onGotItem_info(self):
self.cds.onGotStartSimulation = Mock()
self.cds.onGotStoppedSimulation = Mock()
run_id = '1'
item = Element((pubsub.NS_PUBSUB_EVENT, 'item'))
item['id'] = str(run_id)
params = sim.Parameters(run_id=run_id, cmd='info')
item.addChild(params.toElement())
d = self.cds.onGotItem(item)
def check(data):
self.assertTrue(data is None)
self.assertFalse(self.cds.onGotStartSimulation.called)
self.assertFalse(self.cds.onGotStoppedSimulation.called)
d.addCallback(check)
self.sch.clock.pump([1])
return d
示例11: test_onGotItem_start_alreadyGoing
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import addChild [as 别名]
def test_onGotItem_start_alreadyGoing(self):
self.cds.onGotStartSimulation = Mock()
self.cds.onGotStoppedSimulation = Mock()
run_id = '1'
self.cds.tasks[run_id] = 'I should be a task'
item = Element((pubsub.NS_PUBSUB_EVENT, 'item'))
item['id'] = str(run_id)
params = sim.Parameters(run_id=run_id, cmd='start')
item.addChild(params.toElement())
d = self.cds.onGotItem(item)
def check(data):
self.assertTrue(data is None)
self.assertFalse(self.cds.onGotStartSimulation.called)
self.assertFalse(self.cds.onGotStoppedSimulation.called)
d.addCallback(check)
return d
示例12: test_onGotItem_results
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import addChild [as 别名]
def test_onGotItem_results(self):
self.dm.onGotDistribution = Mock(side_effect=utils.good_side_effect('lush'))
self.dm.onGotStoppedSimulation = Mock()
item = Element((pubsub.NS_PUBSUB_EVENT, 'item'))
item['id'] = str(1)
params = sim.Parameters(run_id='1', cmd='results')
params_el = params.toElement()
params_el.addChild(sim.Progress(200).toElement())
params_el.addChild(sim.Distributions().toElement())
item.addChild(params_el)
d = self.dm.onGotItem(item)
def check(data):
self.assertEquals(data, 'lush')
self.assertEquals(self.dm.onGotDistribution.call_count, 1)
self.assertFalse(self.dm.onGotStoppedSimulation.called)
d.addCallback(check)
return d
示例13: test_onGotItem_stop
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import addChild [as 别名]
def test_onGotItem_stop(self):
self.cds.onGotStartSimulation = Mock()
self.cds.onGotStoppedSimulation = Mock(side_effect=utils.good_side_effect('done'))
run_id = '1'
item = Element((pubsub.NS_PUBSUB_EVENT, 'item'))
item['id'] = str(run_id)
params = sim.Parameters(run_id=run_id, cmd='stop')
item.addChild(params.toElement())
d = self.cds.onGotItem(item)
def check(data):
self.assertEquals(data, 'done')
self.assertEquals(self.cds.onGotStoppedSimulation.call_count, 1)
self.assertFalse(self.cds.onGotStartSimulation.called)
d.addCallback(check)
self.sch.clock.pump([1])
return d
示例14: test_onGotItem_stopping
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import addChild [as 别名]
def test_onGotItem_stopping(self):
cdm = CorrelatedDefaultsManager(testjid)
cdm.broadcastStart = Mock()
cdm.broadcastStop = Mock(side_effect=utils.good_side_effect('lush'))
cdm.broadcastLogs = Mock()
item = Element((pubsub.NS_PUBSUB_EVENT, 'item'))
item['id'] = str(1)
params = simulation.Parameters(cmd='stop')
expected = params.toElement()
item.addChild(expected)
out = yield cdm.onGotItem(item)
self.assertFalse(cdm.broadcastStart.called)
self.assertEquals(cdm.broadcastStop.call_count, 1)
self.assertFalse(cdm.broadcastLogs.called)
for ((a,), dic) in cdm.broadcastStop.call_args_list:
self.assertEquals(a.toElement().toXml(), expected.toXml())
示例15: toElement
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import addChild [as 别名]
def toElement(self):
el = Element((self.defaultUri, 'command'))
el['node'] = self.node
el['sessionid'] = self.sessionid
if self.status:
el['status'] = self.status
if self.action:
el['action'] = self.action
if self.actions:
el.addChild(self.actions.toElement())
if self.form:
el.addChild(self.form.toElement())
if self.notes:
[el.addChild(n.toElement()) for n in self.notes]
return el