for cls, attribute_name in ((cls, name) for cls in ResourceListsDocument.element_map.values() for name, elem in cls._xml_element_children.items() if elem.type is ElementAttributes):
normalized_attributes = dict((name, unicode(value) if value is not None else None) for name, value in attributes.iteritems() if name in self.__attributes__)
contacts = [XCAPContact.normalize(contact) for contact in contacts]
attributes = dict((name, getattr(self, name)) for name in names.intersection(modified_keys))
attributes.update((name, self.attributes[name]) for name in self.__attributes__.intersection(modified_keys))
return attributes
class XCAPContactURI(xcap.ContactURI):
"""An XCAP ContactURI with attributes normalized to unicode"""
__attributes__ = set()
def __init__(self, id, uri, type, **attributes):
normalized_attributes = dict((name, unicode(value) if value is not None else None) for name, value in attributes.iteritems() if name in self.__attributes__)
normalized_attributes = dict((name, unicode(value) if value is not None else None) for name, value in attributes.iteritems() if name in self.__attributes__)
uris = [XCAPContactURI.normalize(uri) for uri in uris]
normalized_attributes = dict((name, unicode(value) if value is not None else None) for name, value in attributes.iteritems() if name in self.__attributes__)
for account in (account for account in account_manager.iter_accounts() if hasattr(account, 'xcap') and account.xcap.discovered and account is not originator_account):
return ItemContainer((id, uri.__getstate__()) for id, uri in self.uris.iteritems())
def __setstate__(self, value):
with self.lock:
self.uris = dict((id, ContactURI(id, **dict((str(key), val) for key, val in state.iteritems()))) for id, state in value.iteritems()) # python < 2.6.5 needs string keyword args -Dan
def ids(self):
return sorted(self.uris.keys())
def add(self, uri):
with self.lock:
self.uris[uri.id] = uri
def remove(self, uri):
with self.lock:
self.uris.pop(uri.id, None)
class ContactURI(SettingsState):
__id__ = SettingsObjectImmutableID(type=ID)
id = __id__
uri = Setting(type=unicode, default='')
type = Setting(type=unicode, default=None, nillable=True)
def __new__(cls, id=None, **state):
if id is None:
id = unique_id()
elif not isinstance(id, basestring):
raise TypeError("id needs to be a string or unicode object")
for account in (account for account in account_manager.iter_accounts() if hasattr(account, 'xcap') and account.xcap.discovered and account is not originator_account):
if any(account.enabled and account.xcap.enabled and account.xcap.discovered for account in account_manager.get_accounts() if hasattr(account, 'xcap')):
self.__old_data = old_data
else:
self.__migrate_contacts(old_data)
return
[Contact(id=id) for id in configuration.get_names(Contact.__key__)]
[Group(id=id) for id in configuration.get_names(Group.__key__)]
[Policy(id=id) for id in configuration.get_names(Policy.__key__)]
def start(self):
pass
def stop(self):
pass
def has_contact(self, id):
return id in self.contacts
def get_contact(self, id):
return self.contacts[id]
def get_contacts(self):
return self.contacts.values()
def has_group(self, id):
return id in self.groups
def get_group(self, id):
return self.groups[id]
def get_groups(self):
return self.groups.values()
def has_policy(self, id):
return id in self.policies
def get_policy(self, id):
return self.policies[id]
def get_policies(self):
return self.policies.values()
def transaction(self):
account_manager = AccountManager()
xcap_accounts = [account for account in account_manager.get_accounts() if hasattr(account, 'xcap') and account.xcap.discovered]