self.check_handle(handleType, handleId)
return self._handles[handleType, handleId]
+ def handle_by_name(self, handleType, handleName):
+ requestedHandleName = handleName.encode('utf-8')
+ if handleType == telepathy.HANDLE_TYPE_CONTACT:
+ _moduleLogger.info("RequestHandles Contact: %s" % requestedHandleName)
+ requestedContactId, requestedContactNumber = handle.ContactHandle.from_handle_name(
+ requestedHandleName
+ )
+ h = handle.create_handle(self, 'contact', requestedContactId, requestedContactNumber)
+ elif handleType == telepathy.HANDLE_TYPE_LIST:
+ # Support only server side (immutable) lists
+ _moduleLogger.info("RequestHandles List: %s" % requestedHandleName)
+ h = handle.create_handle(self, 'list', requestedHandleName)
+ else:
+ raise telepathy.errors.NotAvailable('Handle type unsupported %d' % handleType)
+ return h
+
@property
def _channel_manager(self):
return self.__channelManager
def Disconnect(self):
"""
For org.freedesktop.telepathy.Connection
- @bug Not properly logging out. Cookie files need to be per connection and removed
"""
self.StatusChanged(
telepathy.CONNECTION_STATUS_DISCONNECTED,
handles = []
for name in names:
- requestedHandleName = name.encode('utf-8')
- if handleType == telepathy.HANDLE_TYPE_CONTACT:
- _moduleLogger.info("RequestHandles Contact: %s" % requestedHandleName)
- requestedContactId, requestedContactNumber = handle.ContactHandle.from_handle_name(
- requestedHandleName
- )
- h = handle.create_handle(self, 'contact', requestedContactId, requestedContactNumber)
- elif handleType == telepathy.HANDLE_TYPE_LIST:
- # Support only server side (immutable) lists
- _moduleLogger.info("RequestHandles List: %s" % requestedHandleName)
- h = handle.create_handle(self, 'list', requestedHandleName)
- else:
- raise telepathy.errors.NotAvailable('Handle type unsupported %d' % handleType)
- handles.append(h.id)
+ h = self.handle_by_name(handleType, name)
+ handles.append(h)
self.add_client_handle(h, sender)
return handles
type(self).__name__, self.id, self.name
)
+ def is_same(self, handleType, handleName):
+ return self.get_name() == handleName and self.get_type() == handleType
+
id = property(telepathy.server.Handle.get_id)
type = property(telepathy.server.Handle.get_type)
name = property(telepathy.server.Handle.get_name)
handleName = "#".join((contactId, util_misc.strip_number(contactNumber)))
return handleName
+ @classmethod
+ def normalize_handle_name(cls, name):
+ if "#" in name:
+ # Already a properly formatted name, run through the ringer just in case
+ return cls.to_handle_name(*cls.from_handle_name(name))
+ return name
+ else:
+ return cls.to_handle_name("", name)
+
+ def is_same(self, handleType, handleName):
+ handleName = self.normalize_handle_name(handleName)
+ _moduleLogger.info("%r == %r %r?" % (self, handleType, handleName))
+ return self.get_name() == handleName and self.get_type() == handleType
+
@property
def contactID(self):
return self._contactId
"""
raise NotImplementedError("Abstract property called")
+ @property
+ def handle_by_name(self, handleType, handleName):
+ """
+ @abstract
+ """
+ raise NotImplementedError("Abstract property called")
+
def _get_channels(self):
return [(c._object_path, c.get_props()) for c in self._channels]
if target_handle_type != telepathy.constants.HANDLE_TYPE_NONE:
if target_handle == None:
# Turn TargetID into TargetHandle.
- for handle in self._handles.itervalues():
- if handle.get_name() == target_id and handle.get_type() == target_handle_type:
- target_handle = handle.get_id()
- if not target_handle:
- raise telepathy.errors.InvalidHandle('TargetID %s not valid for type %d' %
- (target_id, target_handle_type))
-
+ target_handle = self.handle_by_name(target_handle_type, target_id)
altered_properties[telepathy.interfaces.CHANNEL_INTERFACE + '.TargetHandle'] = \
target_handle
else: