本文整理汇总了Python中twisted.words.xish.domish.Element类的典型用法代码示例。如果您正苦于以下问题:Python Element类的具体用法?Python Element怎么用?Python Element使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Element类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: getPortfolio
def getPortfolio():
portfolio = Element((collab.COLLAB_NS, 'portfolio'))
#assets
assets = portfolio.addElement('assets')
for i in xrange(num_assets):
a = assets.addElement('asset')
a.addElement('id').addContent(str(i))
a.addElement('name').addContent('asset%i' % i)
a.addElement('default_probability').addContent(str(float(i)/div))
#issuers
issuers = portfolio.addElement('issuers')
for i in xrange(num_issuers):
iss = issuers.addElement('issuer')
iss.addElement('id').addContent(str(i))
iss.addElement('name').addContent('issuer%i' % i)
fs = iss.addElement('factors')
for j in xrange(num_factors):
f = fs.addElement('factor')
f.addElement('name').addContent('factor%i' % j)
f.addElement('weight').addContent(str(float(j)/div))
#asset issuer map
aimap = portfolio.addElement('asset_issuer_map')
for i in xrange(num_assets):
a = aimap.addElement('asset')
a.addElement('id').addContent(str(i))
a.addElement('issuer').addElement('id').addContent(str(i%num_issuers))
return portfolio
开发者ID:wyn,项目名称:collab,代码行数:28,代码来源:utils.py
示例2: getRandomPortfolio
def getRandomPortfolio(min_size=10):
portfolio = Element((collab.COLLAB_NS, 'portfolio'))
#assets
assets = portfolio.addElement('assets')
no_assets = random.randrange(min_size,20)
no_issuers = int(no_assets/ratio)
for i in xrange(no_assets):
a = assets.addElement('asset')
a.addElement('id').addContent(str(i))
a.addElement('name').addContent('asset%i' % i)
a.addElement('default_probability').addContent(str(float(i)/div))
#issuers
issuers = portfolio.addElement('issuers')
for i in xrange(no_issuers):
iss = issuers.addElement('issuer')
iss.addElement('id').addContent(str(i))
iss.addElement('name').addContent('issuer%i' % i)
fs = iss.addElement('factors')
for j in xrange(random.randrange(1, 5)):
f = fs.addElement('factor')
f.addElement('name').addContent('factor%i' % j)
f.addElement('weight').addContent(str(float(j)/div))
#asset issuer map
aimap = portfolio.addElement('asset_issuer_map')
for i in xrange(no_assets):
a = aimap.addElement('asset')
a.addElement('id').addContent(str(i))
a.addElement('issuer').addElement('id').addContent(str(i%no_issuers))
return portfolio
开发者ID:wyn,项目名称:collab,代码行数:30,代码来源:utils.py
示例3: _send
def _send():
mt = getToolByName(portal, "portal_membership", None)
message = Element((None, "message"))
message["id"] = getRandomId()
message["from"] = self.xmlstream.factory.authenticator.jid.full()
message["to"] = to.userhost()
x = message.addElement((NS_ROSTER_X, "x"))
for jid in items:
if to == jid:
continue
member_id = users.unescapeNode(jid.user)
if mt is not None and mt.getMemberInfo(member_id):
info = mt.getMemberInfo(member_id)
fullname = info.get("fullname", member_id).decode("utf-8")
else:
log.warn("Could not get user fullname: %s" % member_id)
fullname = ""
item = x.addElement("item")
item["action"] = "add"
item["jid"] = jid.userhost()
item["name"] = fullname
if group:
item.addElement("group", content=group)
self.xmlstream.send(message)
开发者ID:collective,项目名称:collective.xmpp.core,代码行数:26,代码来源:protocols.py
示例4: makeDataElement
def makeDataElement(self):
""" Returns an XML Element that can be put into a jabber:x:avatar IQ stanza. """
data = Element((None, "data"))
data["mimetype"] = "image/png"
data.addContent(
base64.encodestring(self.getImageData()).replace("\n", ""))
return data
开发者ID:2mf,项目名称:pyicqt,代码行数:7,代码来源:avatar.py
示例5: sendCompletedForm
def sendCompletedForm(self, el, sessionid=None):
to = el.getAttribute('from')
ID = el.getAttribute('id')
ulang = utils.getLang(el)
iq = Element((None, 'iq'))
iq.attributes = {'to': to, 'from': config.jid, 'type': 'result'}
if ID:
iq.attributes['id'] = ID
command = iq.addElement('command')
command.attributes = {
'node': 'settings',
'xmlns': globals.COMMANDS,
'status': 'completed'
}
if sessionid:
command.attributes['sessionid'] = sessionid
else:
command.attributes['sessionid'] = self.pytrans.makeMessageID()
note = command.addElement('note', None, lang.get('settings_changed'))
note.attributes['type'] = 'info'
x = command.addElement('x')
x.attributes = {'xmlns': 'jabber:x:data', 'type': 'form'}
x.addElement('title', None, lang.get('command_Settings'))
x.addElement('instructions', None, lang.get('settings_changed'))
self.pytrans.send(iq)
开发者ID:anton-ryzhov,项目名称:pyicqt_auto_reconnect,代码行数:29,代码来源:Settings.py
示例6: toElement
def toElement(self):
el = Element((collab.COLLAB_NS, 'portfolio'))
el.addElement('name', content=self.name)
ass_el = el.addElement('assets')
for a in self.assets:
ass_el.addChild(a.toElement())
return el
开发者ID:wyn,项目名称:collab,代码行数:7,代码来源:portfolio.py
示例7: onIq
def onIq(self, element: Element):
source = JID(element.getAttribute("from"))
recipient = JID(element.getAttribute("to"))
identification = element.getAttribute("id")
iqType = element.getAttribute("type")
print("IqReceived " + source.full() + " -> " + recipient.full() + ": " + iqType)
# Process component iq
if recipient.full() == self.h2x.config.JID:
self.componentIq(element, source, identification, iqType)
return
# Process user iq
if self.h2x.isHangUser(recipient):
self.userIq(element, source, recipient, identification, iqType)
return
# TODO: Can we send something like wrong request?
self.__sendIqError(
recipient=source.full(),
sender=recipient.full(),
identification=identification,
errorType="cancel",
condition="service-unavailable",
)
开发者ID:vladamatena,项目名称:h2x,代码行数:26,代码来源:iq.py
示例8: toEtree
def toEtree(self):
msg = Element(('jabber:client', 'iq'))
msg['type'] = self.type
msg['id'] = self.id
msg['from'] = self.from_
msg['to'] = self.to
if self.type == 'result':
ecm_message = msg.addElement('ecm_message')
ecm_message['version'] = str(AGENT_VERSION_PROTOCOL)
ecm_message['core'] = str(AGENT_VERSION_CORE)
ecm_message['command'] = self.command
ecm_message['signature'] = self.signature
result = ecm_message.addElement('result')
result['retvalue'] = self.retvalue
result['timed_out'] = self.timed_out
result['partial'] = self.partial
# compress out
result.addElement('gzip_stdout').addContent(base64.b64encode(zlib.compress(self.stdout)))
result.addElement('gzip_stderr').addContent(base64.b64encode(zlib.compress(self.stderr)))
del ecm_message
return msg
开发者ID:ecmanaged,项目名称:ecm-agent,代码行数:25,代码来源:message.py
示例9: sendMood
def sendMood(self, to=None, fro=None, mood=None, text=None, action=None):
"""
send mood to user
"""
LogEvent(INFO)
el = Element((None, "message"))
el.attributes["id"] = self.pytrans.makeMessageID()
if fro:
el.attributes["from"] = fro
e = el.addElement("event")
e.attributes["xmlns"] = globals.PUBSUBEVENT
items = e.addElement("items")
items.attributes["node"] = globals.MOOD
if action == 'retract':
r = items.addElement("retract")
r.attributes["id"] = self.pytrans.makeMessageID()
else:
item = items.addElement("item")
item.attributes["id"] = self.pytrans.makeMessageID()
m = item.addElement("mood")
m.attributes["xmlns"] = globals.MOOD
if mood:
m.addElement(mood)
if text:
t = m.addElement("text")
t.addContent(text)
for res in self.pytrans.sessions[to].resourceList: # send to every resource
el.attributes["to"] = to + '/' + res
self.pytrans.send(el)
开发者ID:anton-ryzhov,项目名称:pyicqt_auto_reconnect,代码行数:35,代码来源:pubsub.py
示例10: removeListEntry
def removeListEntry(self, type, jabberID, legacyID):
""" Removes a legacy ID entry from a list in
the XDB, based off the type and jabberID you provide. """
if type != "roster": return
xdbns = XDBNS_PREFIX+type
list = self.request(jabberID, xdbns)
if list == None:
list = Element((None, "aimtrans"))
list.attributes["xmlns"] = xdbns
buddies = None
for child in list.elements():
try:
if child.name == "buddies":
buddies = child
break
except AttributeError:
continue
if buddies == None:
buddies = list.addElement("buddies")
# Remove the existing element
for child in buddies.elements():
try:
if child.getAttribute("name") == legacyID:
buddies.children.remove(child)
except AttributeError:
continue
self.set(jabberID, xdbns, list)
开发者ID:Ashaman-,项目名称:pyaimt,代码行数:31,代码来源:legacyaimtransport.py
示例11: test_onGotDistribution
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
开发者ID:wyn,项目名称:collab,代码行数:30,代码来源:distributionsManagerTests.py
示例12: test_fromElement_bad
def test_fromElement_bad(self):
el = Element((collab.COLLAB_NS, 'wrong'))
el.addElement('runs', content='100')
def doIt():
p = simulation.Progress.fromElement(el)
self.assertRaises(simulation.InvalidProgressError, doIt)
开发者ID:wyn,项目名称:collab,代码行数:7,代码来源:simulationTests.py
示例13: sendTune
def sendTune(self, to=None, fro=None, musicinfo=None, stop=False):
"""
send tune to user
"""
LogEvent(INFO)
el = Element((None, "message"))
el.attributes["id"] = self.pytrans.makeMessageID()
if fro:
el.attributes["from"] = fro
e = el.addElement("event")
e.attributes["xmlns"] = globals.PUBSUBEVENT
items = e.addElement("items")
items.attributes["node"] = globals.TUNE
item = items.addElement("item")
item.attributes["id"] = self.pytrans.makeMessageID()
t = item.addElement("tune")
t.attributes["xmlns"] = globals.TUNE
if not stop:
if musicinfo and len(musicinfo) > 0:
for key in musicinfo:
if key in ('artist', 'length', 'rating', 'source', 'title', 'track', 'uri'):
value = musicinfo[key]
if value:
t_key = t.addElement(key)
t_key.addContent(value)
for res in self.pytrans.sessions[to].resourceList: # send to every resource
el.attributes["to"] = to + '/' + res
self.pytrans.send(el)
开发者ID:anton-ryzhov,项目名称:pyicqt_auto_reconnect,代码行数:34,代码来源:pubsub.py
示例14: test_fromElement
def test_fromElement(self):
el = Element((collabNs, 'asset'))
el.addElement('name', content='ass')
el.addElement('dp', content='0.1')
el.addElement('recovery', content='0.1')
el.addElement('notional', content='200.0')
i_el = el.addElement('issuer')
i_el.addElement('name', content='iss')
fs_el = i_el.addElement('factors')
f1_el = fs_el.addElement('factor')
f1_el.addElement('name', content='f1')
f1_el.addElement('weight', content='0.1')
f2_el = fs_el.addElement('factor')
f2_el.addElement('name', content='f2')
f2_el.addElement('weight', content='0.2')
ass = portfolio.Asset.fromElement(el)
self.assertEquals(ass.name, 'ass')
self.assertEquals(ass.dp, 0.1)
self.assertEquals(ass.recovery, 0.1)
self.assertEquals(ass.notional, 200.0)
i = ass.issuer
self.assertEquals(i.name, 'iss')
fs = i.factors
self.assertEquals(len(fs), 2)
self.assertTrue(checkFactor('f1', 0.1, fs))
self.assertTrue(checkFactor('f2', 0.2, fs))
开发者ID:wyn,项目名称:collab,代码行数:31,代码来源:portfolioTests.py
示例15: toElement
def toElement(self):
el = Element((None, 'actions'))
if self.default:
el['execute'] = self.default
[el.addElement(a) for a in self.actions]
return el
开发者ID:wyn,项目名称:collab,代码行数:7,代码来源:command.py
示例16: test_fromElement_notTopNode
def test_fromElement_notTopNode(self):
el = Element(('http://jabber.org/protocol/pubsub#event', 'item'))
prog = el.addElement('progress', defaultUri=collab.COLLAB_NS)
prog.addElement('runs', content='100')
p = simulation.Progress.fromElement(el)
self.assertEquals(p.runs, 100)
开发者ID:wyn,项目名称:collab,代码行数:7,代码来源:simulationTests.py
示例17: test_fromElement_ignoresNonData
def test_fromElement_ignoresNonData(self):
name = 'bender'
el = Element((collab.COLLAB_NS, 'distributions'))
h = el.addElement('histogram')
h['name'] = name
for i in xrange(10):
if i%2:
d_el = h.addElement('ignored')
d_el['point'] = str(i)
d_el['value'] = str(2*i)
else:
d_el = h.addElement('data')
d_el['point'] = str(i)
d_el['value'] = str(2*i)
d = simulation.Distributions.fromElement(el)
self.assertTrue(name in d.histograms)
self.assertEquals(len(d.histograms), 1)
hist = d.histograms[name]
for i in xrange(10):
if i%2:
self.assertTrue(i not in hist)
else:
self.assertTrue(i in hist)
self.assertEquals(hist[i], 2*i)
开发者ID:wyn,项目名称:collab,代码行数:26,代码来源:simulationTests.py
示例18: test_onGotStartSimulation_noPortfolio
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
开发者ID:wyn,项目名称:collab,代码行数:25,代码来源:correlatedDefaultsSimulatorTests.py
示例19: successReply
def successReply(self, incoming):
reply = Element((None, "iq"))
reply.attributes["type"] = "result"
ID = incoming.getAttribute("id")
if(ID): reply.attributes["id"] = ID
reply.attributes["from"] = config.jid
reply.attributes["to"] = incoming.getAttribute("from")
self.pytrans.send(reply)
开发者ID:Ashaman-,项目名称:pyaimt,代码行数:8,代码来源:register.py
示例20: test_fromElement_noAssets
def test_fromElement_noAssets(self):
el = Element((collabNs, 'portfolio'))
el.addElement('name', content='port')
def doIt():
p = portfolio.Portfolio.fromElement(el)
self.assertRaises(portfolio.InvalidPortfolioError, doIt)
开发者ID:wyn,项目名称:collab,代码行数:8,代码来源:portfolioTests.py
注:本文中的twisted.words.xish.domish.Element类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论