7 _moduleLogger = logging.getLogger("handle")
10 class TheOneRingHandle(telepathy.server.Handle):
12 Instances are memoized
15 def __init__(self, connection, id, handleType, name):
16 telepathy.server.Handle.__init__(self, id, handleType, name)
17 self._conn = weakref.proxy(connection)
20 return "<%s id=%u name='%s'>" % (
21 type(self).__name__, self.id, self.name
24 id = property(telepathy.server.Handle.get_id)
25 type = property(telepathy.server.Handle.get_type)
26 name = property(telepathy.server.Handle.get_name)
29 class ConnectionHandle(TheOneRingHandle):
31 def __init__(self, connection, id):
32 handleType = telepathy.HANDLE_TYPE_CONTACT
33 handleName = connection.username
34 TheOneRingHandle.__init__(self, connection, id, handleType, handleName)
36 self.profile = connection.username
39 class ContactHandle(TheOneRingHandle):
41 def __init__(self, connection, id, contactId):
42 handleType = telepathy.HANDLE_TYPE_CONTACT
43 handleName = contactId
44 TheOneRingHandle.__init__(self, connection, id, handleType, handleName)
53 def contactDetails(self):
54 return self._conn.addressbook.get_contact_details(self._id)
57 class ListHandle(TheOneRingHandle):
59 def __init__(self, connection, id, listName):
60 handleType = telepathy.HANDLE_TYPE_LIST
62 TheOneRingHandle.__init__(self, connection, id, handleType, handleName)
65 _HANDLE_TYPE_MAPPING = {
66 'connection': ConnectionHandle,
67 'contact': ContactHandle,
72 def create_handle_factory():
74 cache = weakref.WeakValueDictionary()
76 def create_handle(connection, type, *args):
77 Handle = _HANDLE_TYPE_MAPPING[type]
78 key = Handle, connection.username, args
83 handle = Handle(connection, connection.get_handle_id(), *args)
86 connection._handles[handle.get_type(), handle.get_id()] = handle
87 handleStatus = "Is New!" if isNewHandle else "From Cache"
88 _moduleLogger.info("Created Handle: %r (%s)" % (handle, handleStatus))
94 create_handle = create_handle_factory()