本文整理汇总了Python中twisted.words.xish.xpath.queryForNodes函数的典型用法代码示例。如果您正苦于以下问题:Python queryForNodes函数的具体用法?Python queryForNodes怎么用?Python queryForNodes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了queryForNodes函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: validate_session_initiate
def validate_session_initiate(self, query):
contents = xpath.queryForNodes(
'/jingle[@xmlns="%s"]/content' % ns.JINGLE,
query)
audio, video = [], []
for c in contents:
descs = xpath.queryForNodes(
'/content/description[@xmlns="%s"]' % ns.JINGLE_RTP,
c)
assert len(descs) == 1, c.toXml()
d = descs[0]
if d['media'] == 'audio':
audio.append(c['name'])
elif d['media'] == 'video':
video.append(c['name'])
else:
assert False, c.toXml()
assert len(audio) + len(video) > 0, query.toXml()
return (self._extract_session_id(query), audio, video)
开发者ID:jku,项目名称:telepathy-gabble,代码行数:26,代码来源:jingletest2.py
示例2: test_invisible_on_connect_fail
def test_invisible_on_connect_fail(q, bus, conn, stream):
props = conn.Properties.GetAll(cs.CONN_IFACE_SIMPLE_PRESENCE)
assertNotEquals({}, props['Statuses'])
presence_event_pattern = EventPattern('stream-presence')
q.forbid_events([presence_event_pattern])
conn.SimplePresence.SetPresence("hidden", "")
conn.Connect()
stream.handle_get_all_privacy_lists(q, bus, conn)
create_list = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='set')
# Check its name
assertNotEquals([],
xpath.queryForNodes('/query/list/item/presence-out', create_list.query))
acknowledge_iq(stream, create_list.stanza)
set_active = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='set')
active = xpath.queryForNodes('//active', set_active.query)[0]
assertEquals('invisible', active['name'])
send_error_reply(stream, set_active.stanza)
q.unforbid_events([presence_event_pattern])
# Darn! At least we should have our presence set to DND.
q.expect_many(
EventPattern('dbus-signal', signal='PresencesChanged',
interface=cs.CONN_IFACE_SIMPLE_PRESENCE,
args=[{1: (6, 'dnd', '')}]),
EventPattern('dbus-signal', signal='StatusChanged',
args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED]))
开发者ID:jku,项目名称:telepathy-gabble,代码行数:34,代码来源:invisible_xep_0126.py
示例3: test_create_invisible_list
def test_create_invisible_list(q, bus, conn, stream):
conn.SimplePresence.SetPresence("away", "")
conn.Connect()
stream.handle_get_all_privacy_lists(q, bus, conn)
get_list = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='get')
list_node = xpath.queryForNodes('//list', get_list.query)[0]
assertEquals('invisible', list_node['name'])
error = domish.Element((None, 'error'))
error['type'] = 'cancel'
error.addElement((ns.STANZA, 'item-not-found'))
send_error_reply (stream, get_list.stanza, error)
create_list = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='set')
list_node = xpath.queryForNodes('//list', create_list.query)[0]
assertEquals('invisible', list_node['name'])
assertNotEquals([],
xpath.queryForNodes('/query/list/item/presence-out', create_list.query))
acknowledge_iq(stream, create_list.stanza)
q.expect('dbus-signal', signal='StatusChanged',
args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED])
assertContains("hidden",
conn.Properties.Get(cs.CONN_IFACE_SIMPLE_PRESENCE, "Statuses"))
开发者ID:jku,项目名称:telepathy-gabble,代码行数:28,代码来源:invisible_xep_0126.py
示例4: parse_form
def parse_form(stanza):
fields = xpath.queryForNodes('/iq/query/x/field', stanza)
form = {}
for field in fields:
values = xpath.queryForNodes('/field/value', field)
form[field['var']] = [str(v) for v in values]
return form
开发者ID:Thaodan,项目名称:telepathy-gabble,代码行数:7,代码来源:room-config.py
示例5: extract_disco_parts
def extract_disco_parts(stanza):
identity_nodes = xpath.queryForNodes('/iq/query/identity', stanza)
assertLength(1, identity_nodes)
identity_node = identity_nodes[0]
assertEquals('client', identity_node['category'])
assertDoesNotContain('xml:lang', identity_node.attributes)
identity = 'client/%s//%s' % (identity_node['type'], identity_node['name'])
features = []
for feature in xpath.queryForNodes('/iq/query/feature', stanza):
features.append(feature['var'])
# a quick and ugly data form extractor
x_nodes = xpath.queryForNodes('/iq/query/x', stanza) or []
dataforms = {}
for form in x_nodes:
name = None
fields = {}
for field in xpath.queryForNodes('/x/field', form):
if field['var'] == 'FORM_TYPE':
name = str(field.firstChildElement())
else:
values = [str(x) for x in xpath.queryForNodes('/field/value', field)]
fields[field['var']] = values
if name is not None:
dataforms[name] = fields
return ([identity], features, dataforms)
开发者ID:freedesktop-unofficial-mirror,项目名称:ytstenut__ytstenut-plugins,代码行数:32,代码来源:gabblecaps_helper.py
示例6: test_privacy_list_push_conflict
def test_privacy_list_push_conflict(q, bus, conn, stream):
test_invisible_on_connect(q, bus, conn, stream)
set_id = stream.send_privacy_list_push_iq("invisible")
_, req_list = q.expect_many(
EventPattern('stream-iq', iq_type='result', predicate=lambda event: \
event.stanza['id'] == set_id),
EventPattern('stream-iq', query_ns=ns.PRIVACY, iq_type="get"))
stream.send_privacy_list(req_list.stanza,
[elem('item', type='jid', value='[email protected]', action='allow',
order='1')(elem('presence-out')),
elem('item', action='deny', order='2')(elem('presence-out'))])
create_list = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='set')
created = xpath.queryForNodes('//list', create_list.stanza)[0]
assertEquals(created["name"], 'invisible-gabble')
acknowledge_iq(stream, create_list.stanza)
set_active = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='set')
active = xpath.queryForNodes('//active', set_active.query)[0]
assertEquals('invisible-gabble', active['name'])
acknowledge_iq(stream, set_active.stanza)
开发者ID:jku,项目名称:telepathy-gabble,代码行数:25,代码来源:invisible_xep_0126.py
示例7: check_tube_in_presence
def check_tube_in_presence(presence, initiator):
tubes_nodes = xpath.queryForNodes('/presence/tubes[@xmlns="%s"]'
% ns.TUBES, presence)
assert tubes_nodes is not None
assert len(tubes_nodes) == 1
tube_nodes = xpath.queryForNodes('/tubes/tube', tubes_nodes[0])
assert tube_nodes is not None
assert len(tube_nodes) == 1
for tube in tube_nodes:
tube['type'] = 'dbus'
assert tube['initiator'] == initiator
assert tube['service'] == 'com.example.TestCase'
dbus_stream_id = tube['stream-id']
my_bus_name = tube['dbus-name']
dbus_tube_id = tube['id']
params = {}
parameter_nodes = xpath.queryForNodes('/tube/parameters/parameter', tube)
for node in parameter_nodes:
assert node['name'] not in params
params[node['name']] = (node['type'], str(node))
assert params == {'ay': ('bytes', 'aGVsbG8='),
's': ('str', 'hello'),
'i': ('int', '-123'),
'u': ('uint', '123'),
}
return dbus_stream_id, my_bus_name, dbus_tube_id
开发者ID:Thaodan,项目名称:telepathy-gabble,代码行数:29,代码来源:offer-muc-dbus-tube.py
示例8: expect_socks5_reply
def expect_socks5_reply(q):
event = q.expect('stream-iq', iq_type='result')
iq = event.stanza
query = xpath.queryForNodes('/iq/query', iq)[0]
assert query.uri == ns.BYTESTREAMS
streamhost_used = xpath.queryForNodes('/query/streamhost-used', query)[0]
return streamhost_used
开发者ID:dfghj44444,项目名称:realxtend-naali-deps,代码行数:7,代码来源:bytestream.py
示例9: check_si_reply
def check_si_reply(self, iq):
si = xpath.queryForNodes('/iq/si[@xmlns="%s"]' % ns.SI,
iq)[0]
value = xpath.queryForNodes('/si/feature/x/field/value', si)
assert len(value) == 1
proto = value[0]
assert str(proto) == self.get_ns()
开发者ID:dfghj44444,项目名称:realxtend-naali-deps,代码行数:7,代码来源:bytestream.py
示例10: _check_oob_iq
def _check_oob_iq(self, iq_event):
assert iq_event.iq_type == 'set'
assert iq_event.connection == self.incoming
self.iq = iq_event.stanza
assert self.iq['to'] == self.contact_name
query = self.iq.firstChildElement()
assert query.uri == 'jabber:iq:oob'
url_node = xpath.queryForNodes("/iq/query/url", self.iq)[0]
assert url_node['type'] == 'file'
assert url_node['size'] == str(self.file.size)
assert url_node['mimeType'] == self.file.content_type
self.url = url_node.children[0]
_, self.host, self.filename, _, _, _ = urlparse.urlparse(self.url)
urllib.unquote(self.filename) == self.file.name
desc_node = xpath.queryForNodes("/iq/query/desc", self.iq)[0]
self.desc = desc_node.children[0]
assert self.desc == self.file.description
# Metadata forms
forms = extract_data_forms(xpath.queryForNodes('/iq/query/x', self.iq))
if self.service_name:
assertEquals({'ServiceName': [self.service_name]},
forms[ns.TP_FT_METADATA_SERVICE])
else:
assert ns.TP_FT_METADATA_SERVICE not in forms
if self.metadata:
assertEquals(self.metadata, forms[ns.TP_FT_METADATA])
else:
assert ns.TP_FT_METADATA not in forms
开发者ID:freedesktop-unofficial-mirror,项目名称:telepathy__telepathy-salut,代码行数:31,代码来源:file_transfer_helper.py
示例11: test_invisible_on_connect
def test_invisible_on_connect(q, bus, conn, stream):
props = conn.Properties.GetAll(cs.CONN_IFACE_SIMPLE_PRESENCE)
assertNotEquals({}, props['Statuses'])
presence_event_pattern = EventPattern('stream-presence')
q.forbid_events([presence_event_pattern])
conn.SimplePresence.SetPresence("hidden", "")
conn.Connect()
stream.handle_get_all_privacy_lists(q, bus, conn, ['invisible'])
get_list = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='get')
list_node = xpath.queryForNodes('//list', get_list.query)[0]
assertEquals('invisible', list_node['name'])
stream.send_privacy_list(get_list.stanza,
[elem('item', action='deny', order='1')(elem('presence-out'))])
set_active = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='set')
active = xpath.queryForNodes('//active', set_active.query)[0]
assertEquals('invisible', active['name'])
acknowledge_iq(stream, set_active.stanza)
q.unforbid_events([presence_event_pattern])
q.expect('dbus-signal', signal='StatusChanged',
args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED])
开发者ID:jku,项目名称:telepathy-gabble,代码行数:30,代码来源:invisible_xep_0126.py
示例12: disco_caps
def disco_caps(q, stream, presence):
c_nodes = xpath.queryForNodes('/presence/c', presence.stanza)
assert c_nodes is not None
assert len(c_nodes) == 1
hash = c_nodes[0].attributes['hash']
ver = c_nodes[0].attributes['ver']
node = c_nodes[0].attributes['node']
assert hash == 'sha-1'
# ask caps
request = """
<iq from='[email protected]/resource'
id='disco1'
to='[email protected]/resource'
type='get'>
<query xmlns='""" + ns.DISCO_INFO + """'
node='""" + node + '#' + ver + """'/>
</iq>
"""
stream.send(request)
# receive caps
event = q.expect('stream-iq', query_ns=ns.DISCO_INFO)
features = []
for feature in xpath.queryForNodes('/iq/query/feature', event.stanza):
features.append(feature['var'])
# Check if the hash matches the announced capabilities
assert ver == compute_caps_hash(['client/pc//%s' % PACKAGE_STRING], features, {})
return (event, features)
开发者ID:dfghj44444,项目名称:realxtend-naali-deps,代码行数:32,代码来源:caps_helper.py
示例13: itemsReceived
def itemsReceived(self, item_event):
"""Gather items, convert to html and send the files to there proper location.
"""
for item in item_event.items:
if item.name != 'item': # TODO - handle retract and other events
continue
item_id = item.getAttribute('id', str(time.time()))
date_pub = xpath.queryForNodes("/item/entry/published", item)
published = datetime.datetime.now()
if date_pub:
published = str(date_pub[0])
blog_id = None
blog_ids = xpath.queryForNodes("/item/entry/id", item)
if blog_ids:
blog_id = str(blog_ids[0])
if item.entry.id is None:
log.msg('Wrong format for entry')
continue
# create entry
args = self.blog.atom2hash(item.entry)
self.blog.updateEntry(blog_id, args)
last_items = self.blog.archiveItems()
# update index
self.blog.updateIndex(blog_id, last_items)
# update atom
self.blog.updateAtom(blog_id, last_items)
开发者ID:twonds,项目名称:thetofu.com,代码行数:32,代码来源:bot.py
示例14: _cb_disco_iq
def _cb_disco_iq(self, iq):
nodes = xpath.queryForNodes("/iq/query", iq)
query = nodes[0]
if query.getAttribute('node') is None:
return
node = query.attributes['node']
ver = node.replace("http://telepathy.freedesktop.org/caps#", "")
if iq.getAttribute('type') == 'result':
if FileTransferTest.caps_identities is None or \
FileTransferTest.caps_features is None:
identity_nodes = xpath.queryForNodes('/iq/query/identity', iq)
assertLength(1, identity_nodes)
identity_node = identity_nodes[0]
identity_category = identity_node['category']
identity_type = identity_node['type']
identity_name = identity_node['name']
identity = '%s/%s//%s' % (identity_category, identity_type,
identity_name)
FileTransferTest.caps_identities = [identity]
FileTransferTest.caps_features = []
for feature in xpath.queryForNodes('/iq/query/feature', iq):
FileTransferTest.caps_features.append(feature['var'])
# Check if the hash matches the announced capabilities
assertEquals(compute_caps_hash(FileTransferTest.caps_identities,
FileTransferTest.caps_features,
{}), ver)
if ver == FileTransferTest.caps_ft:
caps_share = compute_caps_hash(FileTransferTest.caps_identities,
FileTransferTest.caps_features + \
[ns.GOOGLE_FEAT_SHARE],
{})
n = query.attributes['node'].replace(ver, caps_share)
query.attributes['node'] = n
for feature in xpath.queryForNodes('/iq/query/feature', iq):
query.children.remove(feature)
for f in FileTransferTest.caps_features + [ns.GOOGLE_FEAT_SHARE]:
el = domish.Element((None, 'feature'))
el['var'] = f
query.addChild(el)
elif iq.getAttribute('type') == 'get':
caps_share = compute_caps_hash(FileTransferTest.caps_identities,
FileTransferTest.caps_features + \
[ns.GOOGLE_FEAT_SHARE],
{})
if ver == caps_share:
n = query.attributes['node'].replace(ver,
FileTransferTest.caps_ft)
query.attributes['node'] = n
开发者ID:jku,项目名称:telepathy-gabble,代码行数:60,代码来源:file_transfer_helper.py
示例15: test
def test(q, bus, conn, stream):
# This sidecar sends a stanza, and waits for a reply, before being
# created.
pattern = EventPattern('stream-iq', to='sidecar.example.com',
query_ns='http://example.com/sidecar')
call_async(q, conn.Sidecars1, 'EnsureSidecar', TEST_PLUGIN_IFACE + ".IQ")
e = q.expect_many(pattern)[0]
# The server said yes, so we should get a sidecar back!
acknowledge_iq(stream, e.stanza)
q.expect('dbus-return', method='EnsureSidecar')
identities = ["test/app-list//Test"]
features = ["com.example.test1", "com.example.test2"]
ver = compute_caps_hash(identities, features, {})
iq = IQ(stream, "get")
query = iq.addElement((ns.DISCO_INFO, 'query'))
query['node'] = ns.GABBLE_CAPS + '#' + ver
stream.send(iq)
e = q.expect('stream-iq', query_ns='http://jabber.org/protocol/disco#info')
returned_features = [feature['var']
for feature in xpath.queryForNodes('/iq/query/feature', e.stanza)]
assertEquals(features, returned_features)
returned_identities = [identity['category'] + "/" + identity['type']+"//" + identity['name']
for identity in xpath.queryForNodes('/iq/query/identity', e.stanza)]
assertEquals(identities, returned_identities)
new_ver = compute_caps_hash(returned_identities, returned_features, {})
assertEquals(new_ver, ver)
开发者ID:Thaodan,项目名称:telepathy-gabble,代码行数:32,代码来源:sidecar-own-caps.py
示例16: test
def test(q, bus, conn, stream):
muc_handle = request_muc_handle(q, conn, stream, '[email protected]')
call_async(q, conn, 'RequestChannel', cs.CHANNEL_TYPE_TEXT, cs.HT_ROOM,
muc_handle, True)
q.expect('stream-presence', to='[email protected]/test')
# Send presence for own membership of room.
stream.send(
make_muc_presence('owner', 'moderator', '[email protected]', 'test'))
iq, ret = q.expect_many(
EventPattern('stream-iq', to='[email protected]', iq_type='get',
query_ns=ns.MUC_OWNER),
EventPattern('dbus-return', method='RequestChannel'))
handle_muc_get_iq(stream, iq.stanza)
text_chan = wrap_channel(
bus.get_object(conn.bus_name, ret.value[0]), 'Text')
props = dict([(name, id)
for id, name, sig, flags in text_chan.TpProperties.ListProperties()])
call_async(q, text_chan.TpProperties, 'SetProperties',
[(props['password'], 'foo'), (props['password-required'], True)])
event = q.expect('stream-iq', to='[email protected]', iq_type='get',
query_ns=ns.MUC_OWNER)
handle_muc_get_iq(stream, event.stanza)
event = q.expect('stream-iq', to='[email protected]', iq_type='set',
query_ns=ns.MUC_OWNER)
fields = xpath.queryForNodes('/iq/query/x/field', event.stanza)
form = {}
for field in fields:
values = xpath.queryForNodes('/field/value', field)
form[field['var']] = [str(v) for v in values]
assert form == {'password': ['foo'], 'password_protected': ['1'],
'muc#roomconfig_presencebroadcast' :
['moderator', 'participant', 'visitor']}
acknowledge_iq(stream, event.stanza)
event = q.expect('dbus-signal', signal='PropertiesChanged')
assert event.args == [[(props['password'], 'foo'),
(props['password-required'], True)]]
q.expect('dbus-return', method='SetProperties', value=())
call_async(q, text_chan.TpProperties, 'SetProperties',
[(31337, 'foo'), (props['password-required'], True)])
q.expect('dbus-error', name=cs.INVALID_ARGUMENT)
call_async(q, text_chan.TpProperties, 'SetProperties',
[(props['password'], True), (props['password-required'], 'foo')])
q.expect('dbus-error', name=cs.NOT_AVAILABLE)
call_async(q, text_chan.TpProperties, 'SetProperties',
[(props['subject-contact'], 42)])
q.expect('dbus-error', name=cs.PERMISSION_DENIED)
开发者ID:jku,项目名称:telepathy-gabble,代码行数:59,代码来源:test-muc-properties.py
示例17: test
def test(q, bus, conn, stream):
iq_event = q.expect('stream-iq', to=None, query_ns='vcard-temp',
query_name='vCard')
acknowledge_iq(stream, iq_event.stanza)
# send diso request
m = domish.Element((None, 'iq'))
m['from'] = '[email protected]'
m['id'] = '1'
m['type'] = 'get'
query = m.addElement('query')
query['xmlns'] = ns.DISCO_INFO
stream.send(m)
# wait for disco response
event = q.expect('stream-iq', iq_type='result',
query_ns=ns.DISCO_INFO,
to='[email protected]')
features = set([str(f['var']) for f in xpath.queryForNodes('/iq/query/feature',
event.stanza)])
# OLPC NS aren't announced
assert len(olpc_features.intersection(features)) == 0
# Use OLPC interface
buddy_info_iface = dbus.Interface(conn, 'org.laptop.Telepathy.BuddyInfo')
call_async(q, buddy_info_iface, 'SetProperties',
{'color': '#ff0000,#0000ff'})
# wait for <presence> stanza
event = q.expect('stream-presence')
c_nodes = xpath.queryForNodes('/presence/c', event.stanza)
assert c_nodes is not None
assert len(c_nodes) == 1
# send diso request
m = domish.Element((None, 'iq'))
m['from'] = '[email protected]'
m['id'] = '2'
m['type'] = 'get'
query = m.addElement('query')
query['xmlns'] = ns.DISCO_INFO
stream.send(m)
# wait for disco response
event = q.expect('stream-iq', iq_type='result',
query_ns=ns.DISCO_INFO,
to='[email protected]')
assert event.stanza['id'] == '2'
# OLPC NS are now announced
features = set([str(f['var']) for f in xpath.queryForNodes('/iq/query/feature',
event.stanza)])
assert olpc_features.issubset(features)
开发者ID:Thaodan,项目名称:telepathy-gabble,代码行数:57,代码来源:test-olpc-bundle.py
示例18: test
def test(q, bus, conn, stream):
self_presence = q.expect('stream-presence')
c = xpath.queryForNodes('/presence/c', self_presence.stanza)[0]
jid = '[email protected]/omg'
# Gabble shouldn't send any disco requests to our contact during this test.
q.forbid_events([
EventPattern('stream-iq', to=jid, iq_type='get',
query_ns=ns.DISCO_INFO),
])
# Check that Gabble doesn't disco other clients with the same caps hash.
p = make_presence(jid,
caps={'node': c['node'],
'hash': c['hash'],
'ver': c['ver'],
})
stream.send(p)
sync_stream(q, stream)
# Check that Gabble doesn't disco its own ext='' bundles (well, its own
# bundles as advertised by Gabbles that don't do hashed caps)
p = make_presence(jid,
caps={'node': c['node'],
'ver': c['ver'],
# omitting hash='' so Gabble doesn't ignore ext=''
'ext': 'voice-v1 video-v1',
})
stream.send(p)
sync_stream(q, stream)
# Advertise some different capabilities, to change our own caps hash.
add = [(cs.CHANNEL_TYPE_STREAMED_MEDIA, 2L**32-1),
(cs.CHANNEL_TYPE_STREAM_TUBE, 2L**32-1),
(cs.CHANNEL_TYPE_STREAM_TUBE, 2L**32-1)]
remove = []
caps = conn.Capabilities.AdvertiseCapabilities(add, remove)
self_presence = q.expect('stream-presence')
c_ = xpath.queryForNodes('/presence/c', self_presence.stanza)[0]
assertNotEquals(c['ver'], c_['ver'])
# But then someone asks us for our old caps
iq = IQ(stream, 'get')
iq['from'] = jid
query = iq.addElement((ns.DISCO_INFO, 'query'))
query['node'] = c['node'] + '#' + c['ver']
stream.send(iq)
# Gabble should still know what they are, and reply. This is actually quite
# important: there's a bug in iChat where if you return an error to a disco
# query, it just asks again, and again, and again...
reply = q.expect('stream-iq', to=jid)
assertEquals('result', reply.iq_type)
开发者ID:jku,项目名称:telepathy-gabble,代码行数:56,代码来源:trust-thyself.py
示例19: _wait_activation_iq
def _wait_activation_iq(self):
e = self.q.expect('stream-iq', iq_type='set', to='proxy.localhost',
query_ns=ns.BYTESTREAMS)
query = xpath.queryForNodes('/iq/query', e.stanza)[0]
assert query['sid'] == self.stream_id
activate = xpath.queryForNodes('/iq/query/activate', e.stanza)[0]
assert str(activate) == self.target
self._reply_activation_iq(e.stanza)
开发者ID:dfghj44444,项目名称:realxtend-naali-deps,代码行数:10,代码来源:bytestream.py
示例20: processMessageGC
def processMessageGC(self, elem):
"""Process a stanza element that is from a chatroom"""
# Ignore all messages that are x-stamp (delayed / room history)
# <delay xmlns='urn:xmpp:delay' stamp='2016-05-06T20:04:17.513Z'
# from='[email protected]/twisted_words'/>
if xpath.queryForNodes("/message/delay[@xmlns='urn:xmpp:delay']",
elem):
return
_from = jid.JID(elem["from"])
room = _from.user
res = _from.resource
body = xpath.queryForString('/message/body', elem)
if body is not None and len(body) >= 4 and body[:4] == "ping":
self.send_groupchat(room, "%s: %s" % (res, self.get_fortune()))
# Look for bot commands
if re.match(r"^%s:" % (self.name,), body):
self.process_groupchat_cmd(room, res, body[7:].strip())
# In order for the message to be logged, it needs to be from iembot
# and have a channels attribute
if res is None or res != 'iembot':
return
a = xpath.queryForNodes("/message/x[@xmlns='nwschat:nwsbot']", elem)
if a is None or len(a) == 0:
return
if room not in CHATLOG:
CHATLOG[room] = {'seqnum': [-1]*40, 'timestamps': [0]*40,
'log': ['']*40, 'author': ['']*40,
'product_id': ['']*40, 'txtlog': ['']*40}
ts = datetime.datetime.utcnow()
product_id = ''
if elem.x and elem.x.hasAttribute("product_id"):
product_id = elem.x['product_id']
html = xpath.queryForNodes('/message/html/body', elem)
logEntry = body
if html is not None:
logEntry = html[0].toXml()
CHATLOG[room]['seqnum'] = (CHATLOG[room]['seqnum'][1:] +
[self.next_seqnum(), ])
CHATLOG[room]['timestamps'] = (CHATLOG[room]['timestamps'][1:] +
[ts.strftime("%Y%m%d%H%M%S"), ])
CHATLOG[room]['author'] = CHATLOG[room]['author'][1:] + [res, ]
CHATLOG[room]['product_id'] = (CHATLOG[room]['product_id'][1:] +
[product_id, ])
CHATLOG[room]['log'] = CHATLOG[room]['log'][1:] + [logEntry, ]
CHATLOG[room]['txtlog'] = CHATLOG[room]['txtlog'][1:] + [body, ]
开发者ID:akrherz,项目名称:iembot,代码行数:54,代码来源:iemchatbot.py
注:本文中的twisted.words.xish.xpath.queryForNodes函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论