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
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
from types import DictType, IntType, ListType, LongType, StringType, TupleType
def decode_int(x, f):
f += 1
@ -75,8 +77,6 @@ def bdecode(x):
return r
from types import DictType, IntType, ListType, LongType, StringType, TupleType
class Bencached(object):

View file

@ -177,7 +177,9 @@ class PreferencesManager(component.Component):
if value:
import random
listen_ports = []
randrange = lambda: random.randrange(49152, 65525)
def randrange():
return random.randrange(49152, 65525)
listen_ports.append(randrange())
listen_ports.append(listen_ports[0] + 10)
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_apply_ip_filter)
# Set flags: enable duplicate_is_error & override_resume_data, disable auto_managed.
add_torrent_params["flags"] = ((default_flags
| 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_auto_managed)
add_torrent_params["flags"] = ((default_flags |
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_auto_managed)
if options["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:
self.hover_point = self.get_point(event)
self.hover_label.set_text(self.hover_days[self.hover_point[1]] + " " + str(self.hover_point[0])
+ ":00 - " + str(self.hover_point[0]) + ":59")
self.hover_label.set_text(self.hover_days[self.hover_point[1]] +
" " + str(self.hover_point[0]) +
":00 - " + str(self.hover_point[0]) + ":59")
if self.mouse_press:
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.
#
# Modifications by Connelly Barnes:
@ -62,10 +38,33 @@ __all__ = ['dumps', 'loads']
# (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
from threading import Lock
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_FLOAT_BITS = 32

View file

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

View file

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

View file

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

View file

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

View file

@ -557,8 +557,11 @@ class AllTorrents(BaseMode, component.Component):
if field in first_element:
is_string = isinstance(first_element[field], basestring)
sort_key = lambda s: sg(s)[field]
sort_key2 = lambda s: sg(s)[field].lower()
def sort_key(s):
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 is_string:
@ -1120,10 +1123,8 @@ class AllTorrents(BaseMode, component.Component):
self.search_string += uchar
still_matching = (
cname.lower().find(self.search_string.lower())
==
cname.lower().find(old_search_string.lower())
and
cname.lower().find(self.search_string.lower()) ==
cname.lower().find(old_search_string.lower()) and
cname.lower().find(self.search_string.lower()) != -1
)

View file

@ -254,7 +254,9 @@ def torrent_action(idx, data, mode, ids):
options[key] = "multiple"
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)
for (field, field_type) in torrent_options:

View file

@ -617,9 +617,11 @@ class TorrentDetail(BaseMode, component.Component):
# show popup for priority selections
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:
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("_Normal Priority", data=FILE_PRIORITY["Normal Priority"])
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(
_("Copyright %(year_start)s-%(year_end)s Deluge Team") % {"year_start": 2007, "year_end": 2015})
self.about.set_comments(
_("A peer-to-peer file sharing program\nutilizing the BitTorrent protocol.")
+ "\n\n" + _("Client:") + " %s\n" % version)
_("A peer-to-peer file sharing program\nutilizing the BitTorrent protocol.") +
"\n\n" + _("Client:") + " %s\n" % version)
self.about.set_version(version)
self.about.set_authors([
_("Current Developers:"), "Andrew Resch", "Damien Churchill",

View file

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

View file

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

View file

@ -21,7 +21,8 @@ import deluge.log
try:
from setproctitle import setproctitle
except ImportError:
setproctitle = lambda t: None
def setproctitle(title):
return
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 functools import reduce
from twisted.internet.task import LoopingCall
from deluge import component
from deluge.common import utf8_encoded
from twisted.internet.task import LoopingCall
log = logging.getLogger(__name__)
@ -39,7 +38,7 @@ class AuthError(Exception):
pass
# 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):

View file

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

View file

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