changeset 2915051a3706 in /home/hg/repos/gajim
details:http://hg.gajim.org/gajim?cmd=changeset;node=2915051a3706 description: coding standards, and other few things
diffstat:
src/chat_control.py | 2 +- src/common/jingle.py | 239 +++++++++++++++++++++++------------------------ src/dialogs.py | 6 +- 3 files changed, 122 insertions(+), 125 deletions(-)
diffs (truncated from 644 to 300 lines):
diff -r 1b82c37f0eef -r 2915051a3706 src/chat_control.py --- a/src/chat_control.py Sat Sep 19 16:35:47 2009 +0200 +++ b/src/chat_control.py Sat Sep 19 17:24:59 2009 +0200 @@ -1775,7 +1775,7 @@ self.set_audio_state('connecting', sid)
def on_stop_audio_button_activate(self, *things): - session = gajim.connections[self.account].getJingleSession( + session = gajim.connections[self.account].get_jingle_session( self.contact.get_full_jid(), self.audio_sid) if session: session.end_session() diff -r 1b82c37f0eef -r 2915051a3706 src/common/jingle.py --- a/src/common/jingle.py Sat Sep 19 16:35:47 2009 +0200 +++ b/src/common/jingle.py Sat Sep 19 17:24:59 2009 +0200 @@ -50,7 +50,6 @@ # * handle different kinds of sink and src elements
import gajim -import gobject import xmpp
import farsight, gst @@ -65,9 +64,9 @@ #FIXME: Move it to JingleSession.States? class JingleStates(object): ''' States in which jingle session may exist. ''' - ended=0 - pending=1 - active=2 + ended = 0 + pending = 1 + active = 2
#FIXME: Move it to JingleTransport.Type? class TransportType(object): @@ -75,9 +74,6 @@ datagram = 1 streaming = 2
-class Error(Exception): pass -class WrongState(Error): pass - class OutOfOrder(Exception): ''' Exception that should be raised when an action is received when in the wrong state. '''
@@ -110,7 +106,7 @@ # callbacks to call on proper contents # use .prepend() to add new callbacks, especially when you're going # to send error instead of ack - self.callbacks={ + self.callbacks = { 'content-accept': [self.__contentAcceptCB, self.__defaultCB], 'content-add': [self.__defaultCB], #TODO 'content-modify': [self.__defaultCB], #TODO @@ -134,39 +130,37 @@ }
''' Interaction with user ''' - def approveSession(self): + def approve_session(self): ''' Called when user accepts session in UI (when we aren't the initiator). ''' self.accepted = True - self.acceptSession() + self.accept_session()
- def declineSession(self): + def decline_session(self): ''' Called when user declines session in UI (when we aren't the initiator) ''' reason = xmpp.Node('reason') reason.addChild('decline') - self.__sessionTerminate(reason) + self.__session_terminate(reason)
def end_session(self): + ''' Called when user stops or cancel session in UI. ''' reason = xmpp.Node('reason') if self.state == JingleStates.active: reason.addChild('success') else: reason.addChild('cancel') - self.__sessionTerminate(reason) + self.__session_terminate(reason)
''' Middle-level functions to manage contents. Handle local content cache and send change notifications. ''' - def addContent(self, name, content, creator='we'): + def add_content(self, name, content, creator='we'): ''' Add new content to session. If the session is active, this will send proper stanza to update session. The protocol prohibits changing that when pending. Creator must be one of ('we', 'peer', 'initiator', 'responder')''' assert creator in ('we', 'peer', 'initiator', 'responder')
- if self.state == JingleStates.pending: - raise WrongState - if (creator == 'we' and self.weinitiate) or (creator == 'peer' and \ not self.weinitiate): creator = 'initiator' @@ -175,47 +169,50 @@ creator = 'responder' content.creator = creator content.name = name - self.contents[(creator,name)] = content + self.contents[(creator, name)] = content
if self.state == JingleStates.active: pass # TODO: send proper stanza, shouldn't be needed now
- def removeContent(self, creator, name): + def remove_content(self, creator, name): ''' We do not need this now ''' pass
- def modifyContent(self, creator, name, *someother): + def modify_content(self, creator, name, *someother): ''' We do not need this now ''' pass
- def acceptSession(self): + def accept_session(self): ''' Check if all contents and user agreed to start session. ''' if not self.weinitiate and self.accepted and \ self.state == JingleStates.pending and self.is_ready(): - self.__sessionAccept() + self.__session_accept()
def is_ready(self): + ''' Returns True when all codecs and candidates are ready + (for all contents). ''' return all((c.candidates_ready and c.p2psession.get_property('codecs-ready') for c in self.contents.itervalues()))
''' Middle-level function to do stanza exchange. ''' - def startSession(self): + def start_session(self): ''' Start session. ''' #FIXME: Start only once if self.weinitiate and self.state == JingleStates.ended and self.is_ready(): - self.__sessionInitiate() + self.__session_initiate()
- def sendSessionInfo(self): pass + def send_session_info(self): + pass
- def sendContentAccept(self, content): + def send_content_accept(self, content): assert self.state != JingleStates.ended - stanza, jingle = self.__makeJingle('content-accept') + stanza, jingle = self.__make_jingle('content-accept') jingle.addChild(node=content) self.connection.connection.send(stanza)
- def sendTransportInfo(self, content): - assert self.state!=JingleStates.ended - stanza, jingle = self.__makeJingle('transport-info') + def send_transport_info(self, content): + assert self.state != JingleStates.ended + stanza, jingle = self.__make_jingle('transport-info') jingle.addChild(node=content) self.connection.connection.send(stanza)
@@ -272,7 +269,7 @@ self.__dispatch_error(xmpp_error, jingle_error, text) #FIXME: Not sure when we would want to do that... if xmpp_error == 'item-not-found': - self.connection.deleteJingle(self) + self.connection.delete_jingle(self)
def __transportReplaceCB(self, stanza, jingle, error, action): for content in jingle.iterTags('content'): @@ -286,16 +283,16 @@ #Anyway, content's transport is not modifiable yet pass else: - stanza, jingle = self.__makeJingle('transport-reject') - c = jingle.setTag('content', attrs={'creator': creator, + stanza, jingle = self.__make_jingle('transport-reject') + content = jingle.setTag('content', attrs={'creator': creator, 'name': name}) - c.setTag('transport', namespace=transport_ns) + content.setTag('transport', namespace=transport_ns) self.connection.connection.send(stanza) raise xmpp.NodeProcessed else: #FIXME: This ressource is unknown to us, what should we do? #For now, reject the transport - stanza, jingle = self.__makeJingle('transport-reject') + stanza, jingle = self.__make_jingle('transport-reject') c = jingle.setTag('content', attrs={'creator': creator, 'name': name}) c.setTag('transport', namespace=transport_ns) @@ -317,7 +314,7 @@ if len(self.contents) == 0: reason = xmpp.Node('reason') reason.setTag('success') #FIXME: Is it the good one? - self.__sessionTerminate(reason) + self.__session_terminate(reason)
def __sessionAcceptCB(self, stanza, jingle, error, action): if self.state != JingleStates.pending: #FIXME @@ -363,9 +360,9 @@ if tran_ns == xmpp.NS_JINGLE_ICE_UDP: # we've got voip content if media == 'audio': - self.addContent(element['name'], JingleVoIP(self), 'peer') + self.add_content(element['name'], JingleVoIP(self), 'peer') else: - self.addContent(element['name'], JingleVideo(self), 'peer') + self.add_content(element['name'], JingleVideo(self), 'peer') contents.append((media,)) transports_ok = True
@@ -375,7 +372,7 @@ reason = xmpp.Node('reason') reason.setTag('unsupported-applications') self.__defaultCB(stanza, jingle, error, action) - self.__sessionTerminate(reason) + self.__session_terminate(reason) raise xmpp.NodeProcessed
if not transports_ok: @@ -383,7 +380,7 @@ reason = xmpp.Node('reason') reason.setTag('unsupported-transports') self.__defaultCB(stanza, jingle, error, action) - self.__sessionTerminate(reason) + self.__session_terminate(reason) raise xmpp.NodeProcessed
self.state = JingleStates.pending @@ -401,7 +398,7 @@ cn.stanzaCB(stanza, content, error, action)
def __sessionTerminateCB(self, stanza, jingle, error, action): - self.connection.deleteJingle(self) + self.connection.delete_jingle(self) reason, text = self.__reason_from_stanza(jingle) if reason not in ('success', 'cancel', 'decline'): self.__dispatch_error(reason, reason, text) @@ -411,6 +408,11 @@ text = reason#TODO self.connection.dispatch('JINGLE_DISCONNECTED', (self.peerjid, self.sid, text))
+ def __broadcastAllCB(self, stanza, jingle, error, action): + ''' Broadcast the stanza to all content handlers. ''' + for content in self.contents.itervalues(): + content.stanzaCB(stanza, None, error, action) + def __send_error(self, stanza, error, jingle_error=None, text=None): err = xmpp.Error(stanza, error) err.setNamespace(xmpp.NS_STANZAS) @@ -430,11 +432,6 @@ text = error self.connection.dispatch('JINGLE_ERROR', (self.peerjid, self.sid, text))
- def __broadcastAllCB(self, stanza, jingle, error, action): - ''' Broadcast the stanza to all content handlers. ''' - for content in self.contents.itervalues(): - content.stanzaCB(stanza, None, error, action) - def __reason_from_stanza(self, stanza): reason = 'success' reasons = ['success', 'busy', 'cancel', 'connectivity-error', @@ -453,7 +450,7 @@
''' Methods that make/send proper pieces of XML. They check if the session is in appropriate state. ''' - def __makeJingle(self, action): + def __make_jingle(self, action): stanza = xmpp.Iq(typ='set', to=xmpp.JID(self.peerjid)) attrs = {'action': action, 'sid': self.sid} @@ -464,46 +461,46 @@ jingle = stanza.addChild('jingle', attrs=attrs, namespace=xmpp.NS_JINGLE) return stanza, jingle
- def __appendContent(self, jingle, content): + def __append_content(self, jingle, content): ''' Append <content/> element to <jingle/> element, with (full=True) or without (full=False) <content/> children. ''' jingle.addChild('content', attrs={'name': content.name, 'creator': content.creator})
- def __appendContents(self, jingle): + def __append_contents(self, jingle): ''' Append all <content/> elements to <jingle/>.''' # TODO: integrate with __appendContent? # TODO: parameters 'name', 'content'? for content in self.contents.values(): - self.__appendContent(jingle, content) + self.__append_content(jingle, content)
- def __sessionInitiate(self): - assert self.state==JingleStates.ended