Fix 'W504 line break after binary operator' flake8 warnings

Fixed by running

autopep8 -i -r --select=W504 .

and some hand tuning.
This commit is contained in:
Teemu Ikonen 2022-09-06 23:28:39 +03:00
parent 6bd0bb0530
commit d87ac85506
17 changed files with 118 additions and 117 deletions

View File

@ -1176,8 +1176,8 @@ class gPodderCli(object):
defaults = defaults or ()
minarg, maxarg = len(args) - len(defaults), len(args)
if (len(command_line) < minarg or
(len(command_line) > maxarg and varargs is None)):
if (len(command_line) < minarg
or (len(command_line) > maxarg and varargs is None)):
self._error('Wrong argument count for %s.' % func.__name__)
return False

View File

@ -139,9 +139,9 @@ def main():
from gpodder import log
log.setup(options.verbose, options.quiet)
if (not (gpodder.ui.win32 or gpodder.ui.osx) and
os.environ.get('DISPLAY', '') == '' and
os.environ.get('WAYLAND_DISPLAY', '') == ''):
if (not (gpodder.ui.win32 or gpodder.ui.osx)
and os.environ.get('DISPLAY', '') == ''
and os.environ.get('WAYLAND_DISPLAY', '') == ''):
logger.error('Cannot start gPodder: $DISPLAY or $WAYLAND_DISPLAY is not set.')
sys.exit(1)

View File

@ -121,18 +121,18 @@ class CurrentTrackTracker(object):
# If the position is being updated, and the current status was Playing
# If the status *is* playing, and *was* playing, but the position
# has changed discontinuously, notify a stop for the old position
if (cur['status'] == 'Playing' and
('status' not in kwargs or kwargs['status'] == 'Playing') and not
if (cur['status'] == 'Playing'
and ('status' not in kwargs or kwargs['status'] == 'Playing') and not
subsecond_difference(cur['pos'], kwargs['pos'])):
logger.debug('notify Stopped: playback discontinuity:' +
'calc: %r observed: %r', cur['pos'], kwargs['pos'])
logger.debug('notify Stopped: playback discontinuity:'
+ 'calc: %r observed: %r', cur['pos'], kwargs['pos'])
self.notify_stop()
if ((kwargs['pos']) <= 0 and
self.pos is not None and
self.length is not None and
(self.length - USECS_IN_SEC) < self.pos and
self.pos < (self.length + 2 * USECS_IN_SEC)):
if ((kwargs['pos']) <= 0
and self.pos is not None
and self.length is not None
and (self.length - USECS_IN_SEC) < self.pos
and self.pos < (self.length + 2 * USECS_IN_SEC)):
logger.debug('pos=0 end of stream (calculated pos: %f/%f [%f])',
self.pos / USECS_IN_SEC, self.length / USECS_IN_SEC,
(self.pos / USECS_IN_SEC) - (self.length / USECS_IN_SEC))
@ -174,11 +174,11 @@ class CurrentTrackTracker(object):
self.notify('Playing')
def notify(self, status):
if (self.uri is None or
self.pos is None or
self.status is None or
self.length is None or
self.length <= 0):
if (self.uri is None
or self.pos is None
or self.status is None
or self.length is None
or self.length <= 0):
return
pos = self.pos // USECS_IN_SEC
parsed_url = urllib.parse.urlparse(self.uri)

View File

@ -48,8 +48,8 @@ class gPodderExtension(object):
srtContent = ''
for captionIndex, caption in enumerate(jsonobject['captions'], 1):
startTime = self.milli_to_srt(introduration + caption['startTime'])
endTime = self.milli_to_srt(introduration + caption['startTime'] +
caption['duration'])
endTime = self.milli_to_srt(introduration + caption['startTime']
+ caption['duration'])
srtContent += ''.join([str(captionIndex), os.linesep, startTime,
' --> ', endTime, os.linesep,
caption['content'], os.linesep * 2])

View File

@ -104,8 +104,8 @@ def get_expired_episodes(channels, config):
continue
# Download strategy "Only keep latest"
if (channel.download_strategy == channel.STRATEGY_LATEST and
index > 0):
if (channel.download_strategy == channel.STRATEGY_LATEST
and index > 0):
logger.info('Removing episode (only keep latest strategy): %s',
episode.title)
yield episode

View File

@ -333,11 +333,11 @@ class ExtensionManager(object):
logger.debug('Found extension "%s" in %s', name, filename)
config = getattr(core.config.extensions, name)
container = ExtensionContainer(self, name, config, filename)
if (name in enabled_extensions or
container.metadata.mandatory_in_current_ui):
if (name in enabled_extensions
or container.metadata.mandatory_in_current_ui):
container.set_enabled(True)
if (name in enabled_extensions and
container.metadata.disable_in_current_ui):
if (name in enabled_extensions
and container.metadata.disable_in_current_ui):
container.set_enabled(False)
self.containers.append(container)
@ -390,9 +390,9 @@ class ExtensionManager(object):
def get_extensions(self):
"""Get a list of all loaded extensions and their enabled flag"""
return [c for c in self.containers
if c.metadata.available_for_current_ui and
not c.metadata.mandatory_in_current_ui and
not c.metadata.disable_in_current_ui]
if c.metadata.available_for_current_ui
and not c.metadata.mandatory_in_current_ui
and not c.metadata.disable_in_current_ui]
# Define all known handler functions here, decorate them with the
# "call_extension" decorator to forward all calls to extension scripts that have

View File

@ -92,11 +92,11 @@ class OnSyncActionList(Gtk.ListStore):
def get_index(self):
for index, row in enumerate(self):
if (self._config.device_sync.after_sync.delete_episodes and
row[self.C_ON_SYNC_DELETE]):
if (self._config.device_sync.after_sync.delete_episodes
and row[self.C_ON_SYNC_DELETE]):
return index
if (self._config.device_sync.after_sync.mark_episodes_played and
row[self.C_ON_SYNC_MARK_PLAYED] and not
if (self._config.device_sync.after_sync.mark_episodes_played
and row[self.C_ON_SYNC_MARK_PLAYED] and not
self._config.device_sync.after_sync.delete_episodes):
return index
return 0 # Some sane default

View File

@ -74,8 +74,8 @@ class gPodderConfigEditor(BuilderWidget):
return True
else:
# either the variable name or its value
return (text in model.get_value(iter, 0).lower() or
text in model.get_value(iter, 2).lower())
return (text in model.get_value(iter, 0).lower()
or text in model.get_value(iter, 2).lower())
def value_edited(self, renderer, path, new_text):
model = self.configeditor.get_model()

View File

@ -496,8 +496,8 @@ class gPodder(BuilderWidget, dbus.service.Object):
# Assume the episode's total time for the action
total = episode.total_time
assert (episode.current_position_updated is None or
now >= episode.current_position_updated)
assert (episode.current_position_updated is None
or now >= episode.current_position_updated)
episode.current_position = end
episode.current_position_updated = now
@ -649,8 +649,8 @@ class gPodder(BuilderWidget, dbus.service.Object):
path, column, x, y = result
# The user clicked the icon if she clicked in the first column
# and the x position is in the area where the icon resides
if (x < self.EPISODE_LIST_ICON_WIDTH and
column == treeview.get_columns()[0]):
if (x < self.EPISODE_LIST_ICON_WIDTH
and column == treeview.get_columns()[0]):
model = treeview.get_model()
cursor_episode = model.get_value(model.get_iter(path),
EpisodeListModel.C_EPISODE)
@ -841,8 +841,8 @@ class gPodder(BuilderWidget, dbus.service.Object):
# Initialize progress icons
cake_size = cake_size_from_widget(self.treeAvailable)
for i in range(EpisodeListModel.PROGRESS_STEPS + 1):
pixbuf = draw_cake_pixbuf(i /
EpisodeListModel.PROGRESS_STEPS, size=cake_size)
pixbuf = draw_cake_pixbuf(
i / EpisodeListModel.PROGRESS_STEPS, size=cake_size)
icon_name = 'gpodder-progress-%d' % i
Gtk.IconTheme.add_builtin_icon(icon_name, cake_size, pixbuf)
@ -1443,14 +1443,14 @@ class gPodder(BuilderWidget, dbus.service.Object):
selection = treeview.get_selection()
model, paths = selection.get_selected_rows()
if path is None or (path not in paths and
event.button == 3):
if path is None or (path not in paths
and event.button == 3):
# We have right-clicked, but not into the selection,
# assume we don't want to operate on the selection
paths = []
if (path is not None and not paths and
event.button == 3):
if (path is not None and not paths
and event.button == 3):
# No selection or clicked outside selection;
# select the single item where we clicked
treeview.grab_focus()
@ -2440,8 +2440,8 @@ class gPodder(BuilderWidget, dbus.service.Object):
else:
list_model_length = len(self.podcast_list_model)
force_update = (sections_active != self.config.podcast_list_sections or
sections_changed)
force_update = (sections_active != self.config.podcast_list_sections
or sections_changed)
# Filter items in the list model that are not podcasts, so we get the
# correct podcast list count (ignore section headers and separators)
@ -2914,8 +2914,8 @@ class gPodder(BuilderWidget, dbus.service.Object):
count) % {'count': count}
self.show_message(title, _('New episodes available'))
else:
if (show_new_episodes_dialog and
self.config.auto_download == 'show'):
if (show_new_episodes_dialog
and self.config.auto_download == 'show'):
self.new_episodes_show(episodes, notification=True)
else: # !show_new_episodes_dialog or auto_download == 'ignore'
message = N_('%(count)d new episode available',
@ -3771,8 +3771,8 @@ class gPodder(BuilderWidget, dbus.service.Object):
GLib.source_remove(self._auto_update_timer_source_id)
self._auto_update_timer_source_id = None
if (self.config.auto_update_feeds and
self.config.auto_update_frequency):
if (self.config.auto_update_feeds
and self.config.auto_update_frequency):
interval = 60 * 1000 * self.config.auto_update_frequency
logger.debug('Setting up auto update timer with interval %d.',
self.config.auto_update_frequency)
@ -3922,8 +3922,8 @@ class gPodder(BuilderWidget, dbus.service.Object):
try:
file.mount_enclosing_volume_finish(res)
except GLib.Error as err:
if (not err.matches(Gio.io_error_quark(), Gio.IOErrorEnum.NOT_SUPPORTED) and
not err.matches(Gio.io_error_quark(), Gio.IOErrorEnum.ALREADY_MOUNTED)):
if (not err.matches(Gio.io_error_quark(), Gio.IOErrorEnum.NOT_SUPPORTED)
and not err.matches(Gio.io_error_quark(), Gio.IOErrorEnum.ALREADY_MOUNTED)):
logger.error('mounting volume %s failed: %s' % (file.get_uri(), err.message))
result = False
finally:

View File

@ -64,8 +64,8 @@ class GEpisode(model.PodcastEpisode):
length_str = '%s; ' % util.format_filesize(self.file_size)
else:
length_str = ''
return ('<b>%s</b>\n<small>%s' + _('released %s') +
'; ' + _('from %s') + '</small>') % (
return ('<b>%s</b>\n<small>%s' + _('released %s')
+ '; ' + _('from %s') + '</small>') % (
html.escape(re.sub(r'\s+', ' ', self.title)),
html.escape(length_str),
html.escape(self.pubdate_prop),
@ -82,8 +82,8 @@ class GEpisode(model.PodcastEpisode):
downloaded_string = self.get_age_string()
if not downloaded_string:
downloaded_string = _('today')
return ('<b>%s</b>\n<small>%s; %s; ' + _('downloaded %s') +
'; ' + _('from %s') + '</small>') % (
return ('<b>%s</b>\n<small>%s; %s; ' + _('downloaded %s')
+ '; ' + _('from %s') + '</small>') % (
html.escape(self.title),
html.escape(util.format_filesize(self.file_size)),
html.escape(played_string),
@ -459,8 +459,8 @@ class EpisodeListModel(Gtk.ListStore):
tooltip.append(_('deletion prevented'))
if episode.total_time > 0 and episode.current_position:
tooltip.append('%d%%' % (100. * float(episode.current_position) /
float(episode.total_time),))
tooltip.append('%d%%' % (
100. * float(episode.current_position) / float(episode.total_time)))
elif episode._download_error is not None:
tooltip.append(_('ERROR: %s') % episode._download_error)
status_icon = self.ICON_ERROR

View File

@ -282,8 +282,8 @@ class PodcastEpisode(PodcastModelObject):
is_locked = property(fget=_deprecated, fset=_deprecated)
def has_website_link(self):
return bool(self.link) and (self.link != self.url or
youtube.is_video_link(self.link))
return bool(self.link) and (self.link != self.url
or youtube.is_video_link(self.link))
@classmethod
def from_podcastparser_entry(cls, entry, channel):
@ -417,8 +417,8 @@ class PodcastEpisode(PodcastModelObject):
# "Podcast Name - Title" and "Podcast Name: Title" -> "Title"
for postfix in (' - ', ': '):
prefix = self.parent.title + postfix
if (self.title.startswith(prefix) and
len(self.title) - len(prefix) > LEFTOVER_MIN):
if (self.title.startswith(prefix)
and len(self.title) - len(prefix) > LEFTOVER_MIN):
return self.title[len(prefix):]
regex_patterns = [
@ -437,14 +437,14 @@ class PodcastEpisode(PodcastModelObject):
# "#001: Title" -> "001: Title"
if (
not self.parent._common_prefix and
re.match(r'^#\d+: ', self.title) and
len(self.title) - 1 > LEFTOVER_MIN):
not self.parent._common_prefix
and re.match(r'^#\d+: ', self.title)
and len(self.title) - 1 > LEFTOVER_MIN):
return self.title[1:]
if (self.parent._common_prefix is not None and
self.title.startswith(self.parent._common_prefix) and
len(self.title) - len(self.parent._common_prefix) > LEFTOVER_MIN):
if (self.parent._common_prefix is not None
and self.title.startswith(self.parent._common_prefix)
and len(self.title) - len(self.parent._common_prefix) > LEFTOVER_MIN):
return self.title[len(self.parent._common_prefix):]
return self.title
@ -535,8 +535,8 @@ class PodcastEpisode(PodcastModelObject):
return self.state != gpodder.STATE_DELETED or self.archive
def check_is_new(self):
return (self.state == gpodder.STATE_NORMAL and self.is_new and
not self.downloading)
return (self.state == gpodder.STATE_NORMAL and self.is_new
and not self.downloading)
def save(self):
gpodder.user_extensions.on_episode_save(self)
@ -642,8 +642,8 @@ class PodcastEpisode(PodcastModelObject):
filename = filename.strip('.' + string.whitespace) + extension
for name in util.generate_names(filename):
if (not self.db.episode_filename_exists(self.podcast_id, name) or
self.download_filename == name):
if (not self.db.episode_filename_exists(self.podcast_id, name)
or self.download_filename == name):
return name
def local_filename(self, create, force_update=False, check_only=False,
@ -706,9 +706,9 @@ class PodcastEpisode(PodcastModelObject):
episode_filename, _ = util.filename_from_url(url)
# Use title for YouTube, Vimeo and Soundcloud downloads
if (youtube.is_video_link(self.url) or
vimeo.is_video_link(self.url) or
episode_filename == 'stream'):
if (youtube.is_video_link(self.url)
or vimeo.is_video_link(self.url)
or episode_filename == 'stream'):
episode_filename = self.title
# If the basename is empty, use the md5 hexdigest of the URL
@ -865,9 +865,10 @@ class PodcastEpisode(PodcastModelObject):
current position is greater than 99 percent of the
total time or inside the last 10 seconds of a track.
"""
return (self.current_position > 0 and self.total_time > 0 and
(self.current_position + 10 >= self.total_time or
self.current_position >= self.total_time * .99))
return (self.current_position > 0
and self.total_time > 0
and (self.current_position + 10 >= self.total_time
or self.current_position >= self.total_time * .99))
def get_play_info_string(self, duration_only=False):
duration = util.format_time(self.total_time)
@ -1016,8 +1017,8 @@ class PodcastChannel(PodcastModelObject):
ignore_files = ['folder' + ext for ext in
coverart.CoverDownloader.EXTENSIONS]
external_files = existing_files.difference(list(known_files) +
[os.path.join(self.save_dir, ignore_file)
external_files = existing_files.difference(list(known_files)
+ [os.path.join(self.save_dir, ignore_file)
for ignore_file in ignore_files])
if not external_files:
return
@ -1228,8 +1229,8 @@ class PodcastChannel(PodcastModelObject):
real_new_episode_count += 1
# Only allow a certain number of new episodes per update
if (self.download_strategy == PodcastChannel.STRATEGY_LATEST and
real_new_episode_count > 1):
if (self.download_strategy == PodcastChannel.STRATEGY_LATEST
and real_new_episode_count > 1):
episode.is_new = False
episode.save()
@ -1243,8 +1244,8 @@ class PodcastChannel(PodcastModelObject):
# Keep episodes that are currently being downloaded, though (bug 1534)
if self.id is not None:
episodes_to_purge = [e for e in existing if
e.state != gpodder.STATE_DOWNLOADED and
e.guid not in seen_guids and not e.downloading]
e.state != gpodder.STATE_DOWNLOADED
and e.guid not in seen_guids and not e.downloading]
for episode in episodes_to_purge:
logger.debug('Episode removed from feed: %s (%s)',
@ -1415,8 +1416,8 @@ class PodcastChannel(PodcastModelObject):
download_folder = download_folder.strip('.' + string.whitespace)
for folder_name in util.generate_names(download_folder):
if (not self.db.podcast_download_folder_exists(folder_name) or
self.download_folder == folder_name):
if (not self.db.podcast_download_folder_exists(folder_name)
or self.download_folder == folder_name):
return folder_name
def get_save_dir(self, force_new=False):

View File

@ -254,8 +254,8 @@ class MygPoClient(object):
logger.debug('Play action for %s', episode.url)
episode.mark(is_played=True)
if (action.timestamp > episode.current_position_updated and
action.position is not None):
if (action.timestamp > episode.current_position_updated
and action.position is not None):
logger.debug('Updating position for %s', episode.url)
episode.current_position = action.position
episode.current_position_updated = action.timestamp

View File

@ -221,8 +221,8 @@ class Device(services.ObservableService):
for track in list(tracklist):
# Filter tracks that are not meant to be synchronized
does_not_exist = not track.was_downloaded(and_exists=True)
exclude_played = (not track.is_new and
self._config.device_sync.skip_played_episodes)
exclude_played = (not track.is_new
and self._config.device_sync.skip_played_episodes)
wrong_type = track.file_type() not in self.allowed_types
if does_not_exist:
@ -347,8 +347,8 @@ class iPodDevice(Device):
def episode_on_device(self, episode):
return next((track for track in self.tracks_list
if track.ipod_track.podcast_rss == episode.channel.url and
track.ipod_track.podcast_url == episode.url), None)
if track.ipod_track.podcast_rss == episode.channel.url
and track.ipod_track.podcast_url == episode.url), None)
def remove_track(self, track):
self.notify('status', _('Removing %s') % track.title)
@ -444,8 +444,8 @@ class MP3PlayerDevice(Device):
try:
info = self.destination.query_info(
Gio.FILE_ATTRIBUTE_ACCESS_CAN_WRITE + "," +
Gio.FILE_ATTRIBUTE_STANDARD_TYPE,
Gio.FILE_ATTRIBUTE_ACCESS_CAN_WRITE + ","
+ Gio.FILE_ATTRIBUTE_STANDARD_TYPE,
Gio.FileQueryInfoFlags.NONE,
None)
except GLib.Error as err:
@ -460,8 +460,8 @@ class MP3PlayerDevice(Device):
# open is ok if the target is a directory, and it can be written to
# for smb, query_info doesn't return FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
# -- if that's the case, just assume that it's writable
if (not info.has_attribute(Gio.FILE_ATTRIBUTE_ACCESS_CAN_WRITE) or
info.get_attribute_boolean(Gio.FILE_ATTRIBUTE_ACCESS_CAN_WRITE)):
if (not info.has_attribute(Gio.FILE_ATTRIBUTE_ACCESS_CAN_WRITE)
or info.get_attribute_boolean(Gio.FILE_ATTRIBUTE_ACCESS_CAN_WRITE)):
self.notify('status', _('MP3 player opened'))
self.tracks_list = self.get_all_tracks()
return True
@ -558,10 +558,10 @@ class MP3PlayerDevice(Device):
tracks = []
attributes = (
Gio.FILE_ATTRIBUTE_STANDARD_NAME + "," +
Gio.FILE_ATTRIBUTE_STANDARD_TYPE + "," +
Gio.FILE_ATTRIBUTE_STANDARD_SIZE + "," +
Gio.FILE_ATTRIBUTE_TIME_MODIFIED)
Gio.FILE_ATTRIBUTE_STANDARD_NAME + ","
+ Gio.FILE_ATTRIBUTE_STANDARD_TYPE + ","
+ Gio.FILE_ATTRIBUTE_STANDARD_SIZE + ","
+ Gio.FILE_ATTRIBUTE_TIME_MODIFIED)
root_path = self.destination
for path_info in root_path.enumerate_children(attributes, Gio.FileQueryInfoFlags.NONE, None):

View File

@ -79,8 +79,8 @@ class gPodderSyncUI(object):
continue
for episode in channel.get_all_episodes():
if (episode.was_downloaded(and_exists=True) or
not only_downloaded):
if (episode.was_downloaded(and_exists=True)
or not only_downloaded):
episodes.append(episode)
return episodes
@ -133,8 +133,8 @@ class gPodderSyncUI(object):
return False
# Might not be synced if it's played already
if (not force_played and
self._config.device_sync.skip_played_episodes):
if (not force_played
and self._config.device_sync.skip_played_episodes):
return False
# In all other cases, we expect the episode to be
@ -316,9 +316,9 @@ class gPodderSyncUI(object):
def cleanup_episodes():
# 'skip_played_episodes' must be used or else all the
# played tracks will be copied then immediately deleted
if (self._config.device_sync.delete_deleted_episodes or
(self._config.device_sync.delete_played_episodes and
self._config.device_sync.skip_played_episodes)):
if (self._config.device_sync.delete_deleted_episodes
or (self._config.device_sync.delete_played_episodes
and self._config.device_sync.skip_played_episodes)):
all_episodes = self._filter_sync_episodes(
channels, only_downloaded=False)
for local_episode in all_episodes:

View File

@ -2350,8 +2350,8 @@ def mount_volume_for_file(file, op=None):
file.mount_enclosing_volume_finish(res)
result = True
except GLib.Error as err:
if (not err.matches(Gio.io_error_quark(), Gio.IOErrorEnum.NOT_SUPPORTED) and
not err.matches(Gio.io_error_quark(), Gio.IOErrorEnum.ALREADY_MOUNTED)):
if (not err.matches(Gio.io_error_quark(), Gio.IOErrorEnum.NOT_SUPPORTED)
and not err.matches(Gio.io_error_quark(), Gio.IOErrorEnum.ALREADY_MOUNTED)):
message = err.message
result = False
finally:

View File

@ -32,9 +32,9 @@ class MakeCertPem:
"""
cmd = ["security", "find-certificate", "-a", "-p",
"/System/Library/Keychains/SystemRootCertificates.keychain"]
cert_re = re.compile(b"^-----BEGIN CERTIFICATE-----$" +
b".+?" +
b"^-----END CERTIFICATE-----$", re.M | re.S)
cert_re = re.compile(b"^-----BEGIN CERTIFICATE-----$"
+ b".+?"
+ b"^-----END CERTIFICATE-----$", re.M | re.S)
try:
certs_str = subprocess.check_output(cmd)
all_certs = cert_re.findall(certs_str)

View File

@ -32,9 +32,9 @@ def get_certs(openssl):
cmd = ["security", "find-certificate", "-a", "-p",
"/System/Library/Keychains/SystemRootCertificates.keychain"]
cert_re = re.compile(b"^-----BEGIN CERTIFICATE-----$" +
b".+?" +
b"^-----END CERTIFICATE-----$", re.M | re.S)
cert_re = re.compile(b"^-----BEGIN CERTIFICATE-----$"
+ b".+?"
+ b"^-----END CERTIFICATE-----$", re.M | re.S)
try:
certs_str = subprocess.check_output(cmd)
all_certs = cert_re.findall(certs_str)