Fix the uses of stanza.reply()

This is relying on the stanzas being copied for each handler. We no
longer do that for performance reasons, so instead of editing the copy
in-place, stanza.reply() now returns a new stanza.
This commit is contained in:
mathieui
2015-02-12 12:17:01 +01:00
parent 8b36e918e8
commit f6b3a0c6cf
19 changed files with 83 additions and 84 deletions
+8 -4
View File
@@ -93,7 +93,8 @@ class XEP_0009(BasePlugin):
def _item_not_found(self, iq):
payload = iq.get_payload()
iq.reply().error().set_payload(payload)
iq = iq.reply()
iq.error().set_payload(payload)
iq['error']['code'] = '404'
iq['error']['type'] = 'cancel'
iq['error']['condition'] = 'item-not-found'
@@ -101,7 +102,8 @@ class XEP_0009(BasePlugin):
def _undefined_condition(self, iq):
payload = iq.get_payload()
iq.reply().error().set_payload(payload)
iq = iq.reply()
iq.error().set_payload(payload)
iq['error']['code'] = '500'
iq['error']['type'] = 'cancel'
iq['error']['condition'] = 'undefined-condition'
@@ -109,7 +111,8 @@ class XEP_0009(BasePlugin):
def _forbidden(self, iq):
payload = iq.get_payload()
iq.reply().error().set_payload(payload)
iq = iq.reply()
iq.error().set_payload(payload)
iq['error']['code'] = '403'
iq['error']['type'] = 'auth'
iq['error']['condition'] = 'forbidden'
@@ -117,7 +120,8 @@ class XEP_0009(BasePlugin):
def _recipient_unvailable(self, iq):
payload = iq.get_payload()
iq.reply().error().set_payload(payload)
iq = iq.reply()
error().set_payload(payload)
iq['error']['code'] = '404'
iq['error']['type'] = 'wait'
iq['error']['condition'] = 'recipient-unavailable'
+1 -2
View File
@@ -132,8 +132,7 @@ class XEP_0012(BasePlugin):
if not isinstance(iq, Iq):
reply = self.xmpp.Iq()
else:
iq.reply()
reply = iq
reply = iq.reply()
if jid not in self._last_activities:
raise XMPPError('service-unavailable')
+1 -2
View File
@@ -67,8 +67,7 @@ class XEP_0027(BasePlugin):
register_stanza_plugin(Message, Encrypted)
self.xmpp.add_event_handler('unverified_signed_presence',
self._handle_unverified_signed_presence,
threaded=True)
self._handle_unverified_signed_presence)
self.xmpp.register_handler(
Callback('Signed Presence',
+2 -2
View File
@@ -634,7 +634,7 @@ class XEP_0030(BasePlugin):
info['id'] = iq['id']
info.send()
else:
iq.reply()
iq = iq.reply()
if info:
info = self._fix_default_info(info)
iq.set_payload(info.xml)
@@ -674,7 +674,7 @@ class XEP_0030(BasePlugin):
if isinstance(items, Iq):
items.send()
else:
iq.reply()
iq = iq.reply()
if items:
iq.set_payload(items.xml)
iq.send()
+1 -2
View File
@@ -191,8 +191,7 @@ class XEP_0047(BasePlugin):
self.window_size)
stream.stream_started.set()
self.api['set_stream'](stream.self_jid, stream.sid, stream.peer_jid, stream)
iq.reply()
iq.send()
iq.reply().send()
self.xmpp.event('ibb_stream_start', stream)
self.xmpp.event('stream:%s:%s' % (sid, stream.peer_jid), stream)
+2 -4
View File
@@ -103,8 +103,7 @@ class IBBytestream(object):
self.xmpp.event('ibb_stream_data', {'stream': self, 'data': data})
if isinstance(stanza, Iq):
stanza.reply()
stanza.send()
stanza.reply().send()
def recv(self, *args, **kwargs):
return self.read(block=True)
@@ -134,8 +133,7 @@ class IBBytestream(object):
def _closed(self, iq):
self.stream_in_closed.set()
self.stream_out_closed.set()
iq.reply()
iq.send()
iq.reply().send()
self.xmpp.event('ibb_stream_end', self)
def makefile(self, *args, **kwargs):
+3 -3
View File
@@ -339,7 +339,7 @@ class XEP_0050(BasePlugin):
for item in payload:
register_stanza_plugin(Command, item.__class__, iterable=True)
iq.reply()
iq = iq.reply()
iq['command']['node'] = session['node']
iq['command']['sessionid'] = session['id']
@@ -382,7 +382,7 @@ class XEP_0050(BasePlugin):
if handler:
handler(iq, session)
del self.sessions[sessionid]
iq.reply()
iq = iq.reply()
iq['command']['node'] = node
iq['command']['sessionid'] = sessionid
iq['command']['status'] = 'canceled'
@@ -421,7 +421,7 @@ class XEP_0050(BasePlugin):
del self.sessions[sessionid]
iq.reply()
iq = iq.reply()
iq['command']['node'] = node
iq['command']['sessionid'] = sessionid
iq['command']['actions'] = []
+1 -1
View File
@@ -127,7 +127,7 @@ class XEP_0054(BasePlugin):
if isinstance(vcard, Iq):
vcard.send()
else:
iq.reply()
iq = iq.reply()
iq.append(vcard)
iq.send()
elif iq['type'] == 'set':
+1 -1
View File
@@ -178,7 +178,7 @@ class XEP_0065(BasePlugin):
else:
raise XMPPError(etype='cancel', condition='item-not-found')
iq.reply()
iq = iq.reply()
with self._sessions_lock:
self._sessions[sid] = conn
iq['socks']['sid'] = sid
+1 -1
View File
@@ -64,7 +64,7 @@ class XEP_0092(BasePlugin):
Arguments:
iq -- The Iq stanza containing the software version query.
"""
iq.reply()
iq = iq.reply()
iq['software_version']['name'] = self.software_name
iq['software_version']['version'] = self.version
iq['software_version']['os'] = self.os
+1 -1
View File
@@ -72,7 +72,7 @@ class XEP_0202(BasePlugin):
Arguments:
iq -- The Iq time request stanza.
"""
iq.reply()
iq = iq.reply()
iq['entity_time']['time'] = self.local_time(iq['to'])
iq.send()
+1 -1
View File
@@ -115,7 +115,7 @@ class XEP_0231(BasePlugin):
data.send()
return
iq.reply()
iq = iq.reply()
iq.append(data)
iq.send()
+10 -10
View File
@@ -303,11 +303,11 @@ class XEP_0323(BasePlugin):
#print("added session: " + str(self.sessions))
iq.reply()
iq = iq.reply()
iq['accepted']['seqnr'] = seqnr
if not request_delay_sec is None:
iq['accepted']['queued'] = "true"
iq.send(block=False)
iq.send()
self.sessions[session]["node_list"] = process_nodes
@@ -327,11 +327,11 @@ class XEP_0323(BasePlugin):
self._threaded_node_request(session, process_fields, req_flags)
else:
iq.reply()
iq = iq.reply()
iq['type'] = 'error'
iq['rejected']['seqnr'] = seqnr
iq['rejected']['error'] = error_msg
iq.send(block=False)
iq.send()
def _threaded_node_request(self, session, process_fields, flags):
"""
@@ -515,21 +515,21 @@ class XEP_0323(BasePlugin):
self.sessions[s]["commTimers"][n].cancel()
# Confirm
iq.reply()
iq = iq.reply()
iq['type'] = 'result'
iq['cancelled']['seqnr'] = seqnr
iq.send(block=False)
iq.send()
# Delete session
del self.sessions[s]
return
# Could not find session, send reject
iq.reply()
iq = iq.reply()
iq['type'] = 'error'
iq['rejected']['seqnr'] = seqnr
iq['rejected']['error'] = "Cancel request received, no matching request is active."
iq.send(block=False)
iq.send()
# =================================================================
# Client side (data retriever) API
@@ -610,7 +610,7 @@ class XEP_0323(BasePlugin):
iq['req']._set_flags(flags)
self.sessions[seqnr] = {"from": iq['from'], "to": iq['to'], "seqnr": seqnr, "callback": callback}
iq.send(block=False)
iq.send()
return seqnr
@@ -631,7 +631,7 @@ class XEP_0323(BasePlugin):
iq['type'] = "get"
iq['id'] = seqnr
iq['cancel']['seqnr'] = seqnr
iq.send(block=False)
iq.send()
def _get_new_seqnr(self):
""" Returns a unique sequence number (unique across threads) """
+6 -6
View File
@@ -273,7 +273,7 @@ class XEP_0325(BasePlugin):
self._threaded_node_request(session, process_fields)
else:
iq.reply()
iq = iq.reply()
iq['type'] = 'error'
iq['setResponse']['responseCode'] = "NotFound"
if missing_node is not None:
@@ -282,7 +282,7 @@ class XEP_0325(BasePlugin):
iq['setResponse'].add_data(missing_field)
iq['setResponse']['error']['var'] = "Output"
iq['setResponse']['error']['text'] = error_msg
iq.send(block=False)
iq.send()
def _handle_direct_set(self, msg):
"""
@@ -382,7 +382,7 @@ class XEP_0325(BasePlugin):
iq['setResponse'].add_node(nodeId)
iq['setResponse']['error']['var'] = "Output"
iq['setResponse']['error']['text'] = "Timeout."
iq.send(block=False)
iq.send()
## TODO - should we send one timeout per node??
@@ -443,7 +443,7 @@ class XEP_0325(BasePlugin):
iq['setResponse'].add_data(error_field)
iq['setResponse']['error']['var'] = error_field
iq['setResponse']['error']['text'] = error_msg
iq.send(block=False)
iq.send()
# Drop communication with this device and check if we are done
self.sessions[session]["nodeDone"][nodeId] = True
@@ -463,7 +463,7 @@ class XEP_0325(BasePlugin):
iq['type'] = "result"
iq['id'] = self.sessions[session]['seqnr']
iq['setResponse']['responseCode'] = "OK"
iq.send(block=False)
iq.send()
# The session is complete, delete it
del self.sessions[session]
@@ -526,7 +526,7 @@ class XEP_0325(BasePlugin):
iq['set'].add_data(name=name, typename=typename, value=value)
self.sessions[seqnr] = {"from": iq['from'], "to": iq['to'], "callback": callback}
iq.send(block=False)
iq.send()
def set_command(self, from_jid, to_jid, fields, nodeIds=None):
"""