fix issues raised by bandit

This commit is contained in:
codl 2017-08-29 13:26:32 +02:00
parent 78013ed1e9
commit 2c4d6b9f63
No known key found for this signature in database
GPG Key ID: 6CD7C8891ED1233A
3 changed files with 10 additions and 5 deletions

View File

@ -63,8 +63,9 @@ def decompose_interval(attrname):
try:
value = int(value)
assert value >= 0
except (ValueError, AssertionError) as e:
if not value >= 0:
raise ValueError(value)
except ValueError as e:
raise ValueError("Incorrect time interval", e)
setattr(self, attrname, value * getattr(self, scl_name))

View File

@ -96,6 +96,9 @@ def twitter_login_step2():
except (TwitterError, URLError):
return redirect(url_for('index', twitter_login_error='', _anchor='log_in'))
class TweetArchiveEmptyException(Exception):
pass
@app.route('/upload_tweet_archive', methods=('POST',))
@limiter.limit('10/10 minutes')
@require_auth
@ -111,14 +114,15 @@ def upload_tweet_archive():
ta.chunks = len(files)
db.session.commit()
assert ta.chunks > 0
if not ta.chunks > 0:
raise TweetArchiveEmptyException()
for filename in files:
tasks.import_twitter_archive_month.s(ta.id, filename).apply_async()
return redirect(url_for('index', _anchor='recent_archives'))
except (BadZipFile, AssertionError):
except (BadZipFile, TweetArchiveEmptyException):
return redirect(url_for('index', tweet_archive_failed='', _anchor='tweet_archive_import'))
@app.route('/settings', methods=('POST',))

View File

@ -179,7 +179,7 @@ def delete_from_account(account_id):
account.touch_delete()
action(post)
else:
post = random.choice(eligible)
post = random.choice(eligible) # nosec
print("deleting {}".format(post))
account.touch_delete()
action(post)