X-Git-Url: http://git.maemo.org/git/?p=theonering;a=blobdiff_plain;f=src%2Fhandle.py;h=0db35fe033438e6580808cd8e065fe8aadb8cefb;hp=44a941815953a3e60b7a6b9202f32d5fb553ff30;hb=afa4cdb64e451070cf87cc02f257c582fa057f53;hpb=3ae1df25c091b2bfb6b88b1d4023b868e63ce92f diff --git a/src/handle.py b/src/handle.py index 44a9418..0db35fe 100644 --- a/src/handle.py +++ b/src/handle.py @@ -4,10 +4,10 @@ import weakref import telepathy import tp -import util.misc as util_misc +import util.misc as misc_utils -_moduleLogger = logging.getLogger("handle") +_moduleLogger = logging.getLogger(__name__) class TheOneRingHandle(tp.Handle): @@ -24,9 +24,6 @@ class TheOneRingHandle(tp.Handle): 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(tp.Handle.get_id) type = property(tp.Handle.get_type) name = property(tp.Handle.get_name) @@ -44,58 +41,17 @@ class ConnectionHandle(TheOneRingHandle): class ContactHandle(TheOneRingHandle): - def __init__(self, connection, id, contactId, phoneNumber): + def __init__(self, connection, id, phoneNumber): + self._phoneNumber = misc_utils.normalize_number(phoneNumber) + handleType = telepathy.HANDLE_TYPE_CONTACT - handleName = self.to_handle_name(contactId, phoneNumber) + handleName = self._phoneNumber TheOneRingHandle.__init__(self, connection, id, handleType, handleName) - self._contactId = contactId - self._phoneNumber = util_misc.strip_number(phoneNumber) - - @staticmethod - def from_handle_name(handleName): - parts = handleName.split("#", 1) - if len(parts) == 2: - contactId, contactNumber = parts[0:2] - elif len(parts) == 1: - contactId, contactNumber = "", handleName - else: - raise RuntimeError("Invalid handle: %s" % handleName) - - contactNumber = util_misc.strip_number(contactNumber) - return contactId, contactNumber - - @staticmethod - def to_handle_name(contactId, contactNumber): - 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 - @property def phoneNumber(self): return self._phoneNumber - @property - def contactDetails(self): - return self._conn.addressbook.get_contact_details(self._id) - class ListHandle(TheOneRingHandle): @@ -116,7 +72,7 @@ def create_handle_factory(): cache = weakref.WeakValueDictionary() - def create_handle(connection, type, *args): + def _create_handle(connection, type, *args): Handle = _HANDLE_TYPE_MAPPING[type] key = Handle, connection.username, args try: @@ -128,11 +84,12 @@ def create_handle_factory(): cache[key] = handle isNewHandle = True connection._handles[handle.get_type(), handle.get_id()] = handle - handleStatus = "Is New!" if isNewHandle else "From Cache" - _moduleLogger.debug("Created Handle: %r (%s)" % (handle, handleStatus)) + if isNewHandle: + handleStatus = "Is New!" if isNewHandle else "From Cache" + _moduleLogger.debug("Created Handle: %r (%s)" % (handle, handleStatus)) return handle - return create_handle + return _create_handle create_handle = create_handle_factory()