Fix pep8 across codebase

* Further whitespace fixes by autopep8
 * Using pep8 v1.6.2 (not currently used by pyflakes)
 * Update config for pep8 and flake8 in tox.ini
   * A separate pep8 entry for running autopep8. The ignores prevent
     blank lines being added after docstrings.
   * .tox and E133 are ignored in flake8 by default.
This commit is contained in:
Calum Lind 2015-10-20 19:41:47 +01:00
parent 82ac1bdfe0
commit 32bc20d8ce
32 changed files with 179 additions and 164 deletions

View File

@ -12,6 +12,8 @@
# Minor modifications made by Andrew Resch to replace the BTFailure errors with Exceptions # Minor modifications made by Andrew Resch to replace the BTFailure errors with Exceptions
from types import DictType, IntType, ListType, LongType, StringType, TupleType
def decode_int(x, f): def decode_int(x, f):
f += 1 f += 1
@ -75,8 +77,6 @@ def bdecode(x):
return r return r
from types import DictType, IntType, ListType, LongType, StringType, TupleType
class Bencached(object): class Bencached(object):

View File

@ -177,7 +177,9 @@ class PreferencesManager(component.Component):
if value: if value:
import random import random
listen_ports = [] listen_ports = []
randrange = lambda: random.randrange(49152, 65525)
def randrange():
return random.randrange(49152, 65525)
listen_ports.append(randrange()) listen_ports.append(randrange())
listen_ports.append(listen_ports[0] + 10) listen_ports.append(listen_ports[0] + 10)
else: else:

View File

@ -379,10 +379,10 @@ class TorrentManager(component.Component):
lt.add_torrent_params_flags_t.flag_update_subscribe | lt.add_torrent_params_flags_t.flag_update_subscribe |
lt.add_torrent_params_flags_t.flag_apply_ip_filter) lt.add_torrent_params_flags_t.flag_apply_ip_filter)
# Set flags: enable duplicate_is_error & override_resume_data, disable auto_managed. # Set flags: enable duplicate_is_error & override_resume_data, disable auto_managed.
add_torrent_params["flags"] = ((default_flags add_torrent_params["flags"] = ((default_flags |
| lt.add_torrent_params_flags_t.flag_duplicate_is_error lt.add_torrent_params_flags_t.flag_duplicate_is_error |
| lt.add_torrent_params_flags_t.flag_override_resume_data) lt.add_torrent_params_flags_t.flag_override_resume_data) ^
^ lt.add_torrent_params_flags_t.flag_auto_managed) lt.add_torrent_params_flags_t.flag_auto_managed)
if options["seed_mode"]: if options["seed_mode"]:
add_torrent_params["flags"] |= lt.add_torrent_params_flags_t.flag_seed_mode add_torrent_params["flags"] |= lt.add_torrent_params_flags_t.flag_seed_mode

View File

@ -121,8 +121,9 @@ class SchedulerSelectWidget(gtk.DrawingArea):
if self.get_point(event) != self.hover_point: if self.get_point(event) != self.hover_point:
self.hover_point = self.get_point(event) self.hover_point = self.get_point(event)
self.hover_label.set_text(self.hover_days[self.hover_point[1]] + " " + str(self.hover_point[0]) self.hover_label.set_text(self.hover_days[self.hover_point[1]] +
+ ":00 - " + str(self.hover_point[0]) + ":59") " " + str(self.hover_point[0]) +
":00 - " + str(self.hover_point[0]) + ":59")
if self.mouse_press: if self.mouse_press:
points = [[self.hover_point[0], self.start_point[0]], [self.hover_point[1], self.start_point[1]]] points = [[self.hover_point[0], self.start_point[0]], [self.hover_point[1], self.start_point[1]]]

View File

@ -1,27 +1,3 @@
"""
rencode -- Web safe object pickling/unpickling.
Public domain, Connelly Barnes 2006-2007.
The rencode module is a modified version of bencode from the
BitTorrent project. For complex, heterogeneous data structures with
many small elements, r-encodings take up significantly less space than
b-encodings:
>>> len(rencode.dumps({'a':0, 'b':[1,2], 'c':99}))
13
>>> len(bencode.bencode({'a':0, 'b':[1,2], 'c':99}))
26
The rencode format is not standardized, and may change with different
rencode module versions, so you should check that you are using the
same rencode version throughout your project.
"""
__version__ = '1.0.2'
__all__ = ['dumps', 'loads']
# Original bencode module by Petru Paler, et al. # Original bencode module by Petru Paler, et al.
# #
# Modifications by Connelly Barnes: # Modifications by Connelly Barnes:
@ -62,10 +38,33 @@ __all__ = ['dumps', 'loads']
# (The rencode module is licensed under the above license as well). # (The rencode module is licensed under the above license as well).
# #
"""
rencode -- Web safe object pickling/unpickling.
Public domain, Connelly Barnes 2006-2007.
The rencode module is a modified version of bencode from the
BitTorrent project. For complex, heterogeneous data structures with
many small elements, r-encodings take up significantly less space than
b-encodings:
>>> len(rencode.dumps({'a':0, 'b':[1,2], 'c':99}))
13
>>> len(bencode.bencode({'a':0, 'b':[1,2], 'c':99}))
26
The rencode format is not standardized, and may change with different
rencode module versions, so you should check that you are using the
same rencode version throughout your project.
"""
import struct import struct
from threading import Lock from threading import Lock
from types import DictType, FloatType, IntType, ListType, LongType, NoneType, StringType, TupleType, UnicodeType from types import DictType, FloatType, IntType, ListType, LongType, NoneType, StringType, TupleType, UnicodeType
__version__ = '1.0.2'
__all__ = ['dumps', 'loads']
# Default number of bits for serialized floats, either 32 or 64 (also a parameter for dumps()). # Default number of bits for serialized floats, either 32 or 64 (also a parameter for dumps()).
DEFAULT_FLOAT_BITS = 32 DEFAULT_FLOAT_BITS = 32

View File

@ -45,8 +45,8 @@ if 0: # aclient non-core
print("%s" % pydoc.getdoc(func)) print("%s" % pydoc.getdoc(func))
if 1: # baseclient/core if 1: # baseclient/core
methods = sorted([m for m in dir(Core) if m.startswith("export")] methods = sorted([m for m in dir(Core) if m.startswith("export")] +
+ ['export_add_torrent_file_binary']) # HACK ['export_add_torrent_file_binary']) # HACK
for m in methods: for m in methods:

View File

@ -87,8 +87,7 @@ class Win32IcoFile(object):
# end for (read headers) # end for (read headers)
# order by size and color depth # order by size and color depth
self.entry.sort(lambda x, y: cmp(x['width'], y['width']) self.entry.sort(lambda x, y: cmp(x['width'], y['width']) or cmp(x['color_depth'], y['color_depth']))
or cmp(x['color_depth'], y['color_depth']))
self.entry.reverse() self.entry.reverse()
def sizes(self): def sizes(self):

View File

@ -8,6 +8,6 @@
# #
UI_PATH = __path__[0] UI_PATH = __path__[0]
from deluge.ui.console.main import start from deluge.ui.console.main import start # NOQA
assert start # silence pyflakes assert start # silence pyflakes

View File

@ -200,7 +200,9 @@ class Command(BaseCommand):
col_priority += fp col_priority += fp
rf = format_utils.remove_formatting rf = format_utils.remove_formatting
tlen = lambda s: strwidth(rf(s))
def tlen(s):
return strwidth(rf(s))
if not isinstance(col_filename, unicode): if not isinstance(col_filename, unicode):
col_filename = unicode(col_filename, "utf-8") col_filename = unicode(col_filename, "utf-8")

View File

@ -557,8 +557,11 @@ class AllTorrents(BaseMode, component.Component):
if field in first_element: if field in first_element:
is_string = isinstance(first_element[field], basestring) is_string = isinstance(first_element[field], basestring)
sort_key = lambda s: sg(s)[field] def sort_key(s):
sort_key2 = lambda s: sg(s)[field].lower() return sg(s)[field]
def sort_key2(s):
return sg(s)[field].lower()
# If it's a string, sort case-insensitively but preserve A>a order # If it's a string, sort case-insensitively but preserve A>a order
if is_string: if is_string:
@ -1120,10 +1123,8 @@ class AllTorrents(BaseMode, component.Component):
self.search_string += uchar self.search_string += uchar
still_matching = ( still_matching = (
cname.lower().find(self.search_string.lower()) cname.lower().find(self.search_string.lower()) ==
== cname.lower().find(old_search_string.lower()) and
cname.lower().find(old_search_string.lower())
and
cname.lower().find(self.search_string.lower()) != -1 cname.lower().find(self.search_string.lower()) != -1
) )

View File

@ -254,7 +254,9 @@ def torrent_action(idx, data, mode, ids):
options[key] = "multiple" options[key] = "multiple"
def create_popup(status): def create_popup(status):
cb = lambda result, ids=ids: _do_set_torrent_options(ids, result) def cb(result, ids=ids):
return _do_set_torrent_options(ids, result)
option_popup = InputPopup(mode, "Set torrent options (Esc to cancel)", close_cb=cb, height_req=22) option_popup = InputPopup(mode, "Set torrent options (Esc to cancel)", close_cb=cb, height_req=22)
for (field, field_type) in torrent_options: for (field, field_type) in torrent_options:

View File

@ -617,9 +617,11 @@ class TorrentDetail(BaseMode, component.Component):
# show popup for priority selections # show popup for priority selections
def show_priority_popup(self, was_empty): def show_priority_popup(self, was_empty):
func = lambda idx, data, we=was_empty: self.do_priority(idx, data, we) def popup_func(idx, data, we=was_empty):
return self.do_priority(idx, data, we)
if self.marked: if self.marked:
self.popup = SelectablePopup(self, "Set File Priority", func) self.popup = SelectablePopup(self, "Set File Priority", popup_func)
self.popup.add_line("_Do Not Download", data=FILE_PRIORITY["Do Not Download"], foreground="red") self.popup.add_line("_Do Not Download", data=FILE_PRIORITY["Do Not Download"], foreground="red")
self.popup.add_line("_Normal Priority", data=FILE_PRIORITY["Normal Priority"]) self.popup.add_line("_Normal Priority", data=FILE_PRIORITY["Normal Priority"])
self.popup.add_line("_High Priority", data=FILE_PRIORITY["High Priority"], foreground="yellow") self.popup.add_line("_High Priority", data=FILE_PRIORITY["High Priority"], foreground="yellow")

View File

@ -32,8 +32,8 @@ class AboutDialog:
self.about.set_copyright( self.about.set_copyright(
_("Copyright %(year_start)s-%(year_end)s Deluge Team") % {"year_start": 2007, "year_end": 2015}) _("Copyright %(year_start)s-%(year_end)s Deluge Team") % {"year_start": 2007, "year_end": 2015})
self.about.set_comments( self.about.set_comments(
_("A peer-to-peer file sharing program\nutilizing the BitTorrent protocol.") _("A peer-to-peer file sharing program\nutilizing the BitTorrent protocol.") +
+ "\n\n" + _("Client:") + " %s\n" % version) "\n\n" + _("Client:") + " %s\n" % version)
self.about.set_version(version) self.about.set_version(version)
self.about.set_authors([ self.about.set_authors([
_("Current Developers:"), "Andrew Resch", "Damien Churchill", _("Current Developers:"), "Andrew Resch", "Damien Churchill",

View File

@ -59,8 +59,11 @@ log = logging.getLogger(__name__)
try: try:
from setproctitle import setproctitle, getproctitle from setproctitle import setproctitle, getproctitle
except ImportError: except ImportError:
setproctitle = lambda t: None def setproctitle(title):
getproctitle = lambda: None return
def getproctitle():
return
class Gtk(_UI): class Gtk(_UI):

View File

@ -574,7 +574,6 @@ class ListView:
def add_bool_column(self, header, col_type=bool, hidden=False, def add_bool_column(self, header, col_type=bool, hidden=False,
position=None, status_field=None, sortid=0, position=None, status_field=None, sortid=0,
column_type="bool", tooltip=None, default=True): column_type="bool", tooltip=None, default=True):
"""Add a bool column to the listview""" """Add a bool column to the listview"""
render = gtk.CellRendererToggle() render = gtk.CellRendererToggle()
self.add_column(header, render, col_type, hidden, position, self.add_column(header, render, col_type, hidden, position,

View File

@ -21,7 +21,8 @@ import deluge.log
try: try:
from setproctitle import setproctitle from setproctitle import setproctitle
except ImportError: except ImportError:
setproctitle = lambda t: None def setproctitle(title):
return
def version_callback(option, opt_str, value, parser): def version_callback(option, opt_str, value, parser):

View File

@ -15,10 +15,9 @@ from datetime import datetime, timedelta
from email.utils import formatdate from email.utils import formatdate
from functools import reduce from functools import reduce
from twisted.internet.task import LoopingCall
from deluge import component from deluge import component
from deluge.common import utf8_encoded from deluge.common import utf8_encoded
from twisted.internet.task import LoopingCall
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -39,7 +38,7 @@ class AuthError(Exception):
pass pass
# Import after as json_api imports the above AuthError and AUTH_LEVEL_DEFAULT # Import after as json_api imports the above AuthError and AUTH_LEVEL_DEFAULT
from deluge.ui.web.json_api import export, JSONComponent # isort:skip from deluge.ui.web.json_api import export, JSONComponent # NOQA, isort:skip
def make_checksum(session_id): def make_checksum(session_id):

View File

@ -12,7 +12,9 @@ import zlib
from deluge import common from deluge import common
_ = lambda x: gettext.gettext(x).decode("utf-8")
def _(text):
gettext.gettext(text).decode("utf-8")
def escape(text): def escape(text):

View File

@ -6,8 +6,11 @@
[flake8] [flake8]
max-line-length = 120 max-line-length = 120
builtins = _,__request__ builtins = _,__request__
ignore = E133 exclude = .git,dist,build
exclude = .tox,.git,dist,build
[pep8]
max-line-length = 120
ignore = E301,E309
[tox] [tox]
envlist = py27, flake8, isort, docs envlist = py27, flake8, isort, docs