massive refactoring to switch from camelCase to snake_case:
historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a pre-PEP8 code, to use the same coding style as in Twisted. However, snake_case is more readable and it's better to follow PEP8 best practices, so it has been decided to move on full snake_case. Because Libervia has a huge codebase, this ended with a ugly mix of camelCase and snake_case. To fix that, this patch does a big refactoring by renaming every function and method (including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case. This is a massive change, and may result in some bugs.
This commit is contained in:
parent
d50412c7f7
commit
6a6f15707a
1 changed files with 9945 additions and 9945 deletions
|
|
@ -71,13 +71,13 @@ class XEP_0047(object):
|
|||
log.info(_("In-Band Bytestreams plugin initialization"))
|
||||
self.host = host
|
||||
|
||||
def getHandler(self, client):
|
||||
def get_handler(self, client):
|
||||
return XEP_0047_handler(self)
|
||||
|
||||
def profileConnected(self, client):
|
||||
def profile_connected(self, client):
|
||||
client.xep_0047_current_stream = {} # key: stream_id, value: data(dict)
|
||||
|
||||
def _timeOut(self, sid, client):
|
||||
def _time_out(self, sid, client):
|
||||
"""Delete current_stream id, called after timeout
|
||||
|
||||
@param sid(unicode): session id of client.xep_0047_current_stream
|
||||
|
|
@ -88,9 +88,9 @@ class XEP_0047(object):
|
|||
sid=sid, profile=client.profile
|
||||
)
|
||||
)
|
||||
self._killSession(sid, client, "TIMEOUT")
|
||||
self._kill_session(sid, client, "TIMEOUT")
|
||||
|
||||
def _killSession(self, sid, client, failure_reason=None):
|
||||
def _kill_session(self, sid, client, failure_reason=None):
|
||||
"""Delete a current_stream id, clean up associated observers
|
||||
|
||||
@param sid(unicode): session id
|
||||
|
|
@ -124,18 +124,18 @@ class XEP_0047(object):
|
|||
else:
|
||||
stream_d.errback(failure.Failure(exceptions.DataError(failure_reason)))
|
||||
|
||||
def createSession(self, *args, **kwargs):
|
||||
"""like [_createSession] but return the session deferred instead of the whole session
|
||||
def create_session(self, *args, **kwargs):
|
||||
"""like [_create_session] but return the session deferred instead of the whole session
|
||||
|
||||
session deferred is fired when transfer is finished
|
||||
"""
|
||||
return self._createSession(*args, **kwargs)[DEFER_KEY]
|
||||
return self._create_session(*args, **kwargs)[DEFER_KEY]
|
||||
|
||||
def _createSession(self, client, stream_object, local_jid, to_jid, sid):
|
||||
def _create_session(self, client, stream_object, local_jid, to_jid, sid):
|
||||
"""Called when a bytestream is imminent
|
||||
|
||||
@param stream_object(IConsumer): stream object where data will be written
|
||||
@param local_jid(jid.JID): same as [startStream]
|
||||
@param local_jid(jid.JID): same as [start_stream]
|
||||
@param to_jid(jid.JId): jid of the other peer
|
||||
@param sid(unicode): session id
|
||||
@return (dict): session data
|
||||
|
|
@ -149,12 +149,12 @@ class XEP_0047(object):
|
|||
"to": to_jid,
|
||||
"stream_object": stream_object,
|
||||
"seq": -1,
|
||||
"timer": reactor.callLater(TIMEOUT, self._timeOut, sid, client),
|
||||
"timer": reactor.callLater(TIMEOUT, self._time_out, sid, client),
|
||||
}
|
||||
|
||||
return session_data
|
||||
|
||||
def _onIBBOpen(self, iq_elt, client):
|
||||
def _on_ibb_open(self, iq_elt, client):
|
||||
""""Called when an IBB <open> element is received
|
||||
|
||||
@param iq_elt(domish.Element): the whole <iq> stanza
|
||||
|
|
@ -186,18 +186,18 @@ class XEP_0047(object):
|
|||
session_data["event_data"] = event_data = (
|
||||
IBB_MESSAGE_DATA if stanza == "message" else IBB_IQ_DATA
|
||||
).format(sid)
|
||||
session_data["observer_cb"] = observer_cb = self._onIBBData
|
||||
session_data["observer_cb"] = observer_cb = self._on_ibb_data
|
||||
event_close = IBB_CLOSE.format(sid)
|
||||
# we now set the stream observer to look after data packet
|
||||
# FIXME: if we never get the events, the observers stay.
|
||||
# would be better to have generic observer and check id once triggered
|
||||
client.xmlstream.addObserver(event_data, observer_cb, client=client)
|
||||
client.xmlstream.addOnetimeObserver(event_close, self._onIBBClose, client=client)
|
||||
client.xmlstream.addOnetimeObserver(event_close, self._on_ibb_close, client=client)
|
||||
# finally, we send the accept stanza
|
||||
iq_result_elt = xmlstream.toResponse(iq_elt, "result")
|
||||
client.send(iq_result_elt)
|
||||
|
||||
def _onIBBClose(self, iq_elt, client):
|
||||
def _on_ibb_close(self, iq_elt, client):
|
||||
""""Called when an IBB <close> element is received
|
||||
|
||||
@param iq_elt(domish.Element): the whole <iq> stanza
|
||||
|
|
@ -210,9 +210,9 @@ class XEP_0047(object):
|
|||
|
||||
iq_result_elt = xmlstream.toResponse(iq_elt, "result")
|
||||
client.send(iq_result_elt)
|
||||
self._killSession(sid, client)
|
||||
self._kill_session(sid, client)
|
||||
|
||||
def _onIBBData(self, element, client):
|
||||
def _on_ibb_data(self, element, client):
|
||||
"""Observer called on <iq> or <message> stanzas with data element
|
||||
|
||||
Manage the data elelement (check validity and write to the stream_object)
|
||||
|
|
@ -247,7 +247,7 @@ class XEP_0047(object):
|
|||
if element.name == "iq":
|
||||
reason = "not-acceptable"
|
||||
self._sendError(reason, sid, element, client)
|
||||
self.terminateStream(session_data, client, reason)
|
||||
self.terminate_stream(session_data, client, reason)
|
||||
return
|
||||
|
||||
# we reset the timeout:
|
||||
|
|
@ -261,7 +261,7 @@ class XEP_0047(object):
|
|||
log.warning(_("Invalid base64 data"))
|
||||
if element.name == "iq":
|
||||
self._sendError("not-acceptable", sid, element, client)
|
||||
self.terminateStream(session_data, client, reason)
|
||||
self.terminate_stream(session_data, client, reason)
|
||||
return
|
||||
|
||||
# we can now ack success
|
||||
|
|
@ -284,10 +284,10 @@ class XEP_0047(object):
|
|||
)
|
||||
)
|
||||
if sid is not None:
|
||||
self._killSession(sid, client, error_condition)
|
||||
self._kill_session(sid, client, error_condition)
|
||||
client.send(iq_elt)
|
||||
|
||||
def startStream(self, client, stream_object, local_jid, to_jid, sid, block_size=None):
|
||||
def start_stream(self, client, stream_object, local_jid, to_jid, sid, block_size=None):
|
||||
"""Launch the stream workflow
|
||||
|
||||
@param stream_object(ifaces.IStreamProducer): stream object to send
|
||||
|
|
@ -299,7 +299,7 @@ class XEP_0047(object):
|
|||
@param sid(unicode): Stream session id
|
||||
@param block_size(int, None): size of the block (or None for default)
|
||||
"""
|
||||
session_data = self._createSession(client, stream_object, local_jid, to_jid, sid)
|
||||
session_data = self._create_session(client, stream_object, local_jid, to_jid, sid)
|
||||
|
||||
if block_size is None:
|
||||
block_size = XEP_0047.BLOCK_SIZE
|
||||
|
|
@ -315,10 +315,10 @@ class XEP_0047(object):
|
|||
open_elt["stanza"] = "iq" # TODO: manage <message> stanza ?
|
||||
args = [session_data, client]
|
||||
d = iq_elt.send()
|
||||
d.addCallbacks(self._IQDataStreamCb, self._IQDataStreamEb, args, None, args)
|
||||
d.addCallbacks(self._iq_data_stream_cb, self._iq_data_stream_eb, args, None, args)
|
||||
return session_data[DEFER_KEY]
|
||||
|
||||
def _IQDataStreamCb(self, iq_elt, session_data, client):
|
||||
def _iq_data_stream_cb(self, iq_elt, session_data, client):
|
||||
"""Called during the whole data streaming
|
||||
|
||||
@param iq_elt(domish.Element): iq result
|
||||
|
|
@ -340,18 +340,18 @@ class XEP_0047(object):
|
|||
data_elt.addContent(base64.b64encode(buffer_).decode())
|
||||
args = [session_data, client]
|
||||
d = next_iq_elt.send()
|
||||
d.addCallbacks(self._IQDataStreamCb, self._IQDataStreamEb, args, None, args)
|
||||
d.addCallbacks(self._iq_data_stream_cb, self._iq_data_stream_eb, args, None, args)
|
||||
else:
|
||||
self.terminateStream(session_data, client)
|
||||
self.terminate_stream(session_data, client)
|
||||
|
||||
def _IQDataStreamEb(self, failure, session_data, client):
|
||||
def _iq_data_stream_eb(self, failure, session_data, client):
|
||||
if failure.check(error.StanzaError):
|
||||
log.warning("IBB transfer failed: {}".format(failure.value))
|
||||
else:
|
||||
log.error("IBB transfer failed: {}".format(failure.value))
|
||||
self.terminateStream(session_data, client, "IQ_ERROR")
|
||||
self.terminate_stream(session_data, client, "IQ_ERROR")
|
||||
|
||||
def terminateStream(self, session_data, client, failure_reason=None):
|
||||
def terminate_stream(self, session_data, client, failure_reason=None):
|
||||
"""Terminate the stream session
|
||||
|
||||
@param session_data(dict): data of this streaming session
|
||||
|
|
@ -364,7 +364,7 @@ class XEP_0047(object):
|
|||
close_elt = iq_elt.addElement((NS_IBB, "close"))
|
||||
close_elt["sid"] = session_data["id"]
|
||||
iq_elt.send()
|
||||
self._killSession(session_data["id"], client, failure_reason)
|
||||
self._kill_session(session_data["id"], client, failure_reason)
|
||||
|
||||
|
||||
@implementer(iwokkel.IDisco)
|
||||
|
|
@ -375,7 +375,7 @@ class XEP_0047_handler(XMPPHandler):
|
|||
|
||||
def connectionInitialized(self):
|
||||
self.xmlstream.addObserver(
|
||||
IBB_OPEN, self.plugin_parent._onIBBOpen, client=self.parent
|
||||
IBB_OPEN, self.plugin_parent._on_ibb_open, client=self.parent
|
||||
)
|
||||
|
||||
def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
|
||||
|
|
|
|||
Loading…
Reference in a new issue