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
|
|
@ -60,7 +60,7 @@ class StreamProtocol(protocol.Protocol):
|
|||
def __init__(self):
|
||||
self.pause = False
|
||||
|
||||
def setPause(self, paused):
|
||||
def set_pause(self, paused):
|
||||
# in Python 2.x, Twisted classes are old style
|
||||
# so we can use property and setter
|
||||
if paused:
|
||||
|
|
@ -78,10 +78,10 @@ class StreamProtocol(protocol.Protocol):
|
|||
def connectionMade(self):
|
||||
if self.factory.client_conn is not None:
|
||||
self.transport.loseConnection()
|
||||
self.factory.setClientConn(self)
|
||||
self.factory.set_client_conn(self)
|
||||
|
||||
def dataReceived(self, data):
|
||||
self.factory.writeToConsumer(data)
|
||||
self.factory.write_to_consumer(data)
|
||||
|
||||
def sendData(self, data):
|
||||
self.transport.write(data)
|
||||
|
|
@ -92,9 +92,9 @@ class StreamProtocol(protocol.Protocol):
|
|||
return
|
||||
|
||||
if reason.type == error.ConnectionDone:
|
||||
self.factory.streamFinished()
|
||||
self.factory.stream_finished()
|
||||
else:
|
||||
self.factory.streamFailed(reason)
|
||||
self.factory.stream_failed(reason)
|
||||
|
||||
|
||||
@interface.implementer(stream.IStreamProducer)
|
||||
|
|
@ -109,15 +109,15 @@ class StreamFactory(protocol.Factory):
|
|||
def __init__(self):
|
||||
self.client_conn = None
|
||||
|
||||
def setClientConn(self, stream_protocol):
|
||||
def set_client_conn(self, stream_protocol):
|
||||
# in Python 2.x, Twisted classes are old style
|
||||
# so we can use property and setter
|
||||
assert self.client_conn is None
|
||||
self.client_conn = stream_protocol
|
||||
if self.consumer is None:
|
||||
self.client_conn.setPause(True)
|
||||
self.client_conn.set_pause(True)
|
||||
|
||||
def startStream(self, consumer):
|
||||
def start_stream(self, consumer):
|
||||
if self.consumer is not None:
|
||||
raise exceptions.InternalError(
|
||||
_("stream can't be used with multiple consumers")
|
||||
|
|
@ -127,17 +127,17 @@ class StreamFactory(protocol.Factory):
|
|||
consumer.registerProducer(self, True)
|
||||
self.deferred = defer.Deferred()
|
||||
if self.client_conn is not None:
|
||||
self.client_conn.setPause(False)
|
||||
self.client_conn.set_pause(False)
|
||||
return self.deferred
|
||||
|
||||
def streamFinished(self):
|
||||
def stream_finished(self):
|
||||
self.client_conn = None
|
||||
if self.consumer:
|
||||
self.consumer.unregisterProducer()
|
||||
self.port_listening.stopListening()
|
||||
self.deferred.callback(None)
|
||||
|
||||
def streamFailed(self, failure_):
|
||||
def stream_failed(self, failure_):
|
||||
self.client_conn = None
|
||||
if self.consumer:
|
||||
self.consumer.unregisterProducer()
|
||||
|
|
@ -146,7 +146,7 @@ class StreamFactory(protocol.Factory):
|
|||
elif self.producer:
|
||||
self.producer.stopProducing()
|
||||
|
||||
def stopStream(self):
|
||||
def stop_stream(self):
|
||||
if self.client_conn is not None:
|
||||
self.client_conn.disconnect()
|
||||
|
||||
|
|
@ -154,10 +154,10 @@ class StreamFactory(protocol.Factory):
|
|||
self.producer = producer
|
||||
|
||||
def pauseProducing(self):
|
||||
self.client_conn.setPause(True)
|
||||
self.client_conn.set_pause(True)
|
||||
|
||||
def resumeProducing(self):
|
||||
self.client_conn.setPause(False)
|
||||
self.client_conn.set_pause(False)
|
||||
|
||||
def stopProducing(self):
|
||||
if self.client_conn:
|
||||
|
|
@ -169,7 +169,7 @@ class StreamFactory(protocol.Factory):
|
|||
except AttributeError:
|
||||
log.warning(_("No client connected, can't send data"))
|
||||
|
||||
def writeToConsumer(self, data):
|
||||
def write_to_consumer(self, data):
|
||||
self.consumer.write(data)
|
||||
|
||||
|
||||
|
|
@ -180,23 +180,23 @@ class JingleStream(object):
|
|||
log.info(_("Plugin Stream initialization"))
|
||||
self.host = host
|
||||
self._j = host.plugins["XEP-0166"] # shortcut to access jingle
|
||||
self._j.registerApplication(NS_STREAM, self)
|
||||
host.bridge.addMethod(
|
||||
"streamOut",
|
||||
self._j.register_application(NS_STREAM, self)
|
||||
host.bridge.add_method(
|
||||
"stream_out",
|
||||
".plugin",
|
||||
in_sign="ss",
|
||||
out_sign="s",
|
||||
method=self._streamOut,
|
||||
method=self._stream_out,
|
||||
async_=True,
|
||||
)
|
||||
|
||||
# jingle callbacks
|
||||
|
||||
def _streamOut(self, to_jid_s, profile_key):
|
||||
client = self.host.getClient(profile_key)
|
||||
return defer.ensureDeferred(self.streamOut(client, jid.JID(to_jid_s)))
|
||||
def _stream_out(self, to_jid_s, profile_key):
|
||||
client = self.host.get_client(profile_key)
|
||||
return defer.ensureDeferred(self.stream_out(client, jid.JID(to_jid_s)))
|
||||
|
||||
async def streamOut(self, client, to_jid):
|
||||
async def stream_out(self, client, to_jid):
|
||||
"""send a stream
|
||||
|
||||
@param peer_jid(jid.JID): recipient
|
||||
|
|
@ -230,7 +230,7 @@ class JingleStream(object):
|
|||
))
|
||||
return str(port)
|
||||
|
||||
def jingleSessionInit(self, client, session, content_name, stream_object):
|
||||
def jingle_session_init(self, client, session, content_name, stream_object):
|
||||
content_data = session["contents"][content_name]
|
||||
application_data = content_data["application_data"]
|
||||
assert "stream_object" not in application_data
|
||||
|
|
@ -239,7 +239,7 @@ class JingleStream(object):
|
|||
return desc_elt
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def jingleRequestConfirmation(self, client, action, session, content_name, desc_elt):
|
||||
def jingle_request_confirmation(self, client, action, session, content_name, desc_elt):
|
||||
"""This method request confirmation for a jingle session"""
|
||||
content_data = session["contents"][content_name]
|
||||
if content_data["senders"] not in (
|
||||
|
|
@ -249,7 +249,7 @@ class JingleStream(object):
|
|||
log.warning("Bad sender, assuming initiator")
|
||||
content_data["senders"] = self._j.ROLE_INITIATOR
|
||||
|
||||
confirm_data = yield xml_tools.deferDialog(
|
||||
confirm_data = yield xml_tools.defer_dialog(
|
||||
self.host,
|
||||
_(CONFIRM).format(peer=session["peer_jid"].full()),
|
||||
_(CONFIRM_TITLE),
|
||||
|
|
@ -274,10 +274,10 @@ class JingleStream(object):
|
|||
content_data["stream_object"] = factory
|
||||
finished_d = content_data["finished_d"] = defer.Deferred()
|
||||
args = [client, session, content_name, content_data]
|
||||
finished_d.addCallbacks(self._finishedCb, self._finishedEb, args, None, args)
|
||||
finished_d.addCallbacks(self._finished_cb, self._finished_eb, args, None, args)
|
||||
defer.returnValue(True)
|
||||
|
||||
def jingleHandler(self, client, action, session, content_name, desc_elt):
|
||||
def jingle_handler(self, client, action, session, content_name, desc_elt):
|
||||
content_data = session["contents"][content_name]
|
||||
application_data = content_data["application_data"]
|
||||
if action in (self._j.A_ACCEPTED_ACK, self._j.A_SESSION_INITIATE):
|
||||
|
|
@ -287,19 +287,19 @@ class JingleStream(object):
|
|||
content_data["stream_object"] = application_data["stream_object"]
|
||||
finished_d = content_data["finished_d"] = defer.Deferred()
|
||||
args = [client, session, content_name, content_data]
|
||||
finished_d.addCallbacks(self._finishedCb, self._finishedEb, args, None, args)
|
||||
finished_d.addCallbacks(self._finished_cb, self._finished_eb, args, None, args)
|
||||
else:
|
||||
log.warning("FIXME: unmanaged action {}".format(action))
|
||||
return desc_elt
|
||||
|
||||
def _finishedCb(self, __, client, session, content_name, content_data):
|
||||
def _finished_cb(self, __, client, session, content_name, content_data):
|
||||
log.info("Pipe transfer completed")
|
||||
self._j.contentTerminate(client, session, content_name)
|
||||
content_data["stream_object"].stopStream()
|
||||
self._j.content_terminate(client, session, content_name)
|
||||
content_data["stream_object"].stop_stream()
|
||||
|
||||
def _finishedEb(self, failure, client, session, content_name, content_data):
|
||||
def _finished_eb(self, failure, client, session, content_name, content_data):
|
||||
log.warning("Error while streaming pipe: {}".format(failure))
|
||||
self._j.contentTerminate(
|
||||
self._j.content_terminate(
|
||||
client, session, content_name, reason=self._j.REASON_FAILED_TRANSPORT
|
||||
)
|
||||
content_data["stream_object"].stopStream()
|
||||
content_data["stream_object"].stop_stream()
|
||||
|
|
|
|||
Loading…
Reference in a new issue