def setMembershipListXml(self, xml):
        '''modify the structure with a new MembershipList xml
        if it is the first xml that you send, send first the dynamic items'''

        self.contactManager.lists['Allow'] = []
        self.contactManager.lists['Block'] = []
        self.contactManager.lists['Reverse'] = []
        self.contactManager.lists['Pending'] = []

        #ml = minidom.parseString(xml)
        ml = XmlParser.MembershipParser(xml)

        for i in ml.memberships:
            memberRole = i['MemberRole']

            for j in i['Members']:
                try:
                    email = j['PassportName'].lower()
                    if email not in self.contactManager.lists[memberRole]:
                        self.contactManager.lists[memberRole].append(email)
                    else:
                        pass

                    if memberRole == 'Pending' and 'DisplayName' in j:
                        self.contactManager.pendingNicks[email] = \
                            j['DisplayName']

                except Exception, e:
                    pass
Beispiel #2
0
    def handle_response(self, request, response):
        '''handle the response'''
        if response.status == 200:
            parser = XmlParser.MembershipParser(response.body)
            self.session.contacts.pending = {}
            self.session.contacts.reverse = {}
            pending = self.session.contacts.pending
            reverse = self.session.contacts.reverse
            contacts = self.session.contacts.contacts
            new_accounts = []

            for membership in parser.memberships:
                role = membership['MemberRole']

                for member in membership['Members']:
                    if 'PassportName' in member:
                        email = member['PassportName'].lower()
                    else:
                        continue

                    if email in contacts:
                        contact = contacts[email]
                    else:
                        contact = e3.Contact(email)

                    if role == 'Pending':
                        pending[email] = contact
                        contact.attrs['pending'] = True

                        if 'DisplayName' in member:
                            contact.nick = member['DisplayName']

                    if role == 'Reverse':
                        reverse[email] = contact
                        contact.attrs['Reverse'] = True

                    if role == 'Allow':
                        new_accounts.append(email)
                        contacts[email] = contact

                    if role == 'Block':
                        contact.blocked = True
                    else:
                        contact.blocked = False

                    if 'CID' in member:
                        contact.cid = member['CID']

                all_accounts = set(contacts.keys())
                removed_accounts = all_accounts.difference(new_accounts)

                for email in removed_accounts:
                    # TODO: send some kind of signal to inform to remove the
                    # contact
                    del contacts[email]

            DynamicItems(self.session, self.command_queue,
                self.on_login, self.started_from_cache).start()
        else:
            log.debug('error requesting membership ' + response.status)
            log.debug(response.body)