fix E226 missing whitespace around arithmetic operator

This commit is contained in:
MarkusHackspacher 2018-03-27 21:40:36 +02:00
parent 15617c5b39
commit a1e7e1dcbe
6 changed files with 52 additions and 52 deletions

View File

@ -176,7 +176,7 @@ class ContentRange(object):
if end is None:
return cls(start, None, length)
else:
return cls(start, end-1, length)
return cls(start, end - 1, length)
class DownloadCancelledException(Exception): pass
@ -289,10 +289,10 @@ class DownloadURLOpener(urllib.request.FancyURLopener):
logger.warn('Cannot resume: Invalid Content-Range (RFC2616).')
result = headers, fp.geturl()
bs = 1024*8
bs = 1024 * 8
size = -1
read = current_size
blocknum = current_size//bs
blocknum = current_size // bs
if reporthook:
if "content-length" in headers:
size = int(headers['Content-Length']) + current_size
@ -301,7 +301,7 @@ class DownloadURLOpener(urllib.request.FancyURLopener):
if size == -1:
block = fp.read(bs)
else:
block = fp.read(min(size-read, bs))
block = fp.read(min(size - read, bs))
if block == "":
break
read += len(block)
@ -602,7 +602,7 @@ class DownloadTask(object):
try:
already_downloaded = os.path.getsize(self.tempname)
if self.total_size > 0:
self.progress = max(0.0, min(1.0, already_downloaded/self.total_size))
self.progress = max(0.0, min(1.0, already_downloaded / self.total_size))
except OSError as os_error:
logger.error('Cannot get size for %s', os_error)
else:
@ -648,7 +648,7 @@ class DownloadTask(object):
self.__episode.save()
if self.total_size > 0:
self.progress = max(0.0, min(1.0, count*blockSize/self.total_size))
self.progress = max(0.0, min(1.0, count * blockSize / self.total_size))
if self._progress_updated is not None:
diff = time.time() - self._last_progress_updated
if diff > self.MIN_TIME_BETWEEN_UPDATES or self.progress == 1.:
@ -683,24 +683,24 @@ class DownloadTask(object):
passed = now - self.__start_time
if passed > 0:
speed = ((count-self.__start_blocks)*blockSize)/passed
speed = ((count - self.__start_blocks) * blockSize) / passed
else:
speed = 0
else:
self.__start_time = now
self.__start_blocks = count
passed = now - self.__start_time
speed = count*blockSize
speed = count * blockSize
self.speed = float(speed)
if self._config.limit_rate and speed > self._config.limit_rate_value:
# calculate the time that should have passed to reach
# the desired download rate and wait if necessary
should_have_passed = (count-self.__start_blocks)*blockSize/(self._config.limit_rate_value*1024.0)
should_have_passed = (count - self.__start_blocks) * blockSize / (self._config.limit_rate_value * 1024.0)
if should_have_passed > passed:
# sleep a maximum of 10 seconds to not cause time-outs
delay = min(10.0, float(should_have_passed-passed))
delay = min(10.0, float(should_have_passed - passed))
time.sleep(delay)
def recycle(self):

View File

@ -118,7 +118,7 @@ class Store(object):
used = [s for s in slots if getattr(child, s, None) is not None]
values = [self.convert(getattr(child, slot)) for slot in used]
self.db.execute('INSERT INTO %s (%s) VALUES (%s)' % (table,
', '.join(used), ', '.join('?'*len(used))), values)
', '.join(used), ', '.join('?' * len(used))), values)
return
with self.lock:
@ -127,7 +127,7 @@ class Store(object):
values = [self.convert(getattr(o, slot)) for slot in slots]
self.db.execute('INSERT INTO %s (%s) VALUES (%s)' % (table,
', '.join(slots), ', '.join('?'*len(slots))), values)
', '.join(slots), ', '.join('?' * len(slots))), values)
def delete(self, class_, **kwargs):
with self.lock:
@ -201,7 +201,7 @@ if __name__ == '__main__':
return '<Person "%s" (%d)>' % (self.username, self.id)
m = Store()
m.save(Person('User %d' % x, x*20) for x in range(50))
m.save(Person('User %d' % x, x * 20) for x in range(50))
p = m.get(Person, id=200)
print(p)
@ -209,7 +209,7 @@ if __name__ == '__main__':
p = m.get(Person, id=200)
# Remove some persons again (deletion by value!)
m.remove(Person('User %d' % x, x*20) for x in range(40))
m.remove(Person('User %d' % x, x * 20) for x in range(40))
class Person(object):
__slots__ = {'username': str, 'id': int, 'mail': str}
@ -223,5 +223,5 @@ if __name__ == '__main__':
return '<Person "%s" (%s)>' % (self.username, self.mail)
# A schema update takes place here
m.save(Person('User %d' % x, x*20, 'user@home.com') for x in range(50))
m.save(Person('User %d' % x, x * 20, 'user@home.com') for x in range(50))
print(m.load(Person))

View File

@ -251,7 +251,7 @@ class PodcastEpisode(PodcastModelObject):
for postfix in (' - ', ': '):
prefix = self.parent.title + postfix
if (self.title.startswith(prefix) and
len(self.title)-len(prefix) > LEFTOVER_MIN):
len(self.title) - len(prefix) > LEFTOVER_MIN):
return self.title[len(prefix):]
regex_patterns = [
@ -272,12 +272,12 @@ class PodcastEpisode(PodcastModelObject):
if (
not self.parent._common_prefix and
re.match('^#\d+: ', self.title) and
len(self.title)-1 > LEFTOVER_MIN):
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):
len(self.title) - len(self.parent._common_prefix) > LEFTOVER_MIN):
return self.title[len(self.parent._common_prefix):]
return self.title
@ -618,7 +618,7 @@ class PodcastEpisode(PodcastModelObject):
"""
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)
self.current_position >= self.total_time * .99)
def get_play_info_string(self, duration_only=False):
duration = util.format_time(self.total_time)
@ -655,7 +655,7 @@ class PodcastChannel(PodcastModelObject):
]
MAX_FOLDERNAME_LENGTH = 60
SECONDS_PER_WEEK = 7*24*60*60
SECONDS_PER_WEEK = 7 * 24 * 60 * 60
EpisodeClass = PodcastEpisode
feed_fetcher = gPodderFetcher()
@ -756,7 +756,7 @@ class PodcastChannel(PodcastModelObject):
glob.glob(os.path.join(self.save_dir, '*')) \
if not filename.endswith('.partial'))
ignore_files = ['folder'+ext for ext in
ignore_files = ['folder' + ext for ext in
coverart.CoverDownloader.EXTENSIONS]
external_files = existing_files.difference(list(known_files) +
@ -1144,7 +1144,7 @@ class PodcastChannel(PodcastModelObject):
# The common prefix must end with a space - otherwise it's not
# on a word boundary, and we might end up chopping off too much
if prefix and prefix[-1] != ' ':
prefix = prefix[:prefix.rfind(' ')+1]
prefix = prefix[:prefix.rfind(' ') + 1]
self._common_prefix = prefix

View File

@ -176,19 +176,19 @@ class Exporter(object):
# saving the opml data, if this is not possible, don't
# try to save the new file, but keep the old one so we
# don't end up with a clobbed, empty opml file.
FREE_DISK_SPACE_AFTER = 1024*512
FREE_DISK_SPACE_AFTER = 1024 * 512
path = os.path.dirname(self.filename) or os.path.curdir
available = util.get_free_disk_space(path)
if available != -1 and available < 2*len(data)+FREE_DISK_SPACE_AFTER:
if available != -1 and available < 2 * len(data) + FREE_DISK_SPACE_AFTER:
# On Windows, if we have zero bytes available, assume that we have
# not had the win32file module available + assume enough free space
if not gpodder.ui.win32 or available > 0:
logger.error('Not enough free disk space to save channel list to %s', self.filename)
return False
fp = open(self.filename+'.tmp', 'wb')
fp = open(self.filename + '.tmp', 'wb')
fp.write(data)
fp.close()
util.atomic_rename(self.filename+'.tmp', self.filename)
util.atomic_rename(self.filename + '.tmp', self.filename)
except:
logger.error('Could not open file for writing: %s', self.filename,
exc_info=True)

View File

@ -129,7 +129,7 @@ def get_track_length(filename):
if util.find_command('mplayer') is not None:
try:
mplayer_output = os.popen('mplayer -msglevel all=-1 -identify -vo null -ao null -frames 0 "%s" 2>/dev/null' % filename).read()
return int(float(mplayer_output[mplayer_output.index('ID_LENGTH'):].splitlines()[0][10:])*1000)
return int(float(mplayer_output[mplayer_output.index('ID_LENGTH'):].splitlines()[0][10:]) * 1000)
except:
pass
else:
@ -141,7 +141,7 @@ def get_track_length(filename):
except Exception as e:
logger.warn('Could not determine length: %s', filename, exc_info=True)
return int(60*60*1000*3) # Default is three hours (to be on the safe side)
return int(60 * 60 * 1000 * 3) # Default is three hours (to be on the safe side)
class SyncTrack(object):
@ -284,7 +284,7 @@ class iPodDevice(Device):
def get_free_space(self):
# Reserve 10 MiB for iTunesDB writing (to be on the safe side)
RESERVED_FOR_ITDB = 1024*1024*10
RESERVED_FOR_ITDB = 1024 * 1024 * 10
result = util.get_free_disk_space(self.mountpoint)
if result == -1:
# Can't get free disk space
@ -507,7 +507,7 @@ class MP3PlayerDevice(Device):
download_queue_manager):
Device.__init__(self, config)
self.destination = self._config.device_sync.device_folder
self.buffer_size = 1024*1024 # 1 MiB
self.buffer_size = 1024 * 1024 # 1 MiB
self.download_status_model = download_status_model
self.download_queue_manager = download_queue_manager
@ -693,7 +693,7 @@ class MP3PlayerDevice(Device):
def directory_is_empty(self, directory):
files = glob.glob(os.path.join(directory, '*'))
dotfiles = glob.glob(os.path.join(directory, '.*'))
return len(files+dotfiles) == 0
return len(files + dotfiles) == 0
class MTPDevice(Device):
@ -710,7 +710,7 @@ class MTPDevice(Device):
def __callback(self, sent, total):
if self.cancelled:
return -1
percentage = round(sent/total*100)
percentage = round(sent / total * 100)
text = ('%i%%' % percentage)
self.notify('progress', sent, total, text)
@ -1048,7 +1048,7 @@ class SyncTask(download.DownloadTask):
self.total_size = float(totalSize)
if self.total_size > 0:
self.progress = max(0.0, min(1.0, (count*blockSize)/self.total_size))
self.progress = max(0.0, min(1.0, (count * blockSize) / self.total_size))
self._progress_updated(self.progress)
if self.status == SyncTask.CANCELLED:

View File

@ -410,7 +410,7 @@ def file_age_in_days(filename):
if dt is None:
return 0
else:
return (datetime.datetime.now()-dt).days
return (datetime.datetime.now() - dt).days
def file_modification_timestamp(filename):
@ -508,7 +508,7 @@ def format_date(timestamp):
if timestamp is None:
return None
seconds_in_a_day = 60*60*24
seconds_in_a_day = 60 * 60 * 24
today = time.localtime()[:3]
yesterday = time.localtime(time.time() - seconds_in_a_day)[:3]
@ -527,7 +527,7 @@ def format_date(timestamp):
return _('Yesterday')
try:
diff = int( (time.time() - timestamp)/seconds_in_a_day )
diff = int( (time.time() - timestamp) / seconds_in_a_day )
except:
logger.warn('Cannot convert "%s" to date.', timestamp, exc_info=True)
return None
@ -584,7 +584,7 @@ def format_filesize(bytesize, use_si_units=False, digits=2):
used_value = bytesize / float(value)
used_unit = unit
return ('%.'+str(digits)+'f %s') % (used_value, used_unit)
return ('%.' + str(digits) + 'f %s') % (used_value, used_unit)
def delete_file(filename):
@ -884,7 +884,7 @@ def mimetype_from_extension(extension):
return _MIME_TYPES_EXT[extension]
# Need to prepend something to the extension, so guess_type works
type, encoding = mimetypes.guess_type('file'+extension)
type, encoding = mimetypes.guess_type('file' + extension)
return type or ''
@ -922,9 +922,9 @@ def extension_correct_for_mimetype(extension, mimetype):
# Create a "default" extension from the mimetype, e.g. "application/ogg"
# becomes ".ogg", "audio/mpeg" becomes ".mpeg", etc...
default = ['.'+mimetype.split('/')[-1]]
default = ['.' + mimetype.split('/')[-1]]
return extension in default+mimetypes.guess_all_extensions(mimetype)
return extension in default + mimetypes.guess_all_extensions(mimetype)
def filename_from_url(url):
@ -947,7 +947,7 @@ def filename_from_url(url):
(filename, extension) = os.path.splitext(os.path.basename( urllib.parse.unquote(path)))
if file_type_by_extension(extension) is not None and not \
query.startswith(scheme+'://'):
query.startswith(scheme + '://'):
# We have found a valid extension (audio, video)
# and the query string doesn't look like a URL
return ( filename, extension.lower() )
@ -997,7 +997,7 @@ def file_type_by_extension(extension):
return _MIME_TYPES_EXT[extension].split('/')[0]
# Need to prepend something to the extension, so guess_type works
type, encoding = mimetypes.guess_type('file'+extension)
type, encoding = mimetypes.guess_type('file' + extension)
if type is not None and '/' in type:
filetype, rest = type.split('/', 1)
@ -1082,7 +1082,7 @@ def format_desktop_command(command, filenames, start_position=None):
for fieldcode in ('%U', '%F', '%u', '%f'):
if fieldcode in command:
command_before = command[:command.index(fieldcode)]
command_after = command[command.index(fieldcode)+1:]
command_after = command[command.index(fieldcode) + 1:]
multiple_arguments = fieldcode in ('%U', '%F')
break
@ -1091,7 +1091,7 @@ def format_desktop_command(command, filenames, start_position=None):
commands = []
for filename in filenames:
commands.append(command_before+[filename]+command_after)
commands.append(command_before + [filename] + command_after)
return commands
@ -1394,7 +1394,7 @@ def format_seconds_to_hour_min_sec(seconds):
result.append(N_('%(count)d second', '%(count)d seconds', seconds) % {'count':seconds})
if len(result) > 1:
return (' '+_('and')+' ').join((', '.join(result[:-1]), result[-1]))
return (' ' +_('and') + ' ').join((', '.join(result[:-1]), result[-1]))
else:
return result[0]
@ -1602,7 +1602,7 @@ def commonpath(l1, l2, common=[]):
if len(l1) < 1: return (common, l1, l2)
if len(l2) < 1: return (common, l1, l2)
if l1[0] != l2[0]: return (common, l1, l2)
return commonpath(l1[1:], l2[1:], common+[l1[0]])
return commonpath(l1[1:], l2[1:], common + [l1[0]])
def relpath(p1, p2):
@ -1615,7 +1615,7 @@ def relpath(p1, p2):
(common,l1,l2) = commonpath(pathsplit(p1), pathsplit(p2))
p = []
if len(l1) > 0:
p = [ ('..'+os.sep) * len(l1) ]
p = [ ('..' + os.sep) * len(l1) ]
p = p + l2
if len(p) is 0:
return "."
@ -1675,7 +1675,7 @@ def write_m3u_playlist(m3u_filename, episodes, extm3u=True):
for episode in episodes:
if not extm3u:
# Episode objects are strings that contain file names
f.write(episode+'\n')
f.write(episode + '\n')
continue
if episode.was_downloaded(and_exists=True):
@ -1683,9 +1683,9 @@ def write_m3u_playlist(m3u_filename, episodes, extm3u=True):
assert filename is not None
if os.path.dirname(filename).startswith(os.path.dirname(m3u_filename)):
filename = filename[len(os.path.dirname(m3u_filename)+os.sep):]
f.write('#EXTINF:0,'+episode.playlist_title()+'\n')
f.write(filename+'\n')
filename = filename[len(os.path.dirname(m3u_filename) + os.sep):]
f.write('#EXTINF:0,' + episode.playlist_title() + '\n')
f.write(filename + '\n')
f.close()
@ -1694,7 +1694,7 @@ def generate_names(filename):
basename, ext = os.path.splitext(filename)
for i in itertools.count():
if i:
yield '%s (%d)%s' % (basename, i+1, ext)
yield '%s (%d)%s' % (basename, i + 1, ext)
else:
yield filename