From f9734cde5623aaf701e222b00d5eebdf7a152772 Mon Sep 17 00:00:00 2001 From: mathieui Date: Mon, 20 Oct 2014 21:04:14 +0200 Subject: Remove the (sometimes wrong) default values in the config.get() calls --- src/bookmark.py | 10 +++---- src/config.py | 5 ++-- src/connection.py | 50 ++++++++++++++++---------------- src/core/commands.py | 12 ++++---- src/core/completions.py | 6 ++-- src/core/core.py | 72 +++++++++++++++++++++++------------------------ src/core/handlers.py | 48 +++++++++++++++---------------- src/logger.py | 2 +- src/plugin_manager.py | 4 +-- src/roster.py | 6 ++-- src/tabs/basetabs.py | 10 +++---- src/tabs/muctab.py | 18 ++++++------ src/tabs/privatetab.py | 2 +- src/tabs/rostertab.py | 4 +-- src/text_buffer.py | 4 +-- src/theming.py | 4 +-- src/windows/funcs.py | 2 +- src/windows/info_bar.py | 16 +++++------ src/windows/inputs.py | 2 +- src/windows/muc.py | 10 +++---- src/windows/roster_win.py | 16 +++++------ src/windows/text_win.py | 8 +++--- 22 files changed, 153 insertions(+), 158 deletions(-) (limited to 'src') diff --git a/src/bookmark.py b/src/bookmark.py index 1807c45e..672fb4a5 100644 --- a/src/bookmark.py +++ b/src/bookmark.py @@ -23,7 +23,7 @@ def xml_iter(xml, tag=''): else: return xml.getiterator(tag) -preferred = config.get('use_bookmarks_method', 'pep').lower() +preferred = config.get('use_bookmarks_method').lower() if preferred not in ('pep', 'privatexml'): preferred = 'privatexml' not_preferred = 'privatexml' if preferred == 'pep' else 'privatexml' @@ -155,8 +155,8 @@ def save_local(): def save(xmpp, core=None): """Save all the bookmarks.""" save_local() - if config.get('use_remote_bookmarks', True): - preferred = config.get('use_bookmarks_method', 'privatexml') + if config.get('use_remote_bookmarks'): + preferred = config.get('use_bookmarks_method') if not save_remote(xmpp, method=preferred) and core: core.information('Could not save bookmarks.', 'Error') return False @@ -192,7 +192,7 @@ def get_remote(xmpp): """Add the remotely stored bookmarks to the list.""" if xmpp.anon: return - method = config.get('use_bookmarks_method', '') + method = config.get('use_bookmarks_method') if not method: pep, privatexml = True, True for method in methods[1:]: @@ -214,7 +214,7 @@ def get_remote(xmpp): def get_local(): """Add the locally stored bookmarks to the list.""" - rooms = config.get('rooms', '') + rooms = config.get('rooms') if not rooms: return rooms = rooms.split(':') diff --git a/src/config.py b/src/config.py index 533838e1..0504dbd5 100644 --- a/src/config.py +++ b/src/config.py @@ -133,7 +133,6 @@ DEFAULT_CONFIG = { } } - class Config(RawConfigParser): """ load/save the config to a file @@ -539,7 +538,7 @@ def create_global_config(): def check_create_log_dir(): "Create the poezio logging directory if it doesn’t exist" global LOG_DIR - LOG_DIR = config.get('log_dir', '') + LOG_DIR = config.get('log_dir') if not LOG_DIR: @@ -559,7 +558,7 @@ def check_create_log_dir(): def setup_logging(): "Change the logging config according to the cmdline options and config" - if config.get('log_errors', True): + if config.get('log_errors'): LOGGING_CONFIG['root']['handlers'].append('error') LOGGING_CONFIG['handlers']['error'] = { 'level': 'ERROR', diff --git a/src/connection.py b/src/connection.py index b5b7e12e..e6188e05 100644 --- a/src/connection.py +++ b/src/connection.py @@ -29,28 +29,28 @@ class Connection(sleekxmpp.ClientXMPP): """ __init = False def __init__(self): - resource = config.get('resource', '') - if config.get('jid', ''): + resource = config.get('resource') + if config.get('jid'): # Field used to know if we are anonymous or not. # many features will be handled differently # depending on this setting self.anon = False - jid = '%s' % config.get('jid', '') + jid = '%s' % config.get('jid') if resource: jid = '%s/%s'% (jid, resource) - password = config.get('password', '') or getpass.getpass() + password = config.get('password') or getpass.getpass() else: # anonymous auth self.anon = True - jid = config.get('server', 'anon.jeproteste.info') + jid = config.get('server') if resource: jid = '%s/%s' % (jid, resource) password = None jid = safeJID(jid) # TODO: use the system language sleekxmpp.ClientXMPP.__init__(self, jid, password, - lang=config.get('lang', 'en')) + lang=config.get('lang')) - force_encryption = config.get('force_encryption', True) + force_encryption = config.get('force_encryption') if force_encryption: self['feature_mechanisms'].unencrypted_plain = False self['feature_mechanisms'].unencrypted_digest = False @@ -58,7 +58,7 @@ class Connection(sleekxmpp.ClientXMPP): self['feature_mechanisms'].unencrypted_scram = False self.core = None - self.auto_reconnect = config.get('auto_reconnect', False) + self.auto_reconnect = config.get('auto_reconnect') self.reconnect_max_attempts = 0 self.auto_authorize = None # prosody defaults, lowest is AES128-SHA, it should be a minimum @@ -66,9 +66,9 @@ class Connection(sleekxmpp.ClientXMPP): self.ciphers = config.get('ciphers', 'HIGH+kEDH:HIGH+kEECDH:HIGH:!PSK' ':!SRP:!3DES:!aNULL') - self.ca_certs = config.get('ca_cert_path', '') or None - interval = config.get('whitespace_interval', '300') - if interval.isdecimal() and int(interval) > 0: + self.ca_certs = config.get('ca_cert_path') or None + interval = config.get('whitespace_interval') + if int(interval) > 0: self.whitespace_keepalive_interval = int(interval) else: self.whitespace_keepalive_interval = 300 @@ -90,34 +90,32 @@ class Connection(sleekxmpp.ClientXMPP): # without a body XEP_0184._filter_add_receipt_request = fixes._filter_add_receipt_request self.register_plugin('xep_0184') - self.plugin['xep_0184'].auto_ack = config.get('ack_message_receipts', - True) - self.plugin['xep_0184'].auto_request = config.get( - 'request_message_receipts', True) + self.plugin['xep_0184'].auto_ack = config.get('ack_message_receipts') + self.plugin['xep_0184'].auto_request = config.get('request_message_receipts') self.register_plugin('xep_0191') self.register_plugin('xep_0199') self.set_keepalive_values() - if config.get('enable_user_tune', True): + if config.get('enable_user_tune'): self.register_plugin('xep_0118') - if config.get('enable_user_nick', True): + if config.get('enable_user_nick'): self.register_plugin('xep_0172') - if config.get('enable_user_mood', True): + if config.get('enable_user_mood'): self.register_plugin('xep_0107') - if config.get('enable_user_activity', True): + if config.get('enable_user_activity'): self.register_plugin('xep_0108') - if config.get('enable_user_gaming', True): + if config.get('enable_user_gaming'): self.register_plugin('xep_0196') - if config.get('send_poezio_info', True): + if config.get('send_poezio_info'): info = {'name':'poezio', 'version': options.version} - if config.get('send_os_info', True): + if config.get('send_os_info'): info['os'] = common.get_os_info() self.plugin['xep_0030'].set_identities( identities=set([('client', 'pc', None, 'Poezio')])) @@ -126,7 +124,7 @@ class Connection(sleekxmpp.ClientXMPP): self.plugin['xep_0030'].set_identities( identities=set([('client', 'pc', None, '')])) self.register_plugin('xep_0092', pconfig=info) - if config.get('send_time', True): + if config.get('send_time'): self.register_plugin('xep_0202') self.register_plugin('xep_0224') self.register_plugin('xep_0249') @@ -141,8 +139,8 @@ class Connection(sleekxmpp.ClientXMPP): is changed. Unload and reload the ping plugin, with the new values. """ - ping_interval = config.get('connection_check_interval', 60) - timeout_delay = config.get('connection_timeout_delay', 10) + ping_interval = config.get('connection_check_interval') + timeout_delay = config.get('connection_timeout_delay') if timeout_delay <= 0: # We help the stupid user (with a delay of 0, poezio will try to # reconnect immediately because the timeout is immediately @@ -161,7 +159,7 @@ class Connection(sleekxmpp.ClientXMPP): TODO: try multiple servers with anon auth. """ - custom_host = config.get('custom_host', '') + custom_host = config.get('custom_host') custom_port = config.get('custom_port', 5222) if custom_port == -1: custom_port = 5222 diff --git a/src/core/commands.py b/src/core/commands.py index ab441ae9..daf420fb 100644 --- a/src/core/commands.py +++ b/src/core/commands.py @@ -369,7 +369,7 @@ def command_join(self, arg, histo_length=None): room = room[1:] current_status = self.get_status() if not histo_length: - histo_length = config.get('muc_history_length', 20) + histo_length = config.get('muc_history_length') if histo_length == -1: histo_length = None if histo_length is not None: @@ -473,7 +473,7 @@ def command_bookmark(self, arg=''): /bookmark [room][/nick] [autojoin] [password] """ - if not config.get('use_remote_bookmarks', True): + if not config.get('use_remote_bookmarks'): self.command_bookmark_local(arg) return args = common.shell_split(arg) @@ -533,7 +533,7 @@ def command_bookmark(self, arg=''): if not bm: bm = bookmark.Bookmark(roomname) bookmark.bookmarks.append(bm) - bm.method = config.get('use_bookmarks_method', 'pep') + bm.method = config.get('use_bookmarks_method') if nick: bm.nick = nick if password: @@ -808,11 +808,11 @@ def command_quit(self, arg=''): msg = arg else: msg = None - if config.get('enable_user_mood', True): + if config.get('enable_user_mood'): self.xmpp.plugin['xep_0107'].stop(block=False) - if config.get('enable_user_activity', True): + if config.get('enable_user_activity'): self.xmpp.plugin['xep_0108'].stop(block=False) - if config.get('enable_user_gaming', True): + if config.get('enable_user_gaming'): self.xmpp.plugin['xep_0196'].stop(block=False) self.save_config() self.plugin_manager.disable_plugins() diff --git a/src/core/completions.py b/src/core/completions.py index f8fb7fc8..ca0bb41e 100644 --- a/src/core/completions.py +++ b/src/core/completions.py @@ -46,7 +46,7 @@ def completion_presence(self, the_input): def completion_theme(self, the_input): """ Completion for /theme""" - themes_dir = config.get('themes_dir', '') + themes_dir = config.get('themes_dir') themes_dir = themes_dir or\ os.path.join(os.environ.get('XDG_DATA_HOME') or\ os.path.join(os.environ.get('HOME'), '.local', 'share'), @@ -190,7 +190,7 @@ def completion_bookmark(self, the_input): tab = self.get_tab_by_name(jid.bare, tabs.MucTab) nicks = [tab.own_nick] if tab else [] default = os.environ.get('USER') if os.environ.get('USER') else 'poezio' - nick = config.get('default_nick', '') + nick = config.get('default_nick') if not nick: if not default in nicks: nicks.append(default) @@ -371,7 +371,7 @@ def completion_bookmark_local(self, the_input): tab = self.get_tab_by_name(jid.bare, tabs.MucTab) nicks = [tab.own_nick] if tab else [] default = os.environ.get('USER') if os.environ.get('USER') else 'poezio' - nick = config.get('default_nick', '') + nick = config.get('default_nick') if not nick: if not default in nicks: nicks.append(default) diff --git a/src/core/core.py b/src/core/core.py index 985fb752..52199206 100644 --- a/src/core/core.py +++ b/src/core/core.py @@ -64,10 +64,10 @@ class Core(object): sys.excepthook = self.on_exception self.connection_time = time.time() self.stdscr = None - status = config.get('status', None) + status = config.get('status') status = possible_show.get(status, None) self.status = Status(show=status, - message=config.get('status_message', '')) + message=config.get('status_message')) self.running = True self.xmpp = singleton.Singleton(connection.Connection) self.xmpp.core = self @@ -82,7 +82,7 @@ class Core(object): # that are displayed in almost all tabs, in an # information window. self.information_buffer = TextBuffer() - self.information_win_size = config.get('info_win_height', 2, 'var') + self.information_win_size = config.get('info_win_height', section='var') self.information_win = windows.TextWin(300) self.information_buffer.add_window(self.information_win) self.left_tab_win = None @@ -96,7 +96,7 @@ class Core(object): self._current_tab_nb = 0 self.previous_tab_nb = 0 - own_nick = config.get('default_nick', '') + own_nick = config.get('default_nick') own_nick = own_nick or self.xmpp.boundjid.user own_nick = own_nick or os.environ.get('USER') own_nick = own_nick or 'poezio' @@ -119,7 +119,7 @@ class Core(object): self.register_initial_commands() # We are invisible - if not config.get('send_initial_presence', True): + if not config.get('send_initial_presence'): del self.commands['status'] del self.commands['show'] @@ -241,19 +241,19 @@ class Core(object): connection.MatchAll(None), self.incoming_stanza) self.xmpp.register_handler(self.all_stanzas) - if config.get('enable_user_tune', True): + if config.get('enable_user_tune'): self.xmpp.add_event_handler("user_tune_publish", self.on_tune_event) - if config.get('enable_user_nick', True): + if config.get('enable_user_nick'): self.xmpp.add_event_handler("user_nick_publish", self.on_nick_received) - if config.get('enable_user_mood', True): + if config.get('enable_user_mood'): self.xmpp.add_event_handler("user_mood_publish", self.on_mood_event) - if config.get('enable_user_activity', True): + if config.get('enable_user_activity'): self.xmpp.add_event_handler("user_activity_publish", self.on_activity_event) - if config.get('enable_user_gaming', True): + if config.get('enable_user_gaming'): self.xmpp.add_event_handler("user_gaming_publish", self.on_gaming_event) @@ -342,13 +342,14 @@ class Core(object): """ Called when the request_message_receipts option changes """ - self.xmpp.plugin['xep_0184'].auto_request = config.get(option, True) + self.xmpp.plugin['xep_0184'].auto_request = config.get(option, + default=True) def on_ack_receipts_config_change(self, option, value): """ Called when the ack_message_receipts option changes """ - self.xmpp.plugin['xep_0184'].auto_ack = config.get(option, True) + self.xmpp.plugin['xep_0184'].auto_ack = config.get(option, default=True) def on_plugins_dir_config_change(self, option, value): """ @@ -398,7 +399,7 @@ class Core(object): old_section = old_config.get(section, {}) for option in config.options(section): old_value = old_section.get(option) - new_value = config.get(option, "", section) + new_value = config.get(option, default="", section=section) if new_value != old_value: self.trigger_configuration_change(option, new_value) log.debug("Config reloaded.") @@ -420,11 +421,11 @@ class Core(object): } log.error("%s received. Exiting…", signals[sig]) - if config.get('enable_user_mood', True): + if config.get('enable_user_mood'): self.xmpp.plugin['xep_0107'].stop(block=False) - if config.get('enable_user_activity', True): + if config.get('enable_user_activity'): self.xmpp.plugin['xep_0108'].stop(block=False) - if config.get('enable_user_gaming', True): + if config.get('enable_user_gaming'): self.xmpp.plugin['xep_0196'].stop(block=False) self.plugin_manager.disable_plugins() self.disconnect('') @@ -439,7 +440,7 @@ class Core(object): """ Load the plugins on startup. """ - plugins = config.get('plugins_autoload', '') + plugins = config.get('plugins_autoload') if ':' in plugins: for plugin in plugins.split(':'): self.plugin_manager.load(plugin) @@ -659,9 +660,9 @@ class Core(object): work. If you try to do anything else, your |, [, <<, etc will be interpreted as normal command arguments, not shell special tokens. """ - if config.get('exec_remote', False): + if config.get('exec_remote'): # We just write the command in the fifo - fifo_path = config.get('remote_fifo_path', './') + fifo_path = config.get('remote_fifo_path') if not self.remote_fifo: try: self.remote_fifo = Fifo(os.path.join(fifo_path, @@ -755,7 +756,7 @@ class Core(object): or to use it when joining a new muc) """ self.status = Status(show=pres, message=msg) - if config.get('save_status', True): + if config.get('save_status'): ok = config.silent_set('status', pres if pres else '') msg = msg.replace('\n', '|') if msg else '' ok = ok and config.silent_set('status_message', msg) @@ -993,7 +994,7 @@ class Core(object): return False elif not self.tabs[old_pos]: return False - if config.get('create_gaps', False): + if config.get('create_gaps'): return self.insert_tab_gaps(old_pos, new_pos) return self.insert_tab_nogaps(old_pos, new_pos) @@ -1237,7 +1238,7 @@ class Core(object): if self.previous_tab_nb != nb: self.current_tab_nb = self.previous_tab_nb self.previous_tab_nb = 0 - if config.get('create_gaps', False): + if config.get('create_gaps'): if nb >= len(self.tabs) - 1: self.tabs.remove(tab) nb -= 1 @@ -1288,7 +1289,7 @@ class Core(object): """ Displays an informational message in the "Info" buffer """ - filter_messages = config.get('filter_info_messages', '').split(':') + filter_messages = config.get('filter_info_messages').split(':') for words in filter_messages: if words and words in msg: log.debug('Did not show the message:\n\t%s> %s', typ, msg) @@ -1298,12 +1299,11 @@ class Core(object): nb_lines = self.information_buffer.add_message(msg, nickname=typ, nick_color=color) - popup_on = config.get('information_buffer_popup_on', - 'error roster warning help info').split() + popup_on = config.get('information_buffer_popup_on').split() if isinstance(self.current_tab(), tabs.RosterInfoTab): self.refresh_window() elif typ != '' and typ.lower() in popup_on: - popup_time = config.get('popup_time', 4) + (nb_lines - 1) * 2 + popup_time = config.get('popup_time') + (nb_lines - 1) * 2 self.pop_information_win_up(nb_lines, popup_time) else: if self.information_win_size != 0: @@ -1496,7 +1496,7 @@ class Core(object): """ Enable/disable the left panel. """ - enabled = config.get('enable_vertical_tab_list', False) + enabled = config.get('enable_vertical_tab_list') if not config.silent_set('enable_vertical_tab_list', str(not enabled)): self.information(_('Unable to write in the config file'), 'Error') self.call_for_resize() @@ -1523,14 +1523,14 @@ class Core(object): """ with g_lock: height, width = self.stdscr.getmaxyx() - if config.get('enable_vertical_tab_list', False): + if config.get('enable_vertical_tab_list'): if self.size.core_degrade_x: return try: height, _ = self.stdscr.getmaxyx() truncated_win = self.stdscr.subwin(height, - config.get('vertical_tab_list_size', 20), + config.get('vertical_tab_list_size'), 0, 0) except: log.error('Curses error on infobar resize', exc_info=True) @@ -1569,12 +1569,12 @@ class Core(object): # on the left remaining space with g_lock: height, width = self.stdscr.getmaxyx() - if (config.get('enable_vertical_tab_list', False) and + if (config.get('enable_vertical_tab_list') and not self.size.core_degrade_x): with g_lock: try: scr = self.stdscr.subwin(0, - config.get('vertical_tab_list_size', 20)) + config.get('vertical_tab_list_size')) except: log.error('Curses error on resize', exc_info=True) return @@ -1585,7 +1585,7 @@ class Core(object): self.resize_global_information_win() with g_lock: for tab in self.tabs: - if config.get('lazy_resize', True): + if config.get('lazy_resize'): tab.need_resize = True else: tab.resize() @@ -1818,7 +1818,7 @@ class Core(object): usage='', shortdesc=_('List available ad-hoc commands on the given jid')) - if config.get('enable_user_activity', True): + if config.get('enable_user_activity'): self.register_command('activity', self.command_activity, usage='[ [specific] [text]]', desc=_('Send your current activity to your contacts ' @@ -1826,7 +1826,7 @@ class Core(object): '"stop broadcasting an activity".'), shortdesc=_('Send your activity.'), completion=self.completion_activity) - if config.get('enable_user_mood', True): + if config.get('enable_user_mood'): self.register_command('mood', self.command_mood, usage='[ [text]]', desc=_('Send your current mood to your contacts ' @@ -1834,7 +1834,7 @@ class Core(object): '"stop broadcasting a mood".'), shortdesc=_('Send your mood.'), completion=self.completion_mood) - if config.get('enable_user_gaming', True): + if config.get('enable_user_gaming'): self.register_command('gaming', self.command_gaming, usage='[ [server address]]', desc=_('Send your current gaming activity to ' @@ -1977,7 +1977,7 @@ def replace_key_with_bound(key): Replace an inputted key with the one defined as its replacement in the config """ - bind = config.get(key, key, 'bindings') + bind = config.get(key, default=key, section='bindings') if not bind: bind = key return bind diff --git a/src/core/handlers.py b/src/core/handlers.py index 4853c804..dfcb3223 100644 --- a/src/core/handlers.py +++ b/src/core/handlers.py @@ -44,7 +44,7 @@ def on_session_start_features(self, _): features = iq['disco_info']['features'] rostertab = self.get_tab_by_name('Roster', tabs.RosterInfoTab) rostertab.check_blocking(features) - if (config.get('enable_carbons', True) and + if (config.get('enable_carbons') and 'urn:xmpp:carbons:2' in features): self.xmpp.plugin['xep_0280'].enable() self.xmpp.add_event_handler('carbon_received', self.on_carbon_received) @@ -111,7 +111,7 @@ def on_groupchat_invitation(self, message): if password: msg += ". The password is \"%s\"." % password self.information(msg, 'Info') - if 'invite' in config.get('beep_on', 'invite').split(): + if 'invite' in config.get('beep_on').split(): curses.beep() logger.log_roster_change(inviter.full, 'invited you to %s' % jid.full) self.pending_invites[jid.bare] = inviter.full @@ -142,7 +142,7 @@ def on_groupchat_direct_invitation(self, message): msg += "\nreason: %s" % reason self.information(msg, 'Info') - if 'invite' in config.get('beep_on', 'invite').split(): + if 'invite' in config.get('beep_on').split(): curses.beep() self.pending_invites[room.bare] = inviter.full @@ -178,9 +178,9 @@ def on_normal_message(self, message): elif message['type'] == 'headline' and message['body']: return self.information('%s says: %s' % (message['from'], message['body']), 'Headline') - use_xhtml = config.get('enable_xhtml_im', True) - tmp_dir = config.get('tmp_image_dir', '') or path.join(CACHE_DIR, 'images') - extract_images = config.get('extract_inline_images', True) + use_xhtml = config.get('enable_xhtml_im') + tmp_dir = config.get('tmp_image_dir') or path.join(CACHE_DIR, 'images') + extract_images = config.get('extract_inline_images') body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml, tmp_dir=tmp_dir, extract_images=extract_images) @@ -197,7 +197,7 @@ def on_normal_message(self, message): if conv_jid.bare in roster: remote_nick = roster[conv_jid.bare].name # check for a received nick - if not remote_nick and config.get('enable_user_nick', True): + if not remote_nick and config.get('enable_user_nick'): if message.xml.find('{http://jabber.org/protocol/nick}nick') is not None: remote_nick = message['nick']['nick'] if not remote_nick: @@ -259,7 +259,7 @@ def on_normal_message(self, message): conversation.remote_wants_chatstates = True else: conversation.remote_wants_chatstates = False - if 'private' in config.get('beep_on', 'highlight private').split(): + if 'private' in config.get('beep_on').split(): if not config.get_by_tabname('disable_beep', conv_jid.bare): curses.beep() if self.current_tab() is not conversation: @@ -447,9 +447,9 @@ def on_groupchat_message(self, message): return self.events.trigger('muc_msg', message, tab) - use_xhtml = config.get('enable_xhtml_im', True) - tmp_dir = config.get('tmp_image_dir', '') or path.join(CACHE_DIR, 'images') - extract_images = config.get('extract_inline_images', True) + use_xhtml = config.get('enable_xhtml_im') + tmp_dir = config.get('tmp_image_dir') or path.join(CACHE_DIR, 'images') + extract_images = config.get('extract_inline_images') body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml, tmp_dir=tmp_dir, extract_images=extract_images) @@ -487,7 +487,7 @@ def on_groupchat_message(self, message): current.input.refresh() self.doupdate() - if 'message' in config.get('beep_on', 'highlight private').split(): + if 'message' in config.get('beep_on').split(): if (not config.get_by_tabname('disable_beep', room_from) and self.own_nick != message['from'].resource): curses.beep() @@ -508,9 +508,9 @@ def on_groupchat_private_message(self, message): return self.on_groupchat_message(message) room_from = jid.bare - use_xhtml = config.get('enable_xhtml_im', True) - tmp_dir = config.get('tmp_image_dir', '') or path.join(CACHE_DIR, 'images') - extract_images = config.get('extract_inline_images', True) + use_xhtml = config.get('enable_xhtml_im') + tmp_dir = config.get('tmp_image_dir') or path.join(CACHE_DIR, 'images') + extract_images = config.get('extract_inline_images') body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml, tmp_dir=tmp_dir, extract_images=extract_images) @@ -554,7 +554,7 @@ def on_groupchat_private_message(self, message): tab.remote_wants_chatstates = True else: tab.remote_wants_chatstates = False - if 'private' in config.get('beep_on', 'highlight private').split(): + if 'private' in config.get('beep_on').split(): if not config.get_by_tabname('disable_beep', jid.full): curses.beep() if tab is self.current_tab(): @@ -876,23 +876,23 @@ def on_session_start(self, event): # request the roster self.xmpp.get_roster() # send initial presence - if config.get('send_initial_presence', True): + if config.get('send_initial_presence'): pres = self.xmpp.make_presence() pres['show'] = self.status.show pres['status'] = self.status.message self.events.trigger('send_normal_presence', pres) pres.send() bookmark.get_local() - if not self.xmpp.anon and config.get('use_remote_bookmarks', True): + if not self.xmpp.anon and config.get('use_remote_bookmarks'): bookmark.get_remote(self.xmpp) for bm in bookmark.bookmarks: - if bm.autojoin or config.get('open_all_bookmarks', False): + if bm.autojoin or config.get('open_all_bookmarks'): tab = self.get_tab_by_name(bm.jid, tabs.MucTab) nick = bm.nick if bm.nick else self.own_nick if not tab: self.open_new_room(bm.jid, nick, False) self.initial_joins.append(bm.jid) - histo_length = config.get('muc_history_length', 20) + histo_length = config.get('muc_history_length') if histo_length == -1: histo_length = None if histo_length is not None: @@ -906,7 +906,7 @@ def on_session_start(self, event): status=self.status.message, show=self.status.show) - if config.get('enable_user_nick', True): + if config.get('enable_user_nick'): self.xmpp.plugin['xep_0172'].publish_nick(nick=self.own_nick, callback=dumb_callback, block=False) self.xmpp.plugin['xep_0115'].update_caps() @@ -1081,9 +1081,9 @@ def validate_ssl(self, pem): """ Check the server certificate using the sleekxmpp ssl_cert event """ - if config.get('ignore_certificate', False): + if config.get('ignore_certificate'): return - cert = config.get('certificate', '') + cert = config.get('certificate') # update the cert representation when it uses the old one if cert and not ':' in cert: cert = ':'.join(i + j for i, j in zip(cert[::2], cert[1::2])).upper() @@ -1147,7 +1147,7 @@ def _composing_tab_state(tab, state): else: return # should not happen - show = config.get('show_composing_tabs', 'direct') + show = config.get('show_composing_tabs') show = show in values if tab.state != 'composing' and state == 'composing': diff --git a/src/logger.py b/src/logger.py index 53ec4311..85c7a746 100644 --- a/src/logger.py +++ b/src/logger.py @@ -50,7 +50,7 @@ class Logger(object): and also log the conversations to logfiles """ def __init__(self): - self.logfile = config.get('logfile', 'logs') + self.logfile = config.get('logfile') self.roster_logfile = None # a dict of 'groupchatname': file-object (opened) self.fds = dict() diff --git a/src/plugin_manager.py b/src/plugin_manager.py index af87a23b..d5cb9bc1 100644 --- a/src/plugin_manager.py +++ b/src/plugin_manager.py @@ -325,7 +325,7 @@ class PluginManager(object): """ Create the plugins_conf_dir """ - plugins_conf_dir = config.get('plugins_conf_dir', '') + plugins_conf_dir = config.get('plugins_conf_dir') if not plugins_conf_dir: config_home = os.environ.get('XDG_CONFIG_HOME') if not config_home: @@ -352,7 +352,7 @@ class PluginManager(object): """ Set the plugins_dir on start """ - plugins_dir = config.get('plugins_dir', '') + plugins_dir = config.get('plugins_dir') plugins_dir = plugins_dir or\ os.path.join(os.environ.get('XDG_DATA_HOME') or\ os.path.join(os.environ.get('HOME'), diff --git a/src/roster.py b/src/roster.py index eb898e5e..d18a41c4 100644 --- a/src/roster.py +++ b/src/roster.py @@ -36,10 +36,8 @@ class Roster(object): self.contact_filter = None # A tuple(function, *args) # function to filter contacts, # on search, for example - self.folded_groups = set(config.get( - 'folded_roster_groups', - '', - section='var').split(':')) + self.folded_groups = set(config.get('folded_roster_groups', + section='var').split(':')) self.groups = {} self.contacts = {} diff --git a/src/tabs/basetabs.py b/src/tabs/basetabs.py index 0fde624c..2f5db40a 100644 --- a/src/tabs/basetabs.py +++ b/src/tabs/basetabs.py @@ -139,7 +139,7 @@ class Tab(object): Returns 1 or 0, depending on if we are using the vertical tab list or not. """ - if config.get('enable_vertical_tab_list', False): + if config.get('enable_vertical_tab_list'): return 0 return 1 @@ -298,7 +298,7 @@ class Tab(object): return False def refresh_tab_win(self): - if config.get('enable_vertical_tab_list', False): + if config.get('enable_vertical_tab_list'): if self.left_tab_win and not self.size.core_degrade_x: self.left_tab_win.refresh() elif not self.size.core_degrade_y: @@ -476,7 +476,7 @@ class ChatTab(Tab): self.update_keys() # Get the logs - log_nb = config.get('load_log', 10) + log_nb = config.get('load_log') logs = self.load_logs(log_nb) if logs: @@ -537,7 +537,7 @@ class ChatTab(Tab): for word in txt.split(): if len(word) >= 4 and word not in words: words.append(word) - words.extend([word for word in config.get('words', '').split(':') if word]) + words.extend([word for word in config.get('words').split(':') if word]) self.input.auto_completion(words, ' ', quotify=False) def on_enter(self): @@ -825,7 +825,7 @@ class OneToOneTab(ChatTab): if attention or empty: features.append(_('attention requests (/attention)')) if (receipts or empty) \ - and config.get('request_message_receipts', True): + and config.get('request_message_receipts'): features.append(_('message delivery receipts')) if len(features) > 1: tail = features.pop() diff --git a/src/tabs/muctab.py b/src/tabs/muctab.py index bd8ed312..fb89b0fa 100644 --- a/src/tabs/muctab.py +++ b/src/tabs/muctab.py @@ -251,7 +251,7 @@ class MucTab(ChatTab): def completion_nick(self, the_input): """Completion for /nick""" nicks = [os.environ.get('USER'), - config.get('default_nick', ''), + config.get('default_nick'), self.core.get_bookmark_nickname(self.name)] nicks = [i for i in nicks if i] return the_input.auto_completion(nicks, '', quotify=False) @@ -801,7 +801,7 @@ class MucTab(ChatTab): Resize the whole window. i.e. all its sub-windows """ self.need_resize = False - if config.get("hide_user_list", False) or self.size.tab_degrade_x: + if config.get('hide_user_list') or self.size.tab_degrade_x: display_user_list = False text_width = self.width else: @@ -842,7 +842,7 @@ class MucTab(ChatTab): if self.need_resize: self.resize() log.debug(' TAB Refresh: %s', self.__class__.__name__) - if config.get("hide_user_list", False) or self.size.tab_degrade_x: + if config.get('hide_user_list') or self.size.tab_degrade_x: display_user_list = False else: display_user_list = True @@ -885,7 +885,7 @@ class MucTab(ChatTab): for user in sorted(self.users, key=compare_users, reverse=True): if user.nick != self.own_nick: word_list.append(user.nick) - after = config.get('after_completion', ',') + ' ' + after = config.get('after_completion') + ' ' input_pos = self.input.pos if ' ' not in self.input.get_text()[:input_pos] or ( self.input.last_completion and @@ -893,7 +893,7 @@ class MucTab(ChatTab): self.input.last_completion + after): add_after = after else: - if not config.get('add_space_after_completion', True): + if not config.get('add_space_after_completion'): add_after = '' else: add_after = ' ' @@ -905,7 +905,7 @@ class MucTab(ChatTab): self.send_composing_chat_state(empty_after) def get_nick(self): - if not config.get('show_muc_jid', True): + if not config.get('show_muc_jid'): return safeJID(self.name).user return self.name @@ -930,7 +930,7 @@ class MucTab(ChatTab): def on_gain_focus(self): self.state = 'current' if (self.text_win.built_lines and self.text_win.built_lines[-1] is None - and not config.get('show_useless_separator', False)): + and not config.get('show_useless_separator')): self.text_win.remove_line_separator() curses.curs_set(1) if self.joined and config.get_by_tabname('send_chat_states', @@ -940,7 +940,7 @@ class MucTab(ChatTab): def on_info_win_size_changed(self): if self.core.information_win_size >= self.height-3: return - if config.get("hide_user_list", False): + if config.get("hide_user_list"): text_width = self.width else: text_width = (self.width//10)*9 @@ -1476,7 +1476,7 @@ class MucTab(ChatTab): highlighted = True break if highlighted: - beep_on = config.get('beep_on', 'highlight private').split() + beep_on = config.get('beep_on').split() if 'highlight' in beep_on and 'message' not in beep_on: if not config.get_by_tabname('disable_beep', self.name): curses.beep() diff --git a/src/tabs/privatetab.py b/src/tabs/privatetab.py index f4fa10cf..4c01cd70 100644 --- a/src/tabs/privatetab.py +++ b/src/tabs/privatetab.py @@ -109,7 +109,7 @@ class PrivateTab(OneToOneTab): compare_users = lambda x: x.last_talked word_list = [user.nick for user in sorted(self.parent_muc.users, key=compare_users, reverse=True)\ if user.nick != self.own_nick] - after = config.get('after_completion', ',')+" " + after = config.get('after_completion') + ' ' input_pos = self.input.pos if ' ' not in self.input.get_text()[:input_pos] or (self.input.last_completion and\ self.input.get_text()[:input_pos] == self.input.last_completion + after): diff --git a/src/tabs/rostertab.py b/src/tabs/rostertab.py index 3d01046b..26f429d0 100644 --- a/src/tabs/rostertab.py +++ b/src/tabs/rostertab.py @@ -349,7 +349,7 @@ class RosterInfoTab(Tab): def callback(iq): if iq['type'] == 'result': self.core.information('Password updated', 'Account') - if config.get('password', ''): + if config.get('password'): config.silent_set('password', arg) else: self.core.information('Unable to change the password', 'Account') @@ -763,7 +763,7 @@ class RosterInfoTab(Tab): Show or hide offline contacts """ option = 'roster_show_offline' - value = config.get(option, False) + value = config.get(option) success = config.silent_set(option, str(not value)) roster.modified() if not success: diff --git a/src/text_buffer.py b/src/text_buffer.py index 4a41fd97..59aa96e1 100644 --- a/src/text_buffer.py +++ b/src/text_buffer.py @@ -64,7 +64,7 @@ class TextBuffer(object): def __init__(self, messages_nb_limit=None): if messages_nb_limit is None: - messages_nb_limit = config.get('max_messages_in_memory', 2048) + messages_nb_limit = config.get('max_messages_in_memory') self.messages_nb_limit = messages_nb_limit # Message objects self.messages = [] @@ -138,7 +138,7 @@ class TextBuffer(object): self.messages.pop(0) ret_val = None - show_timestamps = config.get('show_timestamps', True) + show_timestamps = config.get('show_timestamps') for window in self.windows: # make the associated windows # build the lines from the new message nb = window.build_new_message(msg, history=history, diff --git a/src/theming.py b/src/theming.py index 9820addf..dc3052f0 100755 --- a/src/theming.py +++ b/src/theming.py @@ -455,7 +455,7 @@ def update_themes_dir(option=None, value=None): # import from the user-defined prefs themes_dir = path.expanduser( value or - config.get('themes_dir', '') or + config.get('themes_dir') or path.join(os.environ.get('XDG_DATA_HOME') or path.join(os.environ.get('HOME'), '.local', 'share'), 'poezio', 'themes') @@ -482,7 +482,7 @@ def update_themes_dir(option=None, value=None): log.debug('Theme load path: %s', load_path) def reload_theme(): - theme_name = config.get('theme', 'default') + theme_name = config.get('theme') global theme if theme_name == 'default' or not theme_name.strip(): theme = Theme() diff --git a/src/windows/funcs.py b/src/windows/funcs.py index 47011faf..d58d4683 100644 --- a/src/windows/funcs.py +++ b/src/windows/funcs.py @@ -20,7 +20,7 @@ def find_first_format_char(text, chars=None): return pos def truncate_nick(nick, size=None): - size = size or config.get('max_nick_length', 25) + size = size or config.get('max_nick_length') if size < 1: size = 1 if nick and len(nick) > size: diff --git a/src/windows/info_bar.py b/src/windows/info_bar.py index 9917fa6a..cea4702f 100644 --- a/src/windows/info_bar.py +++ b/src/windows/info_bar.py @@ -25,10 +25,10 @@ class GlobalInfoBar(Win): self._win.erase() self.addstr(0, 0, "[", to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) - create_gaps = config.get('create_gaps', False) - show_names = config.get('show_tab_names', False) - show_nums = config.get('show_tab_numbers', True) - use_nicks = config.get('use_tab_nicks', True) + create_gaps = config.get('create_gaps') + show_names = config.get('show_tab_names') + show_nums = config.get('show_tab_numbers') + use_nicks = config.get('use_tab_nicks') # ignore any remaining gap tabs if the feature is not enabled if create_gaps: sorted_tabs = self.core.tabs[:] @@ -38,7 +38,7 @@ class GlobalInfoBar(Win): for nb, tab in enumerate(sorted_tabs): if not tab: continue color = tab.color - if not config.get('show_inactive_tabs', True) and\ + if not config.get('show_inactive_tabs') and\ color is get_theme().COLOR_TAB_NORMAL: continue try: @@ -72,11 +72,11 @@ class VerticalGlobalInfoBar(Win): height, width = self._win.getmaxyx() self._win.erase() sorted_tabs = [tab for tab in self.core.tabs if tab] - if not config.get('show_inactive_tabs', True): + if not config.get('show_inactive_tabs'): sorted_tabs = [tab for tab in sorted_tabs if\ tab.vertical_color != get_theme().COLOR_VERTICAL_TAB_NORMAL] nb_tabs = len(sorted_tabs) - use_nicks = config.get('use_tab_nicks', True) + use_nicks = config.get('use_tab_nicks') if nb_tabs >= height: for y, tab in enumerate(sorted_tabs): if tab.vertical_color == get_theme().COLOR_VERTICAL_TAB_CURRENT: @@ -92,7 +92,7 @@ class VerticalGlobalInfoBar(Win): for y, tab in enumerate(sorted_tabs): color = tab.vertical_color - if not config.get('vertical_tab_list_sort', 'desc') != 'asc': + if not config.get('vertical_tab_list_sort') != 'asc': y = height - y - 1 self.addstr(y, 0, "%2d" % tab.nb, to_curses_attr(get_theme().COLOR_VERTICAL_TAB_NUMBER)) diff --git a/src/windows/inputs.py b/src/windows/inputs.py index db339b77..8e1673e1 100644 --- a/src/windows/inputs.py +++ b/src/windows/inputs.py @@ -564,7 +564,7 @@ class HistoryInput(Input): self.current_completed = '' self.key_func['^R'] = self.toggle_search self.search = False - if config.get('separate_history', False): + if config.get('separate_history'): self.history = list() def toggle_search(self): diff --git a/src/windows/muc.py b/src/windows/muc.py index ce296e26..cd594c4c 100644 --- a/src/windows/muc.py +++ b/src/windows/muc.py @@ -34,11 +34,11 @@ class UserList(Win): def refresh(self, users): log.debug('Refresh: %s', self.__class__.__name__) - if config.get("hide_user_list", False): + if config.get('hide_user_list'): return # do not refresh if this win is hidden. with g_lock: self._win.erase() - if config.get('user_list_sort', 'desc').lower() == 'asc': + if config.get('user_list_sort').lower() == 'asc': y, x = self._win.getmaxyx() y -= 1 users = sorted(users) @@ -56,7 +56,7 @@ class UserList(Win): self.addstr(y, 2, poopt.cut_by_columns(user.nick, self.width - 2), to_curses_attr(user.color)) - if config.get('user_list_sort', 'desc').lower() == 'asc': + if config.get('user_list_sort').lower() == 'asc': y -= 1 else: y += 1 @@ -64,12 +64,12 @@ class UserList(Win): break # draw indicators of position in the list if self.pos > 0: - if config.get('user_list_sort', 'desc').lower() == 'asc': + if config.get('user_list_sort').lower() == 'asc': self.draw_plus(self.height-1) else: self.draw_plus(0) if self.pos + self.height < len(users): - if config.get('user_list_sort', 'desc').lower() == 'asc': + if config.get('user_list_sort').lower() == 'asc': self.draw_plus(0) else: self.draw_plus(self.height-1) diff --git a/src/windows/roster_win.py b/src/windows/roster_win.py index d5f6d958..d98f27ce 100644 --- a/src/windows/roster_win.py +++ b/src/windows/roster_win.py @@ -95,13 +95,13 @@ class RosterWin(Win): # This is a search if roster.contact_filter: self.roster_cache = [] - sort = config.get('roster_sort', 'jid:show') or 'jid:show' + sort = config.get('roster_sort') or 'jid:show' for contact in roster.get_contacts_sorted_filtered(sort): self.roster_cache.append(contact) else: - show_offline = config.get('roster_show_offline', False) or roster.contact_filter - sort = config.get('roster_sort', 'jid:show') or 'jid:show' - group_sort = config.get('roster_group_sort', 'name') or 'name' + show_offline = config.get('roster_show_offline') or roster.contact_filter + sort = config.get('roster_sort') or 'jid:show' + group_sort = config.get('roster_group_sort') or 'name' self.roster_cache = [] # build the cache for group in roster.get_groups(group_sort): @@ -230,7 +230,7 @@ class RosterWin(Win): self.addstr(y, 0, ' ') self.addstr(theme.CHAR_STATUS, to_curses_attr(color)) - show_roster_sub = config.get('show_roster_subscriptions', '') + show_roster_sub = config.get('show_roster_subscriptions') self.addstr(' ') if resource: @@ -238,7 +238,7 @@ class RosterWin(Win): added += 4 if contact.ask: added += len(get_theme().CHAR_ROSTER_ASKED) - if config.get('show_s2s_errors', True) and contact.error: + if config.get('show_s2s_errors') and contact.error: added += len(get_theme().CHAR_ROSTER_ERROR) if contact.tune: added += len(get_theme().CHAR_ROSTER_TUNE) @@ -251,7 +251,7 @@ class RosterWin(Win): if show_roster_sub in ('all', 'incomplete', 'to', 'from', 'both', 'none'): added += len(theme.char_subscription(contact.subscription, keep=show_roster_sub)) - if not config.get('show_roster_jids', True) and contact.name: + if not config.get('show_roster_jids') and contact.name: display_name = '%s' % contact.name elif contact.name and contact.name != contact.bare_jid: display_name = '%s (%s)' % (contact.name, contact.bare_jid) @@ -269,7 +269,7 @@ class RosterWin(Win): self.addstr(theme.char_subscription(contact.subscription, keep=show_roster_sub), to_curses_attr(theme.COLOR_ROSTER_SUBSCRIPTION)) if contact.ask: self.addstr(get_theme().CHAR_ROSTER_ASKED, to_curses_attr(get_theme().COLOR_IMPORTANT_TEXT)) - if config.get('show_s2s_errors', True) and contact.error: + if config.get('show_s2s_errors') and contact.error: self.addstr(get_theme().CHAR_ROSTER_ERROR, to_curses_attr(get_theme().COLOR_ROSTER_ERROR)) if contact.tune: self.addstr(get_theme().CHAR_ROSTER_TUNE, to_curses_attr(get_theme().COLOR_ROSTER_TUNE)) diff --git a/src/windows/text_win.py b/src/windows/text_win.py index de9b0625..4c6b9a18 100644 --- a/src/windows/text_win.py +++ b/src/windows/text_win.py @@ -19,7 +19,7 @@ from theming import to_curses_attr, get_theme, dump_tuple class TextWin(Win): - def __init__(self, lines_nb_limit=config.get('max_lines_in_memory', 2048)): + def __init__(self, lines_nb_limit=config.get('max_lines_in_memory')): Win.__init__(self) self.lines_nb_limit = lines_nb_limit self.pos = 0 @@ -265,7 +265,7 @@ class TextWin(Win): lines = self.built_lines[-self.height:] else: lines = self.built_lines[-self.height-self.pos:-self.pos] - with_timestamps = config.get("show_timestamps", True) + with_timestamps = config.get("show_timestamps") with g_lock: self._win.move(0, 0) self._win.erase() @@ -405,7 +405,7 @@ class TextWin(Win): def rebuild_everything(self, room): self.built_lines = [] - with_timestamps = config.get("show_timestamps", True) + with_timestamps = config.get('show_timestamps') for message in room.messages: self.build_new_message(message, clean=False, timestamp=with_timestamps) if self.separator_after is message: @@ -418,7 +418,7 @@ class TextWin(Win): Find a message, and replace it with a new one (instead of rebuilding everything in order to correct a message) """ - with_timestamps = config.get("show_timestamps", True) + with_timestamps = config.get('show_timestamps') for i in range(len(self.built_lines)-1, -1, -1): if self.built_lines[i] and self.built_lines[i].msg.identifier == old_id: index = i -- cgit v1.2.3