self._callbackNumbers = {}
self._lastAuthed = 0.0
+ self.__contacts = None
+
def is_authed(self, force = False):
"""
Attempts to detect a current session and pull the auth token ( a_t ) from the page.
self._browser.cookies.clear()
self._browser.cookies.save()
+ self.clear_caches()
+
def dial(self, number):
"""
This is the main function responsible for initating the callback
return False
def clear_caches(self):
- pass
+ self.__contacts = None
def is_valid_syntax(self, number):
"""
@returns Iterable of (Address Book Factory, Book Id, Book Name)
"""
yield self, "", ""
-
+
def open_addressbook(self, bookId):
return self
"""
@returns Iterable of (contact id, contact name)
"""
- contactsPagesUrls = [GCDialer._contactsURL]
- for contactsPageUrl in contactsPagesUrls:
- contactsPage = self._browser.download(contactsPageUrl)
- for contact_match in self._contactsRe.finditer(contactsPage):
- contactId = contact_match.group(1)
- contactName = contact_match.group(2)
- yield contactId, contactName
-
- next_match = self._contactsNextRe.match(contactsPage)
- if next_match is not None:
- newContactsPageUrl = self._contactsURL + next_match.group(1)
- contactsPagesUrls.append(newContactsPageUrl)
-
+ if self.__contacts is None:
+ self.__contacts = []
+
+ contactsPagesUrls = [GCDialer._contactsURL]
+ for contactsPageUrl in contactsPagesUrls:
+ contactsPage = self._browser.download(contactsPageUrl)
+ for contact_match in self._contactsRe.finditer(contactsPage):
+ contactId = contact_match.group(1)
+ contactName = contact_match.group(2)
+ contact = contactId, contactName
+ self.__contacts.append(contact)
+ yield contact
+
+ next_match = self._contactsNextRe.match(contactsPage)
+ if next_match is not None:
+ newContactsPageUrl = self._contactsURL + next_match.group(1)
+ contactsPagesUrls.append(newContactsPageUrl)
+ else:
+ for contact in self.__contacts:
+ yield contact
+
def get_contact_details(self, contactId):
"""
@returns Iterable of (Phone Type, Phone Number)
Minimal example of both an addressbook factory and an addressbook
"""
+ def clear_caches(self):
+ pass
+
def get_addressbooks(self):
"""
@returns Iterable of (Address Book Factory, Book Id, Book Name)
def __init__(self, addressbooks, sorter = None):
self.__addressbooks = addressbooks
self.__sort_contacts = sorter if sorter is not None else self.null_sorter
+ self.__contacts = None
+
+ def clear_caches(self):
+ for addressBook in self.__addressbooks:
+ addressBook.clear_caches()
+ self.__contacts = None
def get_addressbooks(self):
"""
"""
@returns Iterable of (contact id, contact name)
"""
- contacts = (
- ("-".join([str(bookIndex), contactId]), contactName)
- for (bookIndex, addressbook) in enumerate(self.__addressbooks)
- for (contactId, contactName) in addressbook.get_contacts()
- )
- sortedContacts = self.__sort_contacts(contacts)
- return sortedContacts
+ if self.__contacts is None:
+ contacts = (
+ ("-".join([str(bookIndex), contactId]), contactName)
+ for (bookIndex, addressbook) in enumerate(self.__addressbooks)
+ for (contactId, contactName) in addressbook.get_contacts()
+ )
+ sortedContacts = self.__sort_contacts(contacts)
+
+ self.__contacts = []
+ for contact in sortedContacts:
+ self.__contacts.append(contact)
+ yield contact
+ else:
+ for contact in self.__contacts:
+ yield contact
def get_contact_details(self, contactId):
"""
"""
if memory_low:
self._gcBackend.clear_caches()
+ for factory in self._addressBookFactories:
+ factory.clear_caches()
+ self._addressBook.clear_caches()
gc.collect()
def _on_connection_change(self, connection, event, magicIdentifier):