Example #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))
Example #2
0
    def connect(self, **connect_args):
        # Find the protocol's __init__ method from the import path in ProtocolMeta.py
        log.info('Loading protocol for account %r...', self)
        connection_class = proto_init(self.protocol)

        # were_connected is a list of Accounts that were connected before the
        # status was set to "Offline"
        profile_obj = profile()
        profile_obj.maybe_return_from_offline()

        self.disconnect() # This will close an old connection and remove it from the reconnect_timers map

        import hub
        self.connection = connection_class(self.name, profile_obj.plain_pw(self.password),
                                           hub.get_instance(),
                                           **self.get_options(True))
        self.connection.account = self

        self.connection.add_observer(self.connection_state_changed, 'state', 'offline_reason')

        self.setnotifyif('offline_reason', self.connection.offline_reason)

        # if invisible was not specified, get from the profile's current status
        if 'invisible' not in connect_args:
            connect_args['invisible'] = profile_obj.status.for_account(self).invisible

        self._connect_args = connect_args
        self._reconnect(also_disconnect=False)
Example #3
0
    def add_email_account(self, **info):
        protocol = info.get('protocol')
        name = info.get('name')

        self.account_manager.add(proto_init(protocol)(**info), 'em')

        # $$plugin
        import plugin_manager.plugin_hub as plugin_hub
        plugin_hub.act('digsby.email.addaccount.async', protocol, name)
Example #4
0
    def add_social_account(self, **info):
        protocol = info.pop('protocol')
        name = info.get('name')

        acct = proto_init(protocol)(**info)
        self.account_manager.add(acct, 'so')

        # $$plugin
        import plugin_manager.plugin_hub as plugin_hub
        plugin_hub.act('digsby.social.addaccount.async', protocol, name)
        return acct
Example #5
0
    def from_net(cls, info, **extra):
#        log.info('from_net')
#        log.info(pformat(info))

        from common.protocolmeta import proto_init
        Class = proto_init(info.protocol)
        cls._ids.insert(info.id, info.id)
        if not all(isinstance(c, str) for c in extra):
            from pprint import pprint
            pprint(extra)
        extra.update(**cPickle.loads(info.data))
        return Class(name = info.username, password = info.password,
                          id=info.id, **extra)
Example #6
0
    def from_net(cls, info, **extra):
        #        log.info('from_net')
        #        log.info(pformat(info))

        from common.protocolmeta import proto_init
        Class = proto_init(info.protocol)
        cls._ids.insert(info.id, info.id)
        if not all(isinstance(c, str) for c in extra):
            from pprint import pprint
            pprint(extra)
        extra.update(**cPickle.loads(info.data))
        return Class(name=info.username,
                     password=info.password,
                     id=info.id,
                     **extra)
Example #7
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))
Example #8
0
    def protocol_class(self):
        "Returns the class of this Account's protocol."

        from common.protocolmeta import proto_init
        return proto_init(self.protocol)
Example #9
0
    def protocol_class(self):
        "Returns the class of this Account's protocol."

        from common.protocolmeta import proto_init
        return proto_init(self.protocol)