summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJonny Lamb <jonny.lamb@collabora.co.uk>2010-03-11 13:33:16 +0000
committerJonny Lamb <jonny.lamb@collabora.co.uk>2010-03-11 17:35:57 +0000
commit028c2e68b2532ad15dd9b91f0cf76cb8665f38ce (patch)
tree417f3e2b160443cd14f59d8b26e55e1e0acf8746 /src
parentbec4146bf881332763cd6a5c10226edd717c212d (diff)
channel{,manager}: use NoneHandle around to remove hacks where handle might be None
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
Diffstat (limited to 'src')
-rw-r--r--src/server/channel.py47
-rw-r--r--src/server/channelmanager.py21
-rw-r--r--src/server/conn.py2
3 files changed, 26 insertions, 44 deletions
diff --git a/src/server/channel.py b/src/server/channel.py
index 5e93ca9..ea09bc8 100644
--- a/src/server/channel.py
+++ b/src/server/channel.py
@@ -43,6 +43,8 @@ from telepathy._generated.Channel import Channel as _Channel
from telepathy.server.properties import DBusProperties
+from telepathy.server.handle import NoneHandle
+
class Channel(_Channel, DBusProperties):
def __init__(self, connection, manager, props, object_path=None):
@@ -64,16 +66,14 @@ class Channel(_Channel, DBusProperties):
self._immutable_properties = dict()
- if CHANNEL_INTERFACE + '.TargetHandleType' in props \
- and CHANNEL_INTERFACE + '.TargetHandle' in props:
- if props[CHANNEL_INTERFACE + '.TargetHandleType'] == HANDLE_TYPE_NONE:
- self._handle = None
- else:
- self._handle = self._conn.handle(
- props[CHANNEL_INTERFACE + '.TargetHandleType'],
- props[CHANNEL_INTERFACE + '.TargetHandle'])
+ tht = props.get(CHANNEL_INTERFACE + '.TargetHandleType', HANDLE_TYPE_NONE)
+
+ if tht == HANDLE_TYPE_NONE:
+ self._handle = NoneHandle()
else:
- self._handle = None
+ self._handle = self._conn.handle(
+ props[CHANNEL_INTERFACE + '.TargetHandleType'],
+ props[CHANNEL_INTERFACE + '.TargetHandle'])
self._interfaces = set()
@@ -81,9 +81,9 @@ class Channel(_Channel, DBusProperties):
self._implement_property_get(CHANNEL_INTERFACE,
{'ChannelType': lambda: dbus.String(self.GetChannelType()),
'Interfaces': lambda: dbus.Array(self.GetInterfaces(), signature='s'),
- 'TargetHandle': lambda: dbus.UInt32(self._get_target_handle()),
- 'TargetHandleType': lambda: dbus.UInt32(self._get_handle_type()),
- 'TargetID': lambda: dbus.String(self._get_target_id()),
+ 'TargetHandle': lambda: dbus.UInt32(self._handle.get_id()),
+ 'TargetHandleType': lambda: dbus.UInt32(self._handle.get_type()),
+ 'TargetID': lambda: dbus.String(self._handle.get_name()),
'Requested': lambda: self._requested})
self._add_immutables({
@@ -98,24 +98,6 @@ class Channel(_Channel, DBusProperties):
def _add_immutables(self, props):
self._immutable_properties.update(props)
- def _get_target_handle(self):
- if self._handle:
- return self._handle.get_id()
- else:
- return 0
-
- def _get_handle_type(self):
- if self._handle:
- return self._handle.get_type()
- else:
- return CONNECTION_HANDLE_TYPE_NONE
-
- def _get_target_id(self):
- if self._handle:
- return self._handle.get_name()
- else:
- return ''
-
def get_props(self):
# Despite its name, this function actually only returns immutable properties.
props = dict()
@@ -140,10 +122,7 @@ class Channel(_Channel, DBusProperties):
""" Returns the handle type and number if this channel represents a
communication with a particular contact, room or server-stored list, or
zero if it is transient and defined only by its contents. """
- if self._handle:
- return self._handle.get_type(), self._handle
- else:
- return (CONNECTION_HANDLE_TYPE_NONE, 0)
+ return (self._handle.get_type(), self._handle.get_id())
@dbus.service.method(CHANNEL_INTERFACE, in_signature='', out_signature='as')
def GetInterfaces(self):
diff --git a/src/server/channelmanager.py b/src/server/channelmanager.py
index 0ee0268..0022b56 100644
--- a/src/server/channelmanager.py
+++ b/src/server/channelmanager.py
@@ -19,7 +19,11 @@
from telepathy.errors import NotImplemented
from telepathy.interfaces import (CHANNEL_INTERFACE,
- CHANNEL_TYPE_CONTACT_LIST)
+ CHANNEL_TYPE_CONTACT_LIST)
+
+from telepathy.constants import HANDLE_TYPE_NONE
+
+from telepathy.server.handle import NoneHandle
class ChannelManager(object):
def __init__(self, connection):
@@ -53,18 +57,17 @@ class ChannelManager(object):
def _get_type_requested_handle(self, props):
"""Return the type, request and target handle from the requested
properties"""
- handle = None
-
type = props[CHANNEL_INTERFACE + '.ChannelType']
requested = props[CHANNEL_INTERFACE + '.Requested']
- try:
- target_handle_type = props[CHANNEL_INTERFACE + '.TargetHandleType']
+ target_handle_type = \
+ props.get(CHANNEL_INTERFACE + '.TargetHandleType', HANDLE_TYPE_NONE)
+
+ if target_handle_type == HANDLE_TYPE_NONE:
+ handle = NoneHandle()
+ else:
target_handle = props[CHANNEL_INTERFACE + '.TargetHandle']
handle = self._conn._handles[target_handle_type, target_handle]
- except KeyError:
- # if TargetHandleType=NONE
- pass
return (type, requested, handle)
@@ -100,7 +103,7 @@ class ChannelManager(object):
props, **args)
self._conn.add_channels([channel], signal=signal)
- if handle and type in self._channels:
+ if handle.get_type() != HANDLE_TYPE_NONE and type in self._channels:
self._channels[type].setdefault(handle, []).append(channel)
return channel
diff --git a/src/server/conn.py b/src/server/conn.py
index 166ec48..47c6fae 100644
--- a/src/server/conn.py
+++ b/src/server/conn.py
@@ -312,7 +312,7 @@ class Connection(_Connection, DBusProperties):
self.check_connected()
ret = []
for channel in self._channels:
- chan = (channel._object_path, channel._type, channel._get_handle_type(), channel._handle)
+ chan = (channel._object_path, channel._type, channel._handle.get_type(), channel._handle.get_id())
ret.append(chan)
return ret