From ea2d76864da2448152428a62fe5c7daaea6ab0d3 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sat, 21 Jul 2018 17:09:52 +0200 Subject: yapf -rip --- poezio/config.py | 30 +++++++------ poezio/connection.py | 25 +++++++---- poezio/core/commands.py | 29 +++++++------ poezio/core/completions.py | 7 ++-- poezio/core/core.py | 38 +++++++++-------- poezio/core/handlers.py | 91 +++++++++++++++++++--------------------- poezio/logger.py | 20 +++------ poezio/plugin_manager.py | 14 ++++--- poezio/tabs/basetabs.py | 9 ++-- poezio/tabs/bookmarkstab.py | 8 ++-- poezio/tabs/confirmtab.py | 5 ++- poezio/tabs/conversationtab.py | 5 ++- poezio/tabs/listtab.py | 5 ++- poezio/tabs/muctab.py | 55 ++++++++++++------------ poezio/tabs/privatetab.py | 5 ++- poezio/tabs/rostertab.py | 22 ++++++---- poezio/tabs/xmltab.py | 10 +++-- poezio/text_buffer.py | 11 +++-- poezio/theming.py | 3 +- poezio/windows/base_wins.py | 4 +- poezio/windows/bookmark_forms.py | 53 ++++++++++++----------- poezio/windows/data_forms.py | 4 +- poezio/windows/info_wins.py | 6 +-- poezio/windows/inputs.py | 5 +-- poezio/windows/list.py | 12 +++--- poezio/windows/roster_win.py | 18 ++++---- poezio/xdg.py | 3 +- poezio/xhtml.py | 13 +++--- 28 files changed, 271 insertions(+), 239 deletions(-) diff --git a/poezio/config.py b/poezio/config.py index 5153b0d0..e6e5cbcc 100644 --- a/poezio/config.py +++ b/poezio/config.py @@ -316,16 +316,18 @@ class Config(RawConfigParser): sections, result_lines = result if section not in sections: - log.error('Tried to remove the option %s from a non-' - 'existing section (%s)', option, section) + log.error( + 'Tried to remove the option %s from a non-' + 'existing section (%s)', option, section) return True else: begin, end = sections[section] pos = find_line(result_lines, begin, end, option) if pos is -1: - log.error('Tried to remove a non-existing option %s' - ' from section %s', option, section) + log.error( + 'Tried to remove a non-existing option %s' + ' from section %s', option, section) return True else: del result_lines[pos] @@ -338,7 +340,8 @@ class Config(RawConfigParser): before copying it to the final destination """ try: - filename = self.file_name.parent / ('.%s.tmp' % self.file_name.name) + filename = self.file_name.parent / ( + '.%s.tmp' % self.file_name.name) with os.fdopen( os.open( str(filename), @@ -423,9 +426,10 @@ class Config(RawConfigParser): elif current.lower() == "true": value = "false" else: - return ('Could not toggle option: %s.' - ' Current value is %s.' % - (option, current or "empty"), 'Warning') + return ( + 'Could not toggle option: %s.' + ' Current value is %s.' % (option, current or "empty"), + 'Warning') if self.has_section(section): RawConfigParser.set(self, section, option, value) else: @@ -555,10 +559,12 @@ def run_cmdline_args(): try: options.filename.parent.mkdir(parents=True, exist_ok=True) except OSError as e: - sys.stderr.write('Poezio was unable to create the config directory: %s\n' % e) + sys.stderr.write( + 'Poezio was unable to create the config directory: %s\n' % e) sys.exit(1) default = Path(__file__).parent / '..' / 'data' / 'default_config.cfg' - other = Path(pkg_resources.resource_filename('poezio', 'default_config.cfg')) + other = Path( + pkg_resources.resource_filename('poezio', 'default_config.cfg')) if default.is_file(): copy2(str(default), str(options.filename)) elif other.is_file(): @@ -568,8 +574,8 @@ def run_cmdline_args(): # file is readonly, so is the copy. # Make it writable by the user who just created it. if options.filename.exists(): - options.filename.chmod( - options.filename.stat().st_mode | stat.S_IWUSR) + options.filename.chmod(options.filename.stat().st_mode + | stat.S_IWUSR) global firstrun firstrun = True diff --git a/poezio/connection.py b/poezio/connection.py index aba4a2f0..57254069 100644 --- a/poezio/connection.py +++ b/poezio/connection.py @@ -82,7 +82,9 @@ class Connection(slixmpp.ClientXMPP): jid = config.get('server') password = None jid = safeJID(jid) - jid.resource = '%s-%s' % (jid.resource, device_id) if jid.resource else 'poezio-%s' % device_id + jid.resource = '%s-%s' % ( + jid.resource, + device_id) if jid.resource else 'poezio-%s' % device_id # TODO: use the system language slixmpp.ClientXMPP.__init__( self, jid, password, lang=config.get('lang')) @@ -108,8 +110,9 @@ class Connection(slixmpp.ClientXMPP): self.auto_authorize = None # prosody defaults, lowest is AES128-SHA, it should be a minimum # for anything that came out after 2002 - self.ciphers = config.get('ciphers', 'HIGH+kEDH:HIGH+kEECDH:HIGH:!PSK' - ':!SRP:!3DES:!aNULL') + 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') if int(interval) > 0: @@ -119,11 +122,17 @@ class Connection(slixmpp.ClientXMPP): self.register_plugin('xep_0004') self.register_plugin('xep_0012') # Must be loaded before 0030. - self.register_plugin('xep_0115', { - 'caps_node': 'https://poez.io', - 'cache': FileSystemCache(str(xdg.CACHE_HOME), 'caps', encode=str, - decode=lambda x: DiscoInfo(ET.fromstring(x))), - }) + self.register_plugin( + 'xep_0115', { + 'caps_node': + 'https://poez.io', + 'cache': + FileSystemCache( + str(xdg.CACHE_HOME), + 'caps', + encode=str, + decode=lambda x: DiscoInfo(ET.fromstring(x))), + }) self.register_plugin('xep_0030') self.register_plugin('xep_0045') self.register_plugin('xep_0048') diff --git a/poezio/core/commands.py b/poezio/core/commands.py index e438e095..88bcb753 100644 --- a/poezio/core/commands.py +++ b/poezio/core/commands.py @@ -552,10 +552,10 @@ class CommandCore: theme.COLOR_INFORMATION_TEXT), }) for option_name, option_value in section.items(): - lines.append('%s\x19%s}=\x19o%s' % - (option_name, - dump_tuple(theme.COLOR_REVISIONS_MESSAGE), - option_value)) + lines.append( + '%s\x19%s}=\x19o%s' % + (option_name, dump_tuple( + theme.COLOR_REVISIONS_MESSAGE), option_value)) info = ('Current options:\n%s' % '\n'.join(lines), 'Info') elif len(args) == 1: option = args[0] @@ -570,7 +570,8 @@ class CommandCore: section = plugin_name option = args[1] if plugin_name not in self.core.plugin_manager.plugins: - file_name = self.core.plugin_manager.plugins_conf_dir / (plugin_name + '.cfg') + file_name = self.core.plugin_manager.plugins_conf_dir / ( + plugin_name + '.cfg') plugin_config = PluginConfig(file_name, plugin_name) else: plugin_config = self.core.plugin_manager.plugins[ @@ -597,7 +598,8 @@ class CommandCore: option = args[1] value = args[2] if plugin_name not in self.core.plugin_manager.plugins: - file_name = self.core.plugin_manager.plugins_conf_dir / (plugin_name + '.cfg') + file_name = self.core.plugin_manager.plugins_conf_dir / ( + plugin_name + '.cfg') plugin_config = PluginConfig(file_name, plugin_name) else: plugin_config = self.core.plugin_manager.plugins[ @@ -685,8 +687,9 @@ class CommandCore: "Callback for the last activity" if iq['type'] != 'result': if iq['error']['type'] == 'auth': - self.core.information('You are not allowed to see the ' - 'activity of this contact.', 'Error') + self.core.information( + 'You are not allowed to see the ' + 'activity of this contact.', 'Error') else: self.core.information('Error retrieving the activity', 'Error') @@ -753,8 +756,9 @@ class CommandCore: specific = args[1] text = args[2] if specific and specific not in pep.ACTIVITIES[general]: - return self.core.information('%s is not a correct value ' - 'for an activity' % specific, 'Error') + return self.core.information( + '%s is not a correct value ' + 'for an activity' % specific, 'Error') self.core.xmpp.plugin['xep_0108'].publish_activity( general, specific, text, callback=dumb_callback) @@ -928,8 +932,9 @@ class CommandCore: """ /plugins """ - self.core.information("Plugins currently in use: %s" % repr( - list(self.core.plugin_manager.plugins.keys())), 'Info') + self.core.information( + "Plugins currently in use: %s" % repr( + list(self.core.plugin_manager.plugins.keys())), 'Info') @command_args_parser.quoted(1, 1) def message(self, args): diff --git a/poezio/core/completions.py b/poezio/core/completions.py index 5d6e2e50..0f3b5931 100644 --- a/poezio/core/completions.py +++ b/poezio/core/completions.py @@ -67,7 +67,8 @@ class CompletionCore: def theme(self, the_input): """ Completion for /theme""" themes_dir = config.get('themes_dir') - themes_dir = Path(themes_dir).expanduser() if themes_dir else xdg.DATA_HOME / 'themes' + themes_dir = Path(themes_dir).expanduser( + ) if themes_dir else xdg.DATA_HOME / 'themes' try: theme_files = [ name.stem for name in themes_dir.iterdir() @@ -131,8 +132,8 @@ class CompletionCore: serv_list = [] for tab in self.core.get_tabs(tabs.MucTab): if tab.joined: - serv_list.append('%s@%s' % (jid.user, - safeJID(tab.name).host)) + serv_list.append( + '%s@%s' % (jid.user, safeJID(tab.name).host)) serv_list.extend(relevant_rooms) return Completion( the_input.new_completion, serv_list, 1, quotify=True) diff --git a/poezio/core/core.py b/poezio/core/core.py index aed36502..015515c0 100644 --- a/poezio/core/core.py +++ b/poezio/core/core.py @@ -77,7 +77,8 @@ class Core: self.bookmarks = BookmarkList() self.debug = False self.remote_fifo = None - self.avatar_cache = FileSystemPerJidCache(str(xdg.CACHE_HOME), 'avatars', binary=True) + self.avatar_cache = FileSystemPerJidCache( + str(xdg.CACHE_HOME), 'avatars', binary=True) # a unique buffer used to store global information # that are displayed in almost all tabs, in an # information window. @@ -320,10 +321,10 @@ class Core: self.on_request_receipts_config_change) self.add_configuration_handler("ack_message_receipts", self.on_ack_receipts_config_change) - self.add_configuration_handler("plugins_dir", - self.plugin_manager.on_plugins_dir_change) - self.add_configuration_handler("plugins_conf_dir", - self.plugin_manager.on_plugins_conf_dir_change) + self.add_configuration_handler( + "plugins_dir", self.plugin_manager.on_plugins_dir_change) + self.add_configuration_handler( + "plugins_conf_dir", self.plugin_manager.on_plugins_conf_dir_change) self.add_configuration_handler("connection_timeout_delay", self.xmpp.set_keepalive_values) self.add_configuration_handler("connection_check_interval", @@ -676,8 +677,9 @@ class Core: ok = ok and config.silent_set('info_win_height', self.information_win_size, 'var') if not ok: - self.information('Unable to save runtime preferences' - ' in the config file', 'Error') + self.information( + 'Unable to save runtime preferences' + ' in the config file', 'Error') def on_roster_enter_key(self, roster_row): """ @@ -767,15 +769,15 @@ class Core: filename = os.path.join(fifo_path, 'poezio.fifo') if not self.remote_fifo: try: - self.remote_fifo = Fifo( - filename, 'w') + self.remote_fifo = Fifo(filename, 'w') except (OSError, IOError) as exc: log.error( 'Could not open the fifo for writing (%s)', filename, exc_info=True) - self.information('Could not open the fifo ' - 'file for writing: %s' % exc, 'Error') + self.information( + 'Could not open the fifo ' + 'file for writing: %s' % exc, 'Error') return args = (pipes.quote(arg.replace('\n', ' ')) for arg in command) @@ -862,8 +864,9 @@ class Core: msg = msg.replace('\n', '|') if msg else '' ok = ok and config.silent_set('status_message', msg) if not ok: - self.information('Unable to save the status in ' - 'the config file', 'Error') + self.information( + 'Unable to save the status in ' + 'the config file', 'Error') def get_bookmark_nickname(self, room_name): """ @@ -1420,8 +1423,7 @@ class Core: if typ.lower() in filter_types: log.debug( 'Did not show the message:\n\t%s> %s \n\tdue to ' - 'information_buffer_type_filter configuration', - typ, msg) + 'information_buffer_type_filter configuration', typ, msg) return False filter_messages = config.get('filter_info_messages').split(':') for words in filter_messages: @@ -2076,9 +2078,9 @@ class Core: type_ = iq['error']['type'] condition = iq['error']['condition'] if not (type_ == 'cancel' and condition == 'item-not-found'): - self.information('Unable to fetch the remote' - ' bookmarks; %s: %s' % (type_, condition), - 'Error') + self.information( + 'Unable to fetch the remote' + ' bookmarks; %s: %s' % (type_, condition), 'Error') return remote_bookmarks = self.bookmarks.remote() self.join_initial_rooms(remote_bookmarks) diff --git a/poezio/core/handlers.py b/poezio/core/handlers.py index a3b0d8fc..7868cb59 100644 --- a/poezio/core/handlers.py +++ b/poezio/core/handlers.py @@ -138,8 +138,9 @@ class HandlerCore: sent = message['carbon_sent'] # todo: implement proper MUC detection logic - if (sent['to'].resource and (sent['to'].bare not in roster - or roster[sent['to'].bare].subscription == 'none')): + if (sent['to'].resource + and (sent['to'].bare not in roster + or roster[sent['to'].bare].subscription == 'none')): fixes.has_identity( self.core.xmpp, sent['to'].server, @@ -276,9 +277,7 @@ class HandlerCore: message['from'].bare) tmp_dir = get_image_cache() body = xhtml.get_body_from_message_stanza( - message, - use_xhtml=use_xhtml, - extract_images_to=tmp_dir) + message, use_xhtml=use_xhtml, extract_images_to=tmp_dir) if not body: if not self.core.xmpp.plugin['xep_0380'].has_eme(message): return @@ -332,9 +331,7 @@ class HandlerCore: if not message['body']: return body = xhtml.get_body_from_message_stanza( - message, - use_xhtml=use_xhtml, - extract_images_to=tmp_dir) + message, use_xhtml=use_xhtml, extract_images_to=tmp_dir) delayed, date = common.find_delayed_tag(message) def try_modify(): @@ -395,7 +392,8 @@ class HandlerCore: avatar_hash = info['id'] # First check whether we have it in cache. - cached_avatar = self.core.avatar_cache.retrieve_by_jid(jid, avatar_hash) + cached_avatar = self.core.avatar_cache.retrieve_by_jid( + jid, avatar_hash) if cached_avatar: contact.avatar = cached_avatar log.debug('Using cached avatar for %s', jid) @@ -404,9 +402,8 @@ class HandlerCore: # If we didn’t have any, query the data instead. if not info['url']: try: - result = await self.core.xmpp[ - 'xep_0084'].retrieve_avatar( - jid, avatar_hash, timeout=60) + result = await self.core.xmpp['xep_0084'].retrieve_avatar( + jid, avatar_hash, timeout=60) avatar = result['pubsub']['items']['item']['avatar_data'][ 'value'] if sha1(avatar).hexdigest().lower() != avatar_hash.lower(): @@ -421,7 +418,8 @@ class HandlerCore: log.debug('Received %s avatar: %s', jid, info['type']) # Now we save the data on the file system to not have to request it again. - if not self.core.avatar_cache.store_by_jid(jid, avatar_hash, contact.avatar): + if not self.core.avatar_cache.store_by_jid( + jid, avatar_hash, contact.avatar): log.debug( 'Failed writing %s’s avatar to cache:', jid, @@ -437,7 +435,8 @@ class HandlerCore: log.debug('Received vCard avatar update from %s: %s', jid, avatar_hash) # First check whether we have it in cache. - cached_avatar = self.core.avatar_cache.retrieve_by_jid(jid, avatar_hash) + cached_avatar = self.core.avatar_cache.retrieve_by_jid( + jid, avatar_hash) if cached_avatar: contact.avatar = cached_avatar log.debug('Using cached avatar for %s', jid) @@ -458,8 +457,10 @@ class HandlerCore: log.debug('Received %s avatar: %s', jid, avatar['TYPE']) # Now we save the data on the file system to not have to request it again. - if not self.core.avatar_cache.store_by_jid(jid, avatar_hash, contact.avatar): - log.debug('Failed writing %s’s avatar to cache:', jid, exc_info=True) + if not self.core.avatar_cache.store_by_jid(jid, avatar_hash, + contact.avatar): + log.debug( + 'Failed writing %s’s avatar to cache:', jid, exc_info=True) def on_nick_received(self, message): """ @@ -509,9 +510,9 @@ class HandlerCore: 'display_gaming_notifications', contact.bare_jid): if contact.gaming: self.core.information( - '%s is playing %s' % - (contact.bare_jid, - common.format_gaming_string(contact.gaming)), 'Gaming') + '%s is playing %s' % (contact.bare_jid, + common.format_gaming_string( + contact.gaming)), 'Gaming') else: self.core.information(contact.bare_jid + ' stopped playing.', 'Gaming') @@ -592,8 +593,9 @@ class HandlerCore: if old_activity != contact.activity and config.get_by_tabname( 'display_activity_notifications', contact.bare_jid): if contact.activity: - self.core.information('Activity from ' + contact.bare_jid + - ': ' + contact.activity, 'Activity') + self.core.information( + 'Activity from ' + contact.bare_jid + ': ' + + contact.activity, 'Activity') else: self.core.information( contact.bare_jid + ' stopped doing his/her activity.', @@ -625,9 +627,9 @@ class HandlerCore: contact.tune = {} if contact.tune: - logger.log_roster_change(message['from'].bare, - 'is now listening to %s' % - common.format_tune_string(contact.tune)) + logger.log_roster_change( + message['from'].bare, 'is now listening to %s' % + common.format_tune_string(contact.tune)) if old_tune != contact.tune and config.get_by_tabname( 'display_tune_notifications', contact.bare_jid): @@ -668,9 +670,7 @@ class HandlerCore: use_xhtml = config.get_by_tabname('enable_xhtml_im', room_from) tmp_dir = get_image_cache() body = xhtml.get_body_from_message_stanza( - message, - use_xhtml=use_xhtml, - extract_images_to=tmp_dir) + message, use_xhtml=use_xhtml, extract_images_to=tmp_dir) if not body: return @@ -744,9 +744,7 @@ class HandlerCore: use_xhtml = config.get_by_tabname('enable_xhtml_im', jid.bare) tmp_dir = get_image_cache() body = xhtml.get_body_from_message_stanza( - message, - use_xhtml=use_xhtml, - extract_images_to=tmp_dir) + message, use_xhtml=use_xhtml, extract_images_to=tmp_dir) tab = self.core.get_tab_by_name( jid.full, tabs.PrivateTab) # get the tab with the private conversation @@ -755,7 +753,8 @@ class HandlerCore: if body and not ignore: tab = self.core.open_private_window(room_from, with_nick, False) - sender_nick = (tab.own_nick or self.core.own_nick) if sent else with_nick + sender_nick = (tab.own_nick + or self.core.own_nick) if sent else with_nick if ignore and not sent: self.core.events.trigger('ignored_private', message, tab) msg = config.get_by_tabname('private_auto_response', room_from) @@ -765,9 +764,7 @@ class HandlerCore: return self.core.events.trigger('private_msg', message, tab) body = xhtml.get_body_from_message_stanza( - message, - use_xhtml=use_xhtml, - extract_images_to=tmp_dir) + message, use_xhtml=use_xhtml, extract_images_to=tmp_dir) if not body or not tab: return replaced = False @@ -898,15 +895,16 @@ class HandlerCore: if iq['type'] == 'error': error_condition = iq['error']['condition'] error_text = iq['error']['text'] - reply = '%s: %s' % (error_condition, error_text) if error_text else error_condition - return self.core.information('Could not get the software ' - 'version from %s: %s' % (jid, reply), - 'Warning') + reply = '%s: %s' % (error_condition, + error_text) if error_text else error_condition + return self.core.information( + 'Could not get the software ' + 'version from %s: %s' % (jid, reply), 'Warning') res = iq['software_version'] version = '%s is running %s version %s on %s' % ( jid, res.get('name', 'an unknown software'), - res.get('version', 'unknown'), - res.get('os', 'an unknown platform')) + res.get('version', 'unknown'), res.get('os', + 'an unknown platform')) self.core.information(version, 'Info') ### subscription-related handlers ### @@ -1127,8 +1125,8 @@ class HandlerCore: """ We cannot contact the remote server """ - self.core.information("Connection to remote server failed: %s" % - (error, ), 'Error') + self.core.information( + "Connection to remote server failed: %s" % (error, ), 'Error') async def on_disconnected(self, event): """ @@ -1230,8 +1228,8 @@ class HandlerCore: tab = self.core.get_tab_by_name(room_from, tabs.MucTab) status_codes = { s.attrib['code'] - for s in message.xml.findall('{%s}x/{%s}status' % ( - tabs.NS_MUC_USER, tabs.NS_MUC_USER)) + for s in message.xml.findall('{%s}x/{%s}status' % + (tabs.NS_MUC_USER, tabs.NS_MUC_USER)) } if '101' in status_codes: self.core.information( @@ -1342,9 +1340,8 @@ class HandlerCore: after = '' if user: user_col = dump_tuple(user.color) - user_string = '\x19%s}%s\x19%s}%s' % (user_col, nick_from, - fmt['info_col'], - after) + user_string = '\x19%s}%s\x19%s}%s' % ( + user_col, nick_from, fmt['info_col'], after) else: user_string = '\x19%s}%s%s' % (fmt['info_col'], nick_from, after) diff --git a/poezio/logger.py b/poezio/logger.py index 6f4c0060..f121784f 100644 --- a/poezio/logger.py +++ b/poezio/logger.py @@ -125,9 +125,7 @@ class Logger: return fd except IOError: log.error( - 'Unable to open the log file (%s)', - filename, - exc_info=True) + 'Unable to open the log file (%s)', filename, exc_info=True) def get_logs(self, jid, nb=10): """ @@ -151,16 +149,11 @@ class Logger: try: fd = filename.open('rb') except FileNotFoundError: - log.info( - 'Non-existing log file (%s)', - filename, - exc_info=True) + log.info('Non-existing log file (%s)', filename, exc_info=True) return except OSError: log.error( - 'Unable to open the log file (%s)', - filename, - exc_info=True) + 'Unable to open the log file (%s)', filename, exc_info=True) return if not fd: return @@ -228,8 +221,7 @@ class Logger: filename = log_dir / 'roster.log' if not self._roster_logfile: try: - self._roster_logfile = filename.open( - 'a', encoding='utf-8') + self._roster_logfile = filename.open('a', encoding='utf-8') except IOError: log.error( 'Unable to create the log file (%s)', @@ -242,8 +234,8 @@ class Logger: lines = message.split('\n') first_line = lines.pop(0) nb_lines = str(len(lines)).zfill(3) - self._roster_logfile.write('MI %s %s %s %s\n' % - (str_time, nb_lines, jid, first_line)) + self._roster_logfile.write( + 'MI %s %s %s %s\n' % (str_time, nb_lines, jid, first_line)) for line in lines: self._roster_logfile.write(' %s\n' % line) self._roster_logfile.flush() diff --git a/poezio/plugin_manager.py b/poezio/plugin_manager.py index d0273907..89849747 100644 --- a/poezio/plugin_manager.py +++ b/poezio/plugin_manager.py @@ -93,8 +93,8 @@ class PluginManager: except Exception as e: log.error('Error while loading the plugin %s', name, exc_info=True) if notify: - self.core.information('Unable to load the plugin %s: %s' % - (name, e), 'Error') + self.core.information( + 'Unable to load the plugin %s: %s' % (name, e), 'Error') self.unload(name, notify=False) else: if notify: @@ -130,8 +130,8 @@ class PluginManager: self.core.information('Plugin %s unloaded' % name, 'Info') except Exception as e: log.debug("Could not unload plugin %s", name, exc_info=True) - self.core.information("Could not unload plugin %s: %s" % - (name, e), 'Error') + self.core.information( + "Could not unload plugin %s: %s" % (name, e), 'Error') def add_command(self, module_name, @@ -327,7 +327,8 @@ class PluginManager: Create the plugins_conf_dir """ plugins_conf_dir = config.get('plugins_conf_dir') - self.plugins_conf_dir = Path(plugins_conf_dir).expanduser() if plugins_conf_dir else xdg.CONFIG_HOME / 'plugins' + self.plugins_conf_dir = Path(plugins_conf_dir).expanduser( + ) if plugins_conf_dir else xdg.CONFIG_HOME / 'plugins' self.check_create_plugins_conf_dir() def check_create_plugins_conf_dir(self): @@ -351,7 +352,8 @@ class PluginManager: Set the plugins_dir on start """ plugins_dir = config.get('plugins_dir') - self.plugins_dir = Path(plugins_dir).expanduser() if plugins_dir else xdg.DATA_HOME / 'plugins' + self.plugins_dir = Path(plugins_dir).expanduser( + ) if plugins_dir else xdg.DATA_HOME / 'plugins' self.check_create_plugins_dir() def check_create_plugins_dir(self): diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py index 2865f443..9ba8e6e5 100644 --- a/poezio/tabs/basetabs.py +++ b/poezio/tabs/basetabs.py @@ -293,8 +293,8 @@ class Tab: if self.missing_command_callback is not None: error_handled = self.missing_command_callback(low) if not error_handled: - self.core.information("Unknown command (%s)" % - (command), 'Error') + self.core.information( + "Unknown command (%s)" % (command), 'Error') if command in ('correct', 'say'): # hack arg = xhtml.convert_simple_to_full_colors(arg) else: @@ -685,8 +685,9 @@ class ChatTab(Tab): 'paused') self.core.add_timed_event(new_event) self.timed_event_paused = new_event - new_event = timed_events.DelayedEvent(30, self.send_chat_state, - 'inactive' if self.inactive else 'active') + new_event = timed_events.DelayedEvent( + 30, self.send_chat_state, 'inactive' + if self.inactive else 'active') self.core.add_timed_event(new_event) self.timed_event_not_paused = new_event diff --git a/poezio/tabs/bookmarkstab.py b/poezio/tabs/bookmarkstab.py index ceccc99d..1ee623c5 100644 --- a/poezio/tabs/bookmarkstab.py +++ b/poezio/tabs/bookmarkstab.py @@ -25,7 +25,8 @@ class BookmarksTab(Tab): self.new_bookmarks = [] self.removed_bookmarks = [] self.header_win = windows.ColumnHeaderWin( - ('name', 'room@server/nickname', 'password', 'autojoin', 'storage')) + ('name', 'room@server/nickname', 'password', 'autojoin', + 'storage')) self.bookmarks_win = windows.BookmarksWin( self.bookmarks, self.height - 4, self.width, 1, 0) self.help_win = windows.HelpText('Ctrl+Y: save, Ctrl+G: cancel, ' @@ -77,8 +78,9 @@ class BookmarksTab(Tab): if not self.bookmarks[bm.jid]: self.bookmarks.append(bm) else: - self.core.information('Invalid JID for bookmark: %s/%s' % - (bm.jid, bm.nick), 'Error') + self.core.information( + 'Invalid JID for bookmark: %s/%s' % (bm.jid, bm.nick), + 'Error') return for bm in self.removed_bookmarks: diff --git a/poezio/tabs/confirmtab.py b/poezio/tabs/confirmtab.py index 28c26122..545bb761 100644 --- a/poezio/tabs/confirmtab.py +++ b/poezio/tabs/confirmtab.py @@ -106,8 +106,9 @@ class ConfirmTab(Tab): def on_info_win_size_changed(self): if self.core.information_win_size >= self.height - 3: return - self.dialog.resize(self.height - 3 - self.core.information_win_size - - Tab.tab_win_height(), self.width, 1, 0) + self.dialog.resize( + self.height - 3 - self.core.information_win_size - + Tab.tab_win_height(), self.width, 1, 0) self.infowin_bottom.resize( 1, self.width, self.height - 2 - self.core.information_win_size - Tab.tab_win_height(), 0) diff --git a/poezio/tabs/conversationtab.py b/poezio/tabs/conversationtab.py index a8a22b4a..e93fe1e3 100644 --- a/poezio/tabs/conversationtab.py +++ b/poezio/tabs/conversationtab.py @@ -376,8 +376,9 @@ class ConversationTab(OneToOneTab): def on_info_win_size_changed(self): if self.core.information_win_size >= self.height - 3: return - self.text_win.resize(self.height - 3 - self.core.information_win_size - - Tab.tab_win_height(), self.width, 1, 0) + self.text_win.resize( + self.height - 3 - self.core.information_win_size - + Tab.tab_win_height(), self.width, 1, 0) self.get_info_header().resize( 1, self.width, self.height - 2 - self.core.information_win_size - Tab.tab_win_height(), 0) diff --git a/poezio/tabs/listtab.py b/poezio/tabs/listtab.py index 84dcc38b..1c96f778 100644 --- a/poezio/tabs/listtab.py +++ b/poezio/tabs/listtab.py @@ -173,8 +173,9 @@ class ListTab(Tab): self.info_header.resize( 1, self.width, self.height - 2 - self.core.information_win_size - Tab.tab_win_height(), 0) - self.listview.resize(self.height - 3 - self.core.information_win_size - - Tab.tab_win_height(), self.width, 1, 0) + self.listview.resize( + self.height - 3 - self.core.information_win_size - + Tab.tab_win_height(), self.width, 1, 0) def on_lose_focus(self): self.state = 'normal' diff --git a/poezio/tabs/muctab.py b/poezio/tabs/muctab.py index 70d66ffb..60d5a64b 100644 --- a/poezio/tabs/muctab.py +++ b/poezio/tabs/muctab.py @@ -193,9 +193,9 @@ class MucTab(ChatTab): valid_affiliations = ('outcast', 'none', 'member', 'admin', 'owner') if affiliation not in valid_affiliations: - return self.core.information('The affiliation must be one of ' + - ', '.join(valid_affiliations), - 'Error') + return self.core.information( + 'The affiliation must be one of ' + + ', '.join(valid_affiliations), 'Error') if nick_or_jid in [user.nick for user in self.users]: muc.set_user_affiliation( self.core.xmpp, @@ -220,8 +220,9 @@ class MucTab(ChatTab): def callback(iq): if iq['type'] == 'error': - self.core.information("Could not set role '%s' for '%s'." % - (role, nick), "Warning") + self.core.information( + "Could not set role '%s' for '%s'." % (role, nick), + "Warning") valid_roles = ('none', 'visitor', 'participant', 'moderator') @@ -281,10 +282,8 @@ class MucTab(ChatTab): user = self.get_user_by_name(self.topic_from) if user: user_text = dump_tuple(user.color) - user_string = '\x19%s}(set by \x19%s}%s\x19%s})' % (info_text, - user_text, - user.nick, - info_text) + user_string = '\x19%s}(set by \x19%s}%s\x19%s})' % ( + info_text, user_text, user.nick, info_text) else: user_string = self.topic_from else: @@ -650,8 +649,8 @@ class MucTab(ChatTab): self.core.on_user_rejoined_private_conversation(self.name, from_nick) def on_user_nick_change(self, presence, user, from_nick, from_room): - new_nick = presence.xml.find('{%s}x/{%s}item' % - (NS_MUC_USER, NS_MUC_USER)).attrib['nick'] + new_nick = presence.xml.find( + '{%s}x/{%s}item' % (NS_MUC_USER, NS_MUC_USER)).attrib['nick'] old_color = user.color if user.nick == self.own_nick: self.own_nick = new_nick @@ -959,9 +958,8 @@ class MucTab(ChatTab): role != user.role): # display the message in the room self._text_buffer.add_message(msg) - self.core.on_user_changed_status_in_private('%s/%s' % (from_room, - from_nick), - Status(show, status)) + self.core.on_user_changed_status_in_private( + '%s/%s' % (from_room, from_nick), Status(show, status)) self.users.remove(user) # finally, effectively change the user status user.update(affiliation, show, status, role) @@ -1178,8 +1176,9 @@ class MucTab(ChatTab): info_win_height = self.core.information_win_size self.user_win.resize( - self.height - 3 - info_win_height - tab_win_height, self.width - - (self.width // 10) * 9 - 1, 1, (self.width // 10) * 9 + 1) + self.height - 3 - info_win_height - tab_win_height, + self.width - (self.width // 10) * 9 - 1, 1, + (self.width // 10) * 9 + 1) self.v_separator.resize( self.height - 3 - info_win_height - tab_win_height, 1, 1, 9 * (self.width // 10)) @@ -1223,15 +1222,16 @@ class MucTab(ChatTab): text_width = self.width else: text_width = (self.width // 10) * 9 - self.user_win.resize(self.height - 3 - self.core.information_win_size - - Tab.tab_win_height(), - self.width - (self.width // 10) * 9 - 1, 1, - (self.width // 10) * 9 + 1) + self.user_win.resize( + self.height - 3 - self.core.information_win_size - + Tab.tab_win_height(), self.width - (self.width // 10) * 9 - 1, 1, + (self.width // 10) * 9 + 1) self.v_separator.resize( self.height - 3 - self.core.information_win_size - Tab.tab_win_height(), 1, 1, 9 * (self.width // 10)) - self.text_win.resize(self.height - 3 - self.core.information_win_size - - Tab.tab_win_height(), text_width, 1, 0) + self.text_win.resize( + self.height - 3 - self.core.information_win_size - + Tab.tab_win_height(), text_width, 1, 0) self.info_header.resize( 1, self.width, self.height - 2 - self.core.information_win_size - Tab.tab_win_height(), 0) @@ -1329,8 +1329,9 @@ class MucTab(ChatTab): nick = args[0] color = args[1].lower() if nick == self.own_nick: - return self.core.information("You cannot change the color of your" - " own nick.", 'Error') + return self.core.information( + "You cannot change the color of your" + " own nick.", 'Error') elif color not in xhtml.colors and color not in ('unset', 'random'): return self.core.information("Unknown color: %s" % color, 'Error') self.set_nick_color(nick, color) @@ -1446,9 +1447,9 @@ class MucTab(ChatTab): affiliation = aff.get(user.affiliation, get_theme().CHAR_AFFILIATION_NONE) color = colors.get(user.role, color_other) - buff.append('\x19%s}%s\x19o\x19%s}%s\x19o' % - (color, affiliation, dump_tuple(user.color), - user.nick)) + buff.append( + '\x19%s}%s\x19o\x19%s}%s\x19o' % + (color, affiliation, dump_tuple(user.color), user.nick)) buff.append('\n') message = ' '.join(buff) diff --git a/poezio/tabs/privatetab.py b/poezio/tabs/privatetab.py index d0a12232..d2d2f5ac 100644 --- a/poezio/tabs/privatetab.py +++ b/poezio/tabs/privatetab.py @@ -307,8 +307,9 @@ class PrivateTab(OneToOneTab): def on_info_win_size_changed(self): if self.core.information_win_size >= self.height - 3: return - self.text_win.resize(self.height - 2 - self.core.information_win_size - - Tab.tab_win_height(), self.width, 0, 0) + self.text_win.resize( + self.height - 2 - self.core.information_win_size - + Tab.tab_win_height(), self.width, 0, 0) self.info_header.resize( 1, self.width, self.height - 2 - self.core.information_win_size - Tab.tab_win_height(), 0) diff --git a/poezio/tabs/rostertab.py b/poezio/tabs/rostertab.py index d4c302a3..6aba2c15 100644 --- a/poezio/tabs/rostertab.py +++ b/poezio/tabs/rostertab.py @@ -272,8 +272,9 @@ class RosterInfoTab(Tab): if not certs: return self.core.information('No certificates found', 'Info') msg = 'Certificates:\n' - msg += '\n'.join(((' %s%s' % (item[0] + (': ' if item[1] else ''), - item[1])) for item in certs)) + msg += '\n'.join( + ((' %s%s' % (item[0] + (': ' if item[1] else ''), item[1])) + for item in certs)) self.core.information(msg, 'Info') self.core.xmpp.plugin['xep_0257'].get_certs(callback=cb, timeout=3) @@ -624,7 +625,9 @@ class RosterInfoTab(Tab): names = list(dir_.iterdir()) except OSError: names = [] - names_filtered = [name for name in names if str(name).startswith(base)] + names_filtered = [ + name for name in names if str(name).startswith(base) + ] if names_filtered: names = names_filtered if not names: @@ -703,8 +706,8 @@ class RosterInfoTab(Tab): return jid = safeJID(safeJID(args[0]).bare) if not str(jid): - self.core.information('The provided JID (%s) is not valid' % - (args[0], ), 'Error') + self.core.information( + 'The provided JID (%s) is not valid' % (args[0], ), 'Error') return if jid in roster and roster[jid].subscription in ('to', 'both'): return self.core.information('Already subscribed.', 'Roster') @@ -1267,8 +1270,9 @@ class RosterInfoTab(Tab): acc.append('Contact: %s (%s)' % (cont.bare_jid, res.presence if res else 'unavailable')) if res: - acc.append('%s connected resource%s' % - (len(cont), '' if len(cont) == 1 else 's')) + acc.append( + '%s connected resource%s' % (len(cont), '' + if len(cont) == 1 else 's')) acc.append('Current status: %s' % res.status) if cont.tune: acc.append('Tune: %s' % common.format_tune_string(cont.tune)) @@ -1277,8 +1281,8 @@ class RosterInfoTab(Tab): if cont.activity: acc.append('Activity: %s' % cont.activity) if cont.gaming: - acc.append('Game: %s' % - (common.format_gaming_string(cont.gaming))) + acc.append( + 'Game: %s' % (common.format_gaming_string(cont.gaming))) msg = '\n'.join(acc) elif isinstance(selected_row, Resource): res = selected_row diff --git a/poezio/tabs/xmltab.py b/poezio/tabs/xmltab.py index 26d5aef3..fc04f778 100644 --- a/poezio/tabs/xmltab.py +++ b/poezio/tabs/xmltab.py @@ -261,8 +261,9 @@ class XMLTab(Tab): xml = self.filtered_buffer.messages[:] else: xml = self.core_buffer.messages[:] - text = '\n'.join(('%s %s %s' % (msg.str_time, msg.nickname, - clean_text(msg.txt)) for msg in xml)) + text = '\n'.join( + ('%s %s %s' % (msg.str_time, msg.nickname, clean_text(msg.txt)) + for msg in xml)) filename = os.path.expandvars(os.path.expanduser(args[0])) try: with open(filename, 'w') as fd: @@ -375,8 +376,9 @@ class XMLTab(Tab): def on_info_win_size_changed(self): if self.core.information_win_size >= self.height - 3: return - self.text_win.resize(self.height - 2 - self.core.information_win_size - - Tab.tab_win_height(), self.width, 0, 0) + self.text_win.resize( + self.height - 2 - self.core.information_win_size - + Tab.tab_win_height(), self.width, 0, 0) self.info_header.resize( 1, self.width, self.height - 2 - self.core.information_win_size - Tab.tab_win_height(), 0) diff --git a/poezio/text_buffer.py b/poezio/text_buffer.py index 8043c834..a2e8c8ca 100644 --- a/poezio/text_buffer.py +++ b/poezio/text_buffer.py @@ -214,9 +214,8 @@ class TextBuffer: if msg.ack == 1: # Message was already acked return False if msg.jid != jid: - raise AckError( - 'Wrong JID for message id %s (was %s, expected %s)' % - (old_id, msg.jid, jid)) + raise AckError('Wrong JID for message id %s (was %s, expected %s)' + % (old_id, msg.jid, jid)) msg.ack = value if append: @@ -253,9 +252,9 @@ class TextBuffer: raise CorrectionError('Could not check the ' 'identity of the sender') elif not msg.user and msg.jid != jid: - raise CorrectionError('Messages %s and %s have not been ' - 'sent by the same fullJID' % (old_id, - new_id)) + raise CorrectionError( + 'Messages %s and %s have not been ' + 'sent by the same fullJID' % (old_id, new_id)) if not time: time = msg.time diff --git a/poezio/theming.py b/poezio/theming.py index 029a9a6c..1ea70d73 100755 --- a/poezio/theming.py +++ b/poezio/theming.py @@ -495,7 +495,8 @@ def update_themes_dir(option=None, value=None): # import from the user-defined prefs themes_dir = config.get('themes_dir') - themes_dir = Path(themes_dir).expanduser() if themes_dir else xdg.DATA_HOME / 'themes' + themes_dir = Path( + themes_dir).expanduser() if themes_dir else xdg.DATA_HOME / 'themes' try: themes_dir.mkdir(parents=True, exist_ok=True) except OSError: diff --git a/poezio/windows/base_wins.py b/poezio/windows/base_wins.py index 41f6a761..eaedd82b 100644 --- a/poezio/windows/base_wins.py +++ b/poezio/windows/base_wins.py @@ -120,8 +120,8 @@ class Win: self._win.attron(attr_italic) if (attr_char in string.digits or attr_char == '-') and attr_char != '': - color_str = text[next_attr_char + 1:text.find( - '}', next_attr_char)] + color_str = text[next_attr_char + + 1:text.find('}', next_attr_char)] if ',' in color_str: tup, char = read_tuple(color_str) self._win.attron(to_curses_attr(tup)) diff --git a/poezio/windows/bookmark_forms.py b/poezio/windows/bookmark_forms.py index 25d4055d..5a319c27 100644 --- a/poezio/windows/bookmark_forms.py +++ b/poezio/windows/bookmark_forms.py @@ -184,8 +184,8 @@ class BookmarksWin(Win): BookmarkPasswordInput(bookmark), BookmarkAutojoinWin(bookmark), BookmarkMethodInput(bookmark))) - self.lines[ - self.current_input][self.current_horizontal_input].set_color( + self.lines[self.current_input][ + self.current_horizontal_input].set_color( get_theme().COLOR_NORMAL_TEXT) self.current_horizontal_input = 0 self.current_input = len(self.lines) - 1 @@ -218,8 +218,8 @@ class BookmarksWin(Win): return if self.current_input == len(self.lines) - 1: return - self.lines[ - self.current_input][self.current_horizontal_input].set_color( + self.lines[self.current_input][ + self.current_horizontal_input].set_color( get_theme().COLOR_NORMAL_TEXT) # Adjust the scroll position if the current_input would be outside # of the visible area @@ -238,8 +238,8 @@ class BookmarksWin(Win): return if self.current_input == 0: return - self.lines[ - self.current_input][self.current_horizontal_input].set_color( + self.lines[self.current_input][ + self.current_horizontal_input].set_color( get_theme().COLOR_NORMAL_TEXT) self.current_input -= 1 # Adjust the scroll position if the current_input would be outside @@ -247,21 +247,21 @@ class BookmarksWin(Win): if self.current_input < self.scroll_pos: self.scroll_pos = self.current_input self.refresh() - self.lines[ - self.current_input][self.current_horizontal_input].set_color( + self.lines[self.current_input][ + self.current_horizontal_input].set_color( get_theme().COLOR_SELECTED_ROW) def go_to_next_horizontal_input(self): if not self.lines: return - self.lines[ - self.current_input][self.current_horizontal_input].set_color( + self.lines[self.current_input][ + self.current_horizontal_input].set_color( get_theme().COLOR_NORMAL_TEXT) self.current_horizontal_input += 1 if self.current_horizontal_input > 3: self.current_horizontal_input = 0 - self.lines[ - self.current_input][self.current_horizontal_input].set_color( + self.lines[self.current_input][ + self.current_horizontal_input].set_color( get_theme().COLOR_SELECTED_ROW) def go_to_next_page(self): @@ -271,8 +271,8 @@ class BookmarksWin(Win): if self.current_input == len(self.lines) - 1: return - self.lines[ - self.current_input][self.current_horizontal_input].set_color( + self.lines[self.current_input][ + self.current_horizontal_input].set_color( get_theme().COLOR_NORMAL_TEXT) inc = min(self.height, len(self.lines) - self.current_input - 1) @@ -294,8 +294,8 @@ class BookmarksWin(Win): if self.current_input == 0: return - self.lines[ - self.current_input][self.current_horizontal_input].set_color( + self.lines[self.current_input][ + self.current_horizontal_input].set_color( get_theme().COLOR_NORMAL_TEXT) dec = min(self.height, self.current_input) @@ -305,8 +305,8 @@ class BookmarksWin(Win): if self.current_input < self.scroll_pos: self.scroll_pos = self.current_input self.refresh() - self.lines[ - self.current_input][self.current_horizontal_input].set_color( + self.lines[self.current_input][ + self.current_horizontal_input].set_color( get_theme().COLOR_SELECTED_ROW) return True @@ -315,12 +315,12 @@ class BookmarksWin(Win): return if self.current_horizontal_input == 0: return - self.lines[ - self.current_input][self.current_horizontal_input].set_color( + self.lines[self.current_input][ + self.current_horizontal_input].set_color( get_theme().COLOR_NORMAL_TEXT) self.current_horizontal_input -= 1 - self.lines[ - self.current_input][self.current_horizontal_input].set_color( + self.lines[self.current_input][ + self.current_horizontal_input].set_color( get_theme().COLOR_SELECTED_ROW) def on_input(self, key): @@ -336,9 +336,12 @@ class BookmarksWin(Win): for i in range(len(self.lines)): self.lines[i][0].resize(1, self.width // 4, y + 1, 0) self.lines[i][1].resize(1, self.width // 4, y + 1, self.width // 4) - self.lines[i][2].resize(1, self.width // 6, y + 1, 3 * self.width // 6) - self.lines[i][3].resize(1, self.width // 6, y + 1, 4 * self.width // 6) - self.lines[i][4].resize(1, self.width // 6, y + 1, 5 * self.width // 6) + self.lines[i][2].resize(1, self.width // 6, y + 1, + 3 * self.width // 6) + self.lines[i][3].resize(1, self.width // 6, y + 1, + 4 * self.width // 6) + self.lines[i][4].resize(1, self.width // 6, y + 1, + 5 * self.width // 6) y += 1 self._refresh() for i, inp in enumerate(self.lines): diff --git a/poezio/windows/data_forms.py b/poezio/windows/data_forms.py index d5ee29c5..dc954bd7 100644 --- a/poezio/windows/data_forms.py +++ b/poezio/windows/data_forms.py @@ -422,8 +422,8 @@ class FormWin: self.current_input += 1 jump = 0 while self.current_input + jump != len( - self.inputs) - 1 and self.inputs[self.current_input - + jump]['input'].is_dummy(): + self.inputs) - 1 and self.inputs[self.current_input + + jump]['input'].is_dummy(): jump += 1 if self.inputs[self.current_input + jump]['input'].is_dummy(): return diff --git a/poezio/windows/info_wins.py b/poezio/windows/info_wins.py index 2d4d1e01..27f9e1cf 100644 --- a/poezio/windows/info_wins.py +++ b/poezio/windows/info_wins.py @@ -228,9 +228,9 @@ class DynamicConversationInfoWin(ConversationInfoWin): self.addstr(jid.bare, to_curses_attr(get_theme().COLOR_CONVERSATION_NAME)) if jid.resource: - self.addstr("/%s" % (jid.resource, ), - to_curses_attr( - get_theme().COLOR_CONVERSATION_RESOURCE)) + self.addstr( + "/%s" % (jid.resource, ), + to_curses_attr(get_theme().COLOR_CONVERSATION_RESOURCE)) self.addstr('] ', to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) diff --git a/poezio/windows/inputs.py b/poezio/windows/inputs.py index 6956f4f6..6453205c 100644 --- a/poezio/windows/inputs.py +++ b/poezio/windows/inputs.py @@ -522,9 +522,8 @@ class Input(Win): self._win.erase() if self.color: self._win.attron(to_curses_attr(self.color)) - displayed_text = text[self.view_pos: - self.view_pos + self.width - 1].replace( - '\t', '\x18') + displayed_text = text[self.view_pos:self.view_pos + self.width - + 1].replace('\t', '\x18') self._win.attrset(0) self._addstr_colored_lite(displayed_text) # Fill the rest of the line with the input color diff --git a/poezio/windows/list.py b/poezio/windows/list.py index 1f51e88f..26cb1e5f 100644 --- a/poezio/windows/list.py +++ b/poezio/windows/list.py @@ -101,9 +101,9 @@ class ListWin(Win): if not txt: continue if line is self.lines[self._selected_row]: - self.addstr(y, x, txt[:size], - to_curses_attr( - get_theme().COLOR_INFORMATION_BAR)) + self.addstr( + y, x, txt[:size], + to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) else: self.addstr(y, x, txt[:size]) x += size @@ -192,9 +192,9 @@ class ColumnHeaderWin(Win): size = self._columns_sizes[col] txt += ' ' * (size - len(txt)) if col in self._column_sel: - self.addstr(0, x, txt, - to_curses_attr( - get_theme().COLOR_COLUMN_HEADER_SEL)) + self.addstr( + 0, x, txt, + to_curses_attr(get_theme().COLOR_COLUMN_HEADER_SEL)) else: self.addstr(0, x, txt, to_curses_attr(get_theme().COLOR_COLUMN_HEADER)) diff --git a/poezio/windows/roster_win.py b/poezio/windows/roster_win.py index 36c41ae6..f1490709 100644 --- a/poezio/windows/roster_win.py +++ b/poezio/windows/roster_win.py @@ -146,8 +146,8 @@ class RosterWin(Win): self.scroll_down(self.pos - self.start_pos - self.height + (self.height // 2)) # draw the roster from the cache - roster_view = self.roster_cache[self.start_pos - 1: - self.start_pos + self.height] + roster_view = self.roster_cache[self.start_pos - 1:self.start_pos + + self.height] options = { 'show_roster_sub': config.get('show_roster_subscriptions'), @@ -190,9 +190,10 @@ class RosterWin(Win): """ The header at the top """ - self.addstr('Roster: %s/%s contacts' % - (roster.get_nb_connected_contacts(), len(roster)), - to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) + self.addstr( + 'Roster: %s/%s contacts' % (roster.get_nb_connected_contacts(), + len(roster)), + to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) self.finish_line(get_theme().COLOR_INFORMATION_BAR) def draw_group(self, y, group, colored): @@ -206,9 +207,10 @@ class RosterWin(Win): else: self.addstr(y, 0, '[-] ') contacts = " (%s/%s)" % (group.get_nb_connected_contacts(), len(group)) - self.addstr(y, 4, - self.truncate_name(group.name, - len(contacts) + 4) + contacts) + self.addstr( + y, 4, + self.truncate_name(group.name, + len(contacts) + 4) + contacts) if colored: self._win.attroff(to_curses_attr(get_theme().COLOR_SELECTED_ROW)) self.finish_line() diff --git a/poezio/xdg.py b/poezio/xdg.py index 79dc24a9..e4b336a5 100644 --- a/poezio/xdg.py +++ b/poezio/xdg.py @@ -4,7 +4,6 @@ # # Poezio is free software: you can redistribute it and/or modify # it under the terms of the zlib license. See the COPYING file. - """ Implements the XDG base directory specification. @@ -21,6 +20,7 @@ DEFAULT_PATHS = { 'XDG_CACHE_HOME': Path.home() / '.cache', } + def _get_directory(variable: str): """ returns the default configuration directory path @@ -34,6 +34,7 @@ def _get_directory(variable: str): return xdg_path / 'poezio' return DEFAULT_PATHS[variable] / 'poezio' + CONFIG_HOME = _get_directory('XDG_CONFIG_HOME') DATA_HOME = _get_directory('XDG_DATA_HOME') CACHE_HOME = _get_directory('XDG_CACHE_HOME') diff --git a/poezio/xhtml.py b/poezio/xhtml.py index 29a87ca2..7de048ae 100644 --- a/poezio/xhtml.py +++ b/poezio/xhtml.py @@ -208,8 +208,7 @@ def get_body_from_message_stanza(message, xhtml_body = xhtml.find('{http://www.w3.org/1999/xhtml}body') if xhtml_body is None: return message['body'] - content = xhtml_to_poezio_colors( - xhtml_body, tmp_dir=extract_images_to) + content = xhtml_to_poezio_colors(xhtml_body, tmp_dir=extract_images_to) content = content if content else message['body'] return content or " " @@ -356,7 +355,8 @@ class XHTMLHandler(sax.ContentHandler): elif name == 'em': self.append_formatting('\x19i') elif name == 'img': - if re.match(xhtml_data_re, attrs['src']) and self.tmp_image_dir is not None: + if re.match(xhtml_data_re, + attrs['src']) and self.tmp_image_dir is not None: type_, data = [ i for i in re.split(xhtml_data_re, attrs['src']) if i ] @@ -441,8 +441,7 @@ def xhtml_to_poezio_colors(xml, force=False, tmp_dir=None): elif not isinstance(xml, bytes): xml = ET.tostring(xml) - handler = XHTMLHandler( - force_ns=force, tmp_image_dir=tmp_dir) + handler = XHTMLHandler(force_ns=force, tmp_image_dir=tmp_dir) parser = sax.make_parser() parser.setFeature(sax.handler.feature_namespaces, True) parser.setContentHandler(handler) @@ -561,8 +560,8 @@ def poezio_colors_to_html(string): check_property('font-style', 'italic') if attr_char in digits: - number_str = string[next_attr_char + 1:string.find( - '}', next_attr_char)] + number_str = string[next_attr_char + + 1:string.find('}', next_attr_char)] number = int(number_str) if number in number_to_color_names: check_property('color', -- cgit v1.2.3