fix E201 whitespace after '('

This commit is contained in:
MarkusHackspacher 2018-05-21 21:40:40 +02:00
parent adad95494f
commit bfa93465d3
6 changed files with 105 additions and 88 deletions

View File

@ -156,11 +156,11 @@ def get_escapist_real_url(data, config_json):
one_hash = config_data["hash"]
# Turn the string into numbers
hash_n = [ ord(x) for x in one_hash ]
hash_n = [ord(x) for x in one_hash]
# Split the data into 2char strings
hex_hashes = [ data[x:(x + 2)] for x in range(0,len(data),2) ]
hex_hashes = [data[x:(x + 2)] for x in range(0, len(data), 2)]
# Turn the strings into numbers, considering the hex value
num_hashes = [ int(h, 16) for h in hex_hashes ]
num_hashes = [int(h, 16) for h in hex_hashes]
# Characters again, from the value
# str_hashes = [ unichr(n) for n in num_hashes ]

View File

@ -36,8 +36,8 @@ class gPodderChannel(BuilderWidget):
def new(self):
self.show_on_cover_load = True
self.gPodderChannel.set_title( self.channel.title)
self.entryTitle.set_text( self.channel.title)
self.gPodderChannel.set_title(self.channel.title)
self.entryTitle.set_text(self.channel.title)
self.labelURL.set_text(self.channel.url)
self.cbSkipFeedUpdate.set_active(self.channel.pause_subscription)
self.cbEnableDeviceSync.set_active(self.channel.sync_to_mp3_player)
@ -67,13 +67,13 @@ class gPodderChannel(BuilderWidget):
self.combo_strategy.add_attribute(cell_renderer, 'text', 0)
self.combo_strategy.set_active(active_index)
self.LabelDownloadTo.set_text( self.channel.save_dir)
self.LabelWebsite.set_text( self.channel.link)
self.LabelDownloadTo.set_text(self.channel.save_dir)
self.LabelWebsite.set_text(self.channel.link)
if self.channel.auth_username:
self.FeedUsername.set_text( self.channel.auth_username)
self.FeedUsername.set_text(self.channel.auth_username)
if self.channel.auth_password:
self.FeedPassword.set_text( self.channel.auth_password)
self.FeedPassword.set_text(self.channel.auth_password)
self.cover_downloader.register('cover-available', self.cover_download_finished)
self.cover_downloader.request_cover(self.channel)
@ -83,8 +83,8 @@ class gPodderChannel(BuilderWidget):
self.btn_website.hide()
b = Gtk.TextBuffer()
b.set_text( self.channel.description)
self.channel_description.set_buffer( b)
b.set_text(self.channel.description)
self.channel_description.set_buffer(b)
# Add Drag and Drop Support
flags = Gtk.DestDefaults.ALL
@ -133,7 +133,10 @@ class gPodderChannel(BuilderWidget):
util.open_website(self.channel.link)
def on_btnDownloadCover_clicked(self, widget):
dlg = Gtk.FileChooserDialog(title=_('Select new podcast cover artwork'), parent=self.gPodderChannel, action=Gtk.FileChooserAction.OPEN)
dlg = Gtk.FileChooserDialog(
title=_('Select new podcast cover artwork'),
parent=self.gPodderChannel,
action=Gtk.FileChooserAction.OPEN)
dlg.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
dlg.add_button(Gtk.STOCK_OPEN, Gtk.ResponseType.OK)
@ -159,10 +162,12 @@ class gPodderChannel(BuilderWidget):
util.idle_add(set_cover, channel, pixbuf)
def drag_data_received( self, widget, content, x, y, sel, ttype, time):
def drag_data_received(self, widget, content, x, y, sel, ttype, time):
files = sel.data.strip().split('\n')
if len(files) != 1:
self.show_message( _('You can only drop a single image or URL here.'), _('Drag and drop'))
self.show_message(
_('You can only drop a single image or URL here.'),
_('Drag and drop'))
return
file = files[0]
@ -172,7 +177,9 @@ class gPodderChannel(BuilderWidget):
self.cover_downloader.replace_cover(self.channel, custom_url=file)
return
self.show_message( _('You can only drop local files and http:// URLs here.'), _('Drag and drop'))
self.show_message(
_('You can only drop local files and http:// URLs here.'),
_('Drag and drop'))
def on_gPodderChannel_destroy(self, widget, *args):
self.cover_downloader.unregister('cover-available', self.cover_download_finished)

View File

@ -92,9 +92,9 @@ class gPodderEpisodeSelector(BuilderWidget):
COLUMN_TOGGLE = 2
COLUMN_ADDITIONAL = 3
def new( self):
def new(self):
self._config.connect_gtk_window(self.gPodderEpisodeSelector, 'episode_selector', True)
if not hasattr( self, 'callback'):
if not hasattr(self, 'callback'):
self.callback = None
if not hasattr(self, 'remove_callback'):
@ -106,35 +106,35 @@ class gPodderEpisodeSelector(BuilderWidget):
if not hasattr(self, 'remove_finished'):
self.remove_finished = None
if not hasattr( self, 'episodes'):
if not hasattr(self, 'episodes'):
self.episodes = []
if not hasattr( self, 'size_attribute'):
if not hasattr(self, 'size_attribute'):
self.size_attribute = 'file_size'
if not hasattr(self, 'tooltip_attribute'):
self.tooltip_attribute = 'description'
if not hasattr( self, 'selection_buttons'):
if not hasattr(self, 'selection_buttons'):
self.selection_buttons = {}
if not hasattr( self, 'selected_default'):
if not hasattr(self, 'selected_default'):
self.selected_default = False
if not hasattr( self, 'selected'):
if not hasattr(self, 'selected'):
self.selected = [self.selected_default] * len(self.episodes)
if len(self.selected) < len(self.episodes):
self.selected += [self.selected_default] * (len(self.episodes) - len(self.selected))
if not hasattr( self, 'columns'):
if not hasattr(self, 'columns'):
self.columns = (('title_markup', None, None, _('Episode')),)
if hasattr(self, 'title'):
self.gPodderEpisodeSelector.set_title(self.title)
if hasattr( self, 'instructions'):
self.labelInstructions.set_text( self.instructions)
if hasattr(self, 'instructions'):
self.labelInstructions.set_text(self.instructions)
self.labelInstructions.show_all()
if hasattr(self, 'stock_ok_button'):
@ -147,7 +147,7 @@ class gPodderEpisodeSelector(BuilderWidget):
# check/uncheck column
toggle_cell = Gtk.CellRendererToggle()
toggle_cell.connect( 'toggled', self.toggle_cell_handler)
toggle_cell.connect('toggled', self.toggle_cell_handler)
toggle_column = Gtk.TreeViewColumn('', toggle_cell, active=self.COLUMN_TOGGLE)
toggle_column.set_clickable(True)
self.treeviewEpisodes.append_column(toggle_column)
@ -159,7 +159,7 @@ class gPodderEpisodeSelector(BuilderWidget):
renderer.set_property('ellipsize', Pango.EllipsizeMode.END)
column = Gtk.TreeViewColumn(caption, renderer, markup=next_column)
column.set_clickable(False)
column.set_resizable( True)
column.set_resizable(True)
# Only set "expand" on the first column
if next_column < self.COLUMN_ADDITIONAL + 1:
column.set_expand(True)
@ -167,7 +167,7 @@ class gPodderEpisodeSelector(BuilderWidget):
column.set_sort_column_id(next_column + 1)
else:
column.set_sort_column_id(next_column)
self.treeviewEpisodes.append_column( column)
self.treeviewEpisodes.append_column(column)
next_column += 1
if sort_name is not None:
@ -175,37 +175,37 @@ class gPodderEpisodeSelector(BuilderWidget):
column = Gtk.TreeViewColumn()
column.set_clickable(False)
column.set_visible(False)
self.treeviewEpisodes.append_column( column)
self.treeviewEpisodes.append_column(column)
next_column += 1
column_types = [ int, str, bool ]
column_types = [int, str, bool]
# add string column type plus sort column type if it exists
for name, sort_name, sort_type, caption in self.columns:
column_types.append(str)
if sort_name is not None:
column_types.append(sort_type)
self.model = Gtk.ListStore( *column_types)
self.model = Gtk.ListStore(*column_types)
tooltip = None
for index, episode in enumerate( self.episodes):
for index, episode in enumerate(self.episodes):
if self.tooltip_attribute is not None:
try:
tooltip = getattr(episode, self.tooltip_attribute)
except:
tooltip = None
row = [ index, tooltip, self.selected[index] ]
row = [index, tooltip, self.selected[index]]
for name, sort_name, sort_type, caption in self.columns:
if not hasattr(episode, name):
row.append(None)
else:
row.append(getattr( episode, name))
row.append(getattr(episode, name))
if sort_name is not None:
if not hasattr(episode, sort_name):
row.append(None)
else:
row.append(getattr( episode, sort_name))
self.model.append( row)
row.append(getattr(episode, sort_name))
self.model.append(row)
if self.remove_callback is not None:
self.btnRemoveAction.show()
@ -223,8 +223,8 @@ class gPodderEpisodeSelector(BuilderWidget):
self.treeviewEpisodes.connect('button-press-event', self.treeview_episodes_button_pressed)
self.treeviewEpisodes.connect('popup-menu', self.treeview_episodes_button_pressed)
self.treeviewEpisodes.set_rules_hint( True)
self.treeviewEpisodes.set_model( self.model)
self.treeviewEpisodes.set_rules_hint(True)
self.treeviewEpisodes.set_model(self.model)
self.treeviewEpisodes.columns_autosize()
# Focus the toggle column for Tab-focusing (bug 503)
@ -308,12 +308,12 @@ class gPodderEpisodeSelector(BuilderWidget):
def episode_list_allow_tooltips(self):
self.episode_list_can_tooltip = True
def calculate_total_size( self):
def calculate_total_size(self):
if self.size_attribute is not None:
(total_size, count) = (0, 0)
for episode in self.get_selected_episodes():
try:
total_size += int(getattr( episode, self.size_attribute))
total_size += int(getattr(episode, self.size_attribute))
count += 1
except:
pass
@ -341,7 +341,7 @@ class gPodderEpisodeSelector(BuilderWidget):
break
self.labelTotalSize.set_text('')
def toggle_cell_handler( self, cell, path):
def toggle_cell_handler(self, cell, path):
model = self.treeviewEpisodes.get_model()
model[path][self.COLUMN_TOGGLE] = not model[path][self.COLUMN_TOGGLE]
@ -350,21 +350,21 @@ class gPodderEpisodeSelector(BuilderWidget):
def custom_selection_button_clicked(self, button, label):
callback = self.selection_buttons[label]
for index, row in enumerate( self.model):
new_value = callback( self.episodes[index])
self.model.set_value( row.iter, self.COLUMN_TOGGLE, new_value)
for index, row in enumerate(self.model):
new_value = callback(self.episodes[index])
self.model.set_value(row.iter, self.COLUMN_TOGGLE, new_value)
self.calculate_total_size()
def on_btnCheckAll_clicked( self, widget):
def on_btnCheckAll_clicked(self, widget):
for row in self.model:
self.model.set_value( row.iter, self.COLUMN_TOGGLE, True)
self.model.set_value(row.iter, self.COLUMN_TOGGLE, True)
self.calculate_total_size()
def on_btnCheckNone_clicked( self, widget):
def on_btnCheckNone_clicked(self, widget):
for row in self.model:
self.model.set_value( row.iter, self.COLUMN_TOGGLE, False)
self.model.set_value(row.iter, self.COLUMN_TOGGLE, False)
self.calculate_total_size()
@ -393,12 +393,13 @@ class gPodderEpisodeSelector(BuilderWidget):
self.calculate_total_size()
def get_selected_episodes( self, remove_episodes=False):
def get_selected_episodes(self, remove_episodes=False):
selected_episodes = []
for index, row in enumerate( self.model):
if self.model.get_value( row.iter, self.COLUMN_TOGGLE) is True:
selected_episodes.append( self.episodes[self.model.get_value( row.iter, self.COLUMN_INDEX)])
for index, row in enumerate(self.model):
if self.model.get_value(row.iter, self.COLUMN_TOGGLE) is True:
selected_episodes.append(self.episodes[self.model.get_value(
row.iter, self.COLUMN_INDEX)])
if remove_episodes:
for episode in selected_episodes:
@ -412,12 +413,12 @@ class gPodderEpisodeSelector(BuilderWidget):
return selected_episodes
def on_btnOK_clicked( self, widget):
def on_btnOK_clicked(self, widget):
self.gPodderEpisodeSelector.destroy()
if self.callback is not None:
self.callback( self.get_selected_episodes())
self.callback(self.get_selected_episodes())
def on_btnCancel_clicked( self, widget):
def on_btnCancel_clicked(self, widget):
self.gPodderEpisodeSelector.destroy()
if self.callback is not None:
self.callback([])

View File

@ -44,7 +44,9 @@ import logging
logger = logging.getLogger(__name__)
# where are the .desktop files located?
userappsdirs = [ '/usr/share/applications/', '/usr/local/share/applications/', '/usr/share/applications/kde/' ]
userappsdirs = ['/usr/share/applications/',
'/usr/local/share/applications/',
'/usr/share/applications/kde/']
# the name of the section in the .desktop files
sect = 'Desktop Entry'
@ -153,13 +155,18 @@ class UserAppsReader(object):
self.__has_read = False
self.__finished = threading.Event()
self.__has_sep = False
self.apps.append(UserApplication(_('Default application'), 'default', ';'.join((mime + '/*' for mime in self.mimetypes)), Gtk.STOCK_OPEN))
self.apps.append(UserApplication(
_('Default application'), 'default',
';'.join((mime + '/*' for mime in self.mimetypes)),
Gtk.STOCK_OPEN))
def add_separator(self):
self.apps.append(UserApplication('', '', ';'.join((mime + '/*' for mime in self.mimetypes)), ''))
self.apps.append(UserApplication(
'', '',
';'.join((mime + '/*' for mime in self.mimetypes)), ''))
self.__has_sep = True
def read( self):
def read(self):
if self.__has_read:
return
@ -169,17 +176,19 @@ class UserAppsReader(object):
for caption, types, hkey in WIN32_APP_REG_KEYS:
try:
cmdline = win32_read_registry_key(hkey)
self.apps.append(UserApplication(caption, cmdline, ';'.join(typ + '/*' for typ in types), None))
self.apps.append(UserApplication(
caption, cmdline,
';'.join(typ + '/*' for typ in types), None))
except Exception as e:
logger.warn('Parse HKEY error: %s (%s)', hkey, e)
for dir in userappsdirs:
if os.path.exists( dir):
if os.path.exists(dir):
for file in glob.glob(os.path.join(dir, '*.desktop')):
self.parse_and_append( file)
self.parse_and_append(file)
self.__finished.set()
def parse_and_append( self, filename):
def parse_and_append(self, filename):
try:
parser = RawConfigParser()
parser.read([filename])

View File

@ -61,7 +61,7 @@ class Importer(object):
VALID_TYPES = ('rss', 'link')
def __init__( self, url):
def __init__(self, url):
"""
Parses the OPML feed from the given URL into
a local data structure containing channel metadata.
@ -90,10 +90,10 @@ class Importer(object):
if channel['description'] == channel['title']:
channel['description'] = channel['url']
for attr in ( 'url', 'title', 'description' ):
for attr in ('url', 'title', 'description'):
channel[attr] = channel[attr].strip()
self.items.append( channel)
self.items.append(channel)
if not len(self.items):
logger.info('OPML import finished, but no items found: %s', url)
except:
@ -110,37 +110,37 @@ class Exporter(object):
FEED_TYPE = 'rss'
def __init__( self, filename):
def __init__(self, filename):
if filename is None:
self.filename = None
elif filename.endswith( '.opml') or filename.endswith( '.xml'):
elif filename.endswith('.opml') or filename.endswith('.xml'):
self.filename = filename
else:
self.filename = '%s.opml' % ( filename, )
self.filename = '%s.opml' % (filename, )
def create_node( self, doc, name, content):
def create_node(self, doc, name, content):
"""
Creates a simple XML Element node in a document
with tag name "name" and text content "content",
as in <name>content</name> and returns the element.
"""
node = doc.createElement( name)
node.appendChild( doc.createTextNode( content))
node = doc.createElement(name)
node.appendChild(doc.createTextNode(content))
return node
def create_outline( self, doc, channel):
def create_outline(self, doc, channel):
"""
Creates a OPML outline as XML Element node in a
document for the supplied channel.
"""
outline = doc.createElement( 'outline')
outline.setAttribute( 'title', channel.title)
outline.setAttribute( 'text', channel.description)
outline.setAttribute( 'xmlUrl', channel.url)
outline.setAttribute( 'type', self.FEED_TYPE)
outline = doc.createElement('outline')
outline.setAttribute('title', channel.title)
outline.setAttribute('text', channel.description)
outline.setAttribute('xmlUrl', channel.url)
outline.setAttribute('type', self.FEED_TYPE)
return outline
def write( self, channels):
def write(self, channels):
"""
Creates a XML document containing metadata for each
channel object in the "channels" parameter, which
@ -160,15 +160,15 @@ class Exporter(object):
opml.setAttribute('version', '2.0')
doc.appendChild(opml)
head = doc.createElement( 'head')
head.appendChild( self.create_node( doc, 'title', 'gPodder subscriptions'))
head.appendChild( self.create_node( doc, 'dateCreated', formatdate(localtime=True)))
opml.appendChild( head)
head = doc.createElement('head')
head.appendChild(self.create_node(doc, 'title', 'gPodder subscriptions'))
head.appendChild(self.create_node(doc, 'dateCreated', formatdate(localtime=True)))
opml.appendChild(head)
body = doc.createElement( 'body')
body = doc.createElement('body')
for channel in channels:
body.appendChild( self.create_outline( doc, channel))
opml.appendChild( body)
body.appendChild(self.create_outline(doc, channel))
opml.appendChild(body)
try:
data = doc.toprettyxml(encoding='utf-8', indent=' ', newl=os.linesep)

View File

@ -139,7 +139,7 @@ class SoundcloudUser(object):
global CONSUMER_KEY
try:
json_url = 'https://api.soundcloud.com/users/%(user)s/%(feed)s.json?filter=downloadable&consumer_key=%(consumer_key)s&limit=200' \
% { "user":self.get_user_id(), "feed":feed, "consumer_key": CONSUMER_KEY }
% {"user":self.get_user_id(), "feed":feed, "consumer_key": CONSUMER_KEY}
logger.debug("loading %s", json_url)
json_tracks = json.loads(util.urlopen(json_url).read().decode('utf-8'))
@ -158,7 +158,7 @@ class SoundcloudUser(object):
# Prefer stream URL (MP3), fallback to download URL
url = track.get('stream_url', track['download_url']) + \
'?consumer_key=%(consumer_key)s' \
% { 'consumer_key': CONSUMER_KEY }
% {'consumer_key': CONSUMER_KEY}
if url not in self.cache:
try:
self.cache[url] = get_metadata(url)