X-Git-Url: http://git.maemo.org/git/?p=theonering;a=blobdiff_plain;f=src%2Fhandle.py;h=0db35fe033438e6580808cd8e065fe8aadb8cefb;hp=c2e4bf84703a6442ddfd3a38019e695d1344da65;hb=afa4cdb64e451070cf87cc02f257c582fa057f53;hpb=54fb3d0f7f39e6446e1771cc29483a4d6138f8dd diff --git a/src/handle.py b/src/handle.py index c2e4bf8..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): @@ -41,66 +41,17 @@ class ConnectionHandle(TheOneRingHandle): class ContactHandle(TheOneRingHandle): - _DELIMETER = "|" + def __init__(self, connection, id, phoneNumber): + self._phoneNumber = misc_utils.normalize_number(phoneNumber) - def __init__(self, connection, id, contactId, 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.normalize_number(phoneNumber) - - @classmethod - def from_handle_name(cls, handleName): - """ - >>> ContactHandle.from_handle_name("+1 555 123-1234") - ('', '+15551231234') - >>> ContactHandle.from_handle_name("+15551231234") - ('', '+15551231234') - >>> ContactHandle.from_handle_name("123456|+15551231234") - ('123456', '+15551231234') - """ - parts = handleName.split(cls._DELIMETER, 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.normalize_number(contactNumber) - return contactId, contactNumber - - @classmethod - def to_handle_name(cls, contactId, contactNumber): - """ - >>> ContactHandle.to_handle_name('', "+1 555 123-1234") - '+15551231234' - >>> ContactHandle.to_handle_name('', "+15551231234") - '+15551231234' - >>> ContactHandle.to_handle_name('123456', "+15551231234") - '123456|+15551231234' - """ - contactNumber = util_misc.normalize_number(contactNumber) - if contactId: - handleName = cls._DELIMETER.join((contactId, contactNumber)) - else: - handleName = contactNumber - return handleName - - @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): @@ -121,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: @@ -133,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()