X-Git-Url: http://git.maemo.org/git/?p=theonering;a=blobdiff_plain;f=src%2Fhandle.py;h=5fc4e98ef6e98131d3232f5d6d6286f270f84b13;hp=c2e4bf84703a6442ddfd3a38019e695d1344da65;hb=c031c65923a021324ae3e9077332a9b3d43c716c;hpb=54fb3d0f7f39e6446e1771cc29483a4d6138f8dd diff --git a/src/handle.py b/src/handle.py index c2e4bf8..5fc4e98 100644 --- a/src/handle.py +++ b/src/handle.py @@ -41,66 +41,17 @@ class ConnectionHandle(TheOneRingHandle): class ContactHandle(TheOneRingHandle): - _DELIMETER = "|" + def __init__(self, connection, id, phoneNumber): + self._phoneNumber = util_misc.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):