예제 #1
0
    def __get_value(type_, value, account, jid):
        if value is None:
            return None
        if type_ == SettingType.VALUE:
            return value

        if type_ == SettingType.CONTACT:
            return app.settings.get_contact_setting(account, jid, value)

        if type_ == SettingType.GROUP_CHAT:
            return app.settings.get_group_chat_setting(account, jid, value)

        if type_ == SettingType.CONFIG:
            return app.settings.get(value)

        if type_ == SettingType.ACCOUNT_CONFIG:
            if value == 'password':
                return passwords.get_password(account)
            if value == 'no_log_for':
                no_log = app.settings.get_account_setting(
                    account, 'no_log_for').split()
                return account not in no_log
            return app.settings.get_account_setting(account, value)

        if type_ == SettingType.ACTION:
            if value.startswith('-'):
                return account + value
            return value

        raise ValueError('Wrong SettingType?')
예제 #2
0
    def _create_client(self):
        if self._destroyed:
            # If we disable an account cleanup() is called and all
            # modules are unregistered. Because disable_account() does not wait
            # for the client to properly disconnect, handlers of the
            # nbxmpp.Client() are emitted after we called cleanup().
            # After nbxmpp.Client() disconnects and is destroyed we create a
            # new instance with this method but modules.get_handlers() fails
            # because modules are already unregistered.
            # TODO: Make this nicer
            return
        log.info('Create new nbxmpp client')
        self._client = NBXMPPClient(log_context=self._account)
        self.connection = self._client
        self._client.set_domain(self._hostname)
        self._client.set_username(self._user)
        self._client.set_resource(get_resource(self._account))

        pass_saved = app.settings.get_account_setting(self._account,
                                                      'savepass')
        if pass_saved:
            # Request password from keyring only if the user chose to save
            # his password
            self.password = passwords.get_password(self._account)

        self._client.set_password(self.password)
        self._client.set_accepted_certificates(
            app.cert_store.get_certificates())

        self._client.subscribe('resume-failed', self._on_resume_failed)
        self._client.subscribe('resume-successful', self._on_resume_successful)
        self._client.subscribe('disconnected', self._on_disconnected)
        self._client.subscribe('connection-failed', self._on_connection_failed)
        self._client.subscribe('connected', self._on_connected)

        self._client.subscribe('stanza-sent', self._on_stanza_sent)
        self._client.subscribe('stanza-received', self._on_stanza_received)

        for handler in modules.get_handlers(self):
            self._client.register_handler(handler)
예제 #3
0
 def __get_value(type_, value, account):
     if value is None:
         return
     if type_ == OptionType.VALUE:
         return value
     elif type_ == OptionType.CONFIG:
         return app.config.get(value)
     elif type_ == OptionType.ACCOUNT_CONFIG:
         if value == 'password':
             return passwords.get_password(account)
         elif value == 'no_log_for':
             no_log = app.config.get_per('accounts', account,
                                         'no_log_for').split()
             return account not in no_log
         else:
             return app.config.get_per('accounts', account, value)
     elif type_ == OptionType.ACTION:
         if value.startswith('-'):
             return account + value
         return value
     else:
         raise ValueError('Wrong OptionType?')