From ae58a0e7efd07fd97be2289c97cc2d3a53651ca9 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Sat, 3 Oct 2009 15:26:12 -0500 Subject: [PATCH] Fixing typo bugs, weak dictionary bugs, adding logging, handle type enforcement, etc --- src/channel_manager.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/channel_manager.py b/src/channel_manager.py index 979481f..dfff259 100644 --- a/src/channel_manager.py +++ b/src/channel_manager.py @@ -26,38 +26,41 @@ class ChannelManager(object): chan.Close() def channel_for_list(self, handle, suppress_handler=False): - if handle in self._listChannels: + try: chan = self._listChannels[handle] - else: - if handle.get_type() == telepathy.HANDLE_TYPE_GROUP: - chan = channel.contact_list.GroupChannel(self._connRef(), handle) - elif handle.get_type() == telepathy.HANDLE_TYPE_CONTACT: - chan = channel.contact_list.creat_contact_list_channel(self._connRef(), handle) - else: - _moduleLogger.warn("Unknown channel type %r" % handle.get_type()) + except KeyError, e: + if handle.get_type() != telepathy.HANDLE_TYPE_LIST: + raise RuntimeError("Unsupported channel type %r" % handle.get_type()) + _moduleLogger.debug("Requesting new contact list channel") + + chan = channel.contact_list.create_contact_list_channel(self._connRef(), handle) self._listChannels[handle] = chan self._connRef().add_channel(chan, handle, suppress_handler) return chan def channel_for_text(self, handle, suppress_handler=False): - if handle in self._textChannels: + try: chan = self._textChannels[handle] - else: + except KeyError, e: + if handle.get_type() != telepathy.HANDLE_TYPE_CONTACT: + raise telepathy.NotImplemented("Only Contacts are allowed") _moduleLogger.debug("Requesting new text channel") - contact = handle.contact + contact = handle.contact chan = channel.text.TextChannel(self._connRef()) self._textChannels[handle] = chan self._connRef().add_channel(chan, handle, suppress_handler) return chan def channel_for_call(self, handle, suppress_handler=False): - if handle in self._callChannels: + try: chan = self._callChannels[handle] - else: + except KeyError, e: + if handle.get_type() != telepathy.HANDLE_TYPE_CONTACT: + raise telepathy.NotImplemented("Only Contacts are allowed") _moduleLogger.debug("Requesting new call channel") - contact = handle.contact + contact = handle.contact chan = channel.call.CallChannel(self._connRef()) self._callChannels[handle] = chan self._connRef().add_channel(chan, handle, suppress_handler) -- 1.7.9.5