예제 #1
0
    def _xfrm_sort(self, src, cls, pred):
        '''
        Filters sequence src by predicate pred, and sorts src by its 'order' attribute. Transforms elements
        by calling cls.from_net on each.
        '''
        from common.protocolmeta import protocols, proto_init
        accounts = []
        for x in src:
            if pred(x):
                with traceguard:
                    if x.protocol not in protocols:
                        log.info('don\'t know what kind of account %r is: %r',
                                 x.protocol, x)
                        continue

                    if protocols.get(x.protocol,
                                     {}).get('smtp_pw_type', False):
                        cls2 = proto_init(x.protocol)
                        acct = cls2.from_net(x)
                    else:
                        acct = cls.from_net(x)

                    accounts.append(acct)

        return sorted(accounts,
                      key=lambda x: src.order.index(x.id)
                      if x.id in src.order else len(src))
예제 #2
0
    def _xfrm_sort(self, src, cls, pred):
        '''
        Filters sequence src by predicate pred, and sorts src by its 'order' attribute. Transforms elements
        by calling cls.from_net on each.
        '''
        from common.protocolmeta import protocols, proto_init
        accounts = []
        for x in src:
            if pred(x):
                with traceguard:
                    if x.protocol not in protocols:
                        log.info('don\'t know what kind of account %r is: %r', x.protocol, x)
                        continue

                    if protocols.get(x.protocol, {}).get('smtp_pw_type', False):
                        cls2 = proto_init(x.protocol)
                        acct = cls2.from_net(x)
                    else:
                        acct = cls.from_net(x)

                    accounts.append(acct)

        return sorted(accounts, key=lambda x: src.order.index(x.id) if x.id in src.order else len(src))
예제 #3
0
def social_accounts(x):
    meta = protocols.get(x.protocol, {})
    type = meta.get('type', None)
    return type == 'social' or (type == 'service_component' and meta.get('component_type', None) == 'social')
예제 #4
0
def is_im_account(x):
    'Returns True if x is an IM account.'
    meta = protocols.get(x.protocol, {})
    type = meta.get('type', None)
    return type == 'im' or (type == 'service_component' and meta.get('component_type', None) == 'im')