Merge pull request #53 from sharkykh/pep8

Fix PEP8 errors and warnings
This commit is contained in:
Johnny Ding
2017-05-17 00:08:42 -07:00
committed by GitHub
9 changed files with 123 additions and 70 deletions

View File

@@ -126,7 +126,8 @@ class DisabledSelectField(SelectField):
class EditForm(FlaskForm):
display_name = TextField('Torrent display name', [
Length(min=3, max=255,
message='Torrent display name must be at least %(min)d characters long and %(max)d at most.')
message='Torrent display name must be at least %(min)d characters long '
'and %(max)d at most.')
])
category = DisabledSelectField('Category')
@@ -172,7 +173,8 @@ class UploadForm(FlaskForm):
display_name = TextField('Torrent display name (optional)', [
Optional(),
Length(min=3, max=255,
message='Torrent display name must be at least %(min)d characters long and %(max)d at most.')
message='Torrent display name must be at least %(min)d characters long and '
'%(max)d at most.')
])
# category = SelectField('Category')
@@ -209,7 +211,7 @@ class UploadForm(FlaskForm):
# Decode and ensure data is bencoded data
try:
torrent_dict = bencode.decode(field.data)
#field.data.close()
# field.data.close()
except (bencode.MalformedBencodeException, UnicodeError):
raise ValidationError('Malformed torrent file')
@@ -221,7 +223,6 @@ class UploadForm(FlaskForm):
except AssertionError as e:
raise ValidationError('Malformed torrent metadata ({})'.format(e.args[0]))
site_tracker = app.config.get('MAIN_ANNOUNCE_URL')
ensure_tracker = app.config.get('ENFORCE_MAIN_ANNOUNCE_URL')
@@ -233,11 +234,12 @@ class UploadForm(FlaskForm):
# Ensure private torrents are using our tracker
if torrent_dict['info'].get('private') == 1:
if torrent_dict['announce'].decode('utf-8') != site_tracker:
raise ValidationError('Private torrent: please set {} as the main tracker'.format(site_tracker))
raise ValidationError(
'Private torrent: please set {} as the main tracker'.format(site_tracker))
elif ensure_tracker and not tracker_found:
raise ValidationError('Please include {} in the trackers of the torrent'.format(site_tracker))
raise ValidationError(
'Please include {} in the trackers of the torrent'.format(site_tracker))
# Note! bencode will sort dict keys, as per the spec
# This may result in a different hash if the uploaded torrent does not match the
@@ -266,11 +268,13 @@ class TorrentFileData(object):
# https://wiki.theory.org/BitTorrentSpecification#Metainfo_File_Structure
def _validate_trackers(torrent_dict, tracker_to_check_for=None):
announce = torrent_dict.get('announce')
announce_string = _validate_bytes(announce, 'announce', 'utf-8')
tracker_found = tracker_to_check_for and (announce_string.lower() == tracker_to_check_for.lower()) or False
tracker_found = tracker_to_check_for and (
announce_string.lower() == tracker_to_check_for.lower()) or False
announce_list = torrent_dict.get('announce-list')
if announce_list is not None: