Skip to content

Commit d8ef641

Browse files
committed
flake8 fixes
1 parent bb586f2 commit d8ef641

File tree

1 file changed

+63
-53
lines changed

1 file changed

+63
-53
lines changed

roundup/cgi/actions.py

Lines changed: 63 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
import re, cgi, time, csv, codecs, sys
1+
import cgi
2+
import codecs
3+
import csv
4+
import re
5+
import sys
6+
from datetime import timedelta
27

38
from roundup import hyperdb, token, date, password
49
from roundup.actions import Action as BaseAction
5-
from roundup.i18n import _
10+
from roundup.anypy import urllib_
11+
from roundup.anypy.html import html_escape
12+
from roundup.anypy.strings import StringIO
613
from roundup.cgi import exceptions, templating
7-
from roundup.mailgw import uidFromAddress
8-
from roundup.rate_limit import Gcra, RateLimit
914
from roundup.cgi.timestamp import Timestamped
1015
from roundup.exceptions import Reject, RejectRaw
11-
from roundup.anypy import urllib_
12-
from roundup.anypy.strings import StringIO
13-
14-
15-
from roundup.anypy.html import html_escape
16-
17-
from datetime import timedelta
16+
from roundup.i18n import _
17+
from roundup.mailgw import uidFromAddress
18+
from roundup.rate_limit import Gcra, RateLimit
1819

1920
# Also add action to client.py::Client.actions property
2021
__all__ = ['Action', 'ShowAction', 'RetireAction', 'RestoreAction',
@@ -23,6 +24,7 @@
2324
'ConfRegoAction', 'RegisterAction', 'LoginAction', 'LogoutAction',
2425
'NewItemAction', 'ExportCSVAction', 'ExportCSVWithIdAction']
2526

27+
2628
class Action:
2729
def __init__(self, client):
2830
self.client = client
@@ -135,11 +137,11 @@ def examine_url(self, url):
135137
allowed_pattern = re.compile(r'''^[A-Za-z0-9@:/?._~%!$&'()*+,;=-]*$''')
136138

137139
if not allowed_pattern.match(parsed_url_tuple.path):
138-
raise ValueError(self._("Path component (%(url_path)s) in %(url)s "
139-
"is not properly escaped") % info)
140+
raise ValueError(self._("Path component (%(url_path)s) in %(url)s "
141+
"is not properly escaped") % info)
140142

141143
if not allowed_pattern.match(parsed_url_tuple.params):
142-
raise ValueError(self._("Params component (%(url_params)s) in %(url)s is not properly escaped") % info)
144+
raise ValueError(self._("Params component (%(url_params)s) in %(url)s is not properly escaped") % info)
143145

144146
if not allowed_pattern.match(parsed_url_tuple.query):
145147
raise ValueError(self._("Query component (%(url_query)s) in %(url)s is not properly escaped") % info)
@@ -239,7 +241,7 @@ def handle(self):
239241

240242
# check permission
241243
if not self.hasPermission('Retire', classname=self.classname,
242-
itemid=itemid):
244+
itemid=itemid):
243245
raise exceptions.Unauthorised(self._(
244246
'You do not have permission to retire %(class)s'
245247
) % {'class': self.classname})
@@ -351,9 +353,10 @@ def handle(self):
351353
if queryname != self.db.query.get(qid, 'name'):
352354
continue
353355
# whoops we found a duplicate; report error and return
354-
message = _("You already own a query named '%s'. "
355-
"Please choose another name.") % \
356-
(queryname)
356+
message = _(
357+
"You already own a query named '%s'. "
358+
"Please choose another name.") % (queryname)
359+
357360
self.client.add_error_message(message)
358361
return
359362

@@ -374,7 +377,7 @@ def handle(self):
374377
continue
375378
if not self.hasPermission('Edit', 'query', itemid=qid):
376379
raise exceptions.Unauthorised(self._(
377-
"You do not have permission to edit queries"))
380+
"You do not have permission to edit queries"))
378381
self.db.query.set(qid, klass=self.classname,
379382
url=url, name=queryname)
380383
else:
@@ -424,11 +427,11 @@ def fakeFilterVars(self):
424427
if isinstance(prop, hyperdb.String):
425428
v = self.form[key].value
426429
# If this ever has unbalanced quotes, hilarity will ensue
427-
l = token.token_split(v)
428-
if len(l) != 1 or l[0] != v:
430+
tokens = token.token_split(v)
431+
if len(tokens) != 1 or tokens[0] != v:
429432
self.form.value.remove(self.form[key])
430433
# replace the single value with the split list
431-
for v in l:
434+
for v in tokens:
432435
self.form.value.append(cgi.MiniFieldStorage(key, v))
433436
elif isinstance(prop, hyperdb.Number):
434437
try:
@@ -505,7 +508,7 @@ def handle(self):
505508
line = 0
506509
for values in reader:
507510
line += 1
508-
if line == 1: continue
511+
if line == 1: continue # noqa: E701
509512
# skip property names header
510513
if values == props:
511514
continue
@@ -538,16 +541,17 @@ def handle(self):
538541
# confirm correct weight
539542
if len(props_without_id) != len(values):
540543
self.client.add_error_message(
541-
self._('Not enough values on line %(line)s') % \
542-
{'line':line})
544+
self._('Not enough values on line %(line)s') % {
545+
'line': line})
543546
return
544547

545548
# extract the new values
546549
d = {}
547550
for name, value in zip(props_without_id, values):
548551
# check permission to edit this property on this item
549552
if exists and not self.hasPermission('Edit', itemid=itemid,
550-
classname=self.classname, property=name):
553+
classname=self.classname,
554+
property=name):
551555
raise exceptions.Unauthorised(self._(
552556
'You do not have permission to edit %(class)s'
553557
) % {'class': self.classname})
@@ -812,9 +816,9 @@ def handleCollision(self, props):
812816
message = self._(
813817
'Edit Error: someone else has edited this %(klass)s (%(props)s). '
814818
'View <a target="_blank" href="%(klass)s%(id)s">their changes</a> '
815-
'in a new window.') % { "klass": self.classname,
816-
"props": ', '.join(props),
817-
"id": self.nodeid}
819+
'in a new window.') % {"klass": self.classname,
820+
"props": ', '.join(props),
821+
"id": self.nodeid}
818822
self.client.add_error_message(message, escape=False)
819823
return
820824

@@ -1050,7 +1054,7 @@ def finishRego(self):
10501054
<script nonce="%s" type="text/javascript">
10511055
window.setTimeout('window.location = "%s"', 1000);
10521056
</script>''' % (message, url, message,
1053-
self.client.client_nonce, url)
1057+
self.client.client_nonce, url)
10541058

10551059

10561060
class ConfRegoAction(RegoCommon):
@@ -1101,7 +1105,8 @@ def handle(self):
11011105
# handle the create now
11021106
try:
11031107
# when it hits the None element, it'll set self.nodeid
1104-
messages = self._editnodes(props, links)
1108+
# execute for side effect
1109+
messages = self._editnodes(props, links) # noqa: F841
11051110
except (ValueError, KeyError, IndexError, Reject) as message:
11061111
escape = not isinstance(message, RejectRaw)
11071112
# these errors might just be indicative of user dumbness
@@ -1126,7 +1131,9 @@ def handle(self):
11261131
check_user = self.db.config['WEB_REGISTRATION_PREVALIDATE_USERNAME']
11271132
if check_user:
11281133
try:
1129-
user_found = self.db.user.lookup(user_props['username'])
1134+
# verify user exists
1135+
user_found = self.db.user.lookup(user_props['username']) \
1136+
# noqa: F841
11301137
# if user is found reject the request.
11311138
raise Reject(
11321139
_("Username '%s' is already used.") % user_props['username'])
@@ -1165,7 +1172,8 @@ def handle(self):
11651172
%(url)s?@action=confrego&otk=%(otk)s
11661173
11671174
""") % {'name': user_props['username'], 'tracker': tracker_name,
1168-
'url': self.base, 'otk': otk, 'tracker_email': tracker_email}
1175+
'url': self.base, 'otk': otk, 'tracker_email': tracker_email} \
1176+
# noqa: E122
11691177
else:
11701178
subject = _('Complete your registration to %s') % (tracker_name)
11711179
body = _("""To complete your registration of the user "%(name)s" with
@@ -1174,7 +1182,7 @@ def handle(self):
11741182
%(url)s?@action=confrego&otk=%(otk)s
11751183
11761184
""") % {'name': user_props['username'], 'tracker': tracker_name,
1177-
'url': self.base, 'otk': otk}
1185+
'url': self.base, 'otk': otk} # noqa: E122
11781186
if not self.client.standard_message([user_props['address']], subject,
11791187
body,
11801188
(tracker_name, tracker_email)):
@@ -1278,13 +1286,13 @@ def handle(self):
12781286
query = {}
12791287
pass
12801288

1281-
redirect_url = urllib_.urlunparse((redirect_url_tuple.scheme,
1282-
redirect_url_tuple.netloc,
1283-
redirect_url_tuple.path,
1284-
redirect_url_tuple.params,
1285-
urllib_.urlencode(list(sorted(query.items())), doseq=True),
1286-
redirect_url_tuple.fragment)
1287-
)
1289+
redirect_url = urllib_.urlunparse(
1290+
(redirect_url_tuple.scheme,
1291+
redirect_url_tuple.netloc,
1292+
redirect_url_tuple.path,
1293+
redirect_url_tuple.params,
1294+
urllib_.urlencode(list(sorted(query.items())), doseq=True),
1295+
redirect_url_tuple.fragment))
12881296

12891297
try:
12901298
# Implement rate limiting of logins by login name.
@@ -1326,13 +1334,13 @@ def handle(self):
13261334
if '__came_from' in self.form:
13271335
# set a new error
13281336
query['@error_message'] = err.args
1329-
redirect_url = urllib_.urlunparse((redirect_url_tuple.scheme,
1330-
redirect_url_tuple.netloc,
1331-
redirect_url_tuple.path,
1332-
redirect_url_tuple.params,
1333-
urllib_.urlencode(list(sorted(query.items())), doseq=True),
1334-
redirect_url_tuple.fragment )
1335-
)
1337+
redirect_url = urllib_.urlunparse(
1338+
(redirect_url_tuple.scheme,
1339+
redirect_url_tuple.netloc,
1340+
redirect_url_tuple.path,
1341+
redirect_url_tuple.params,
1342+
urllib_.urlencode(list(sorted(query.items())), doseq=True),
1343+
redirect_url_tuple.fragment))
13361344
raise exceptions.Redirect(redirect_url)
13371345
# if no __came_from, send back to base url with error
13381346
return
@@ -1347,7 +1355,9 @@ def handle(self):
13471355

13481356
# If we came from someplace, go back there
13491357
if '__came_from' in self.form:
1350-
query['@ok_message'] = _("Welcome %(username)s!") %{"username" : self.client.user, } # adds welcome message to user when logged in
1358+
# add welcome message to user when logged in
1359+
query['@ok_message'] = _("Welcome %(username)s!") % {
1360+
"username": self.client.user, }
13511361
redirect_url = urllib_.urlunparse((redirect_url_tuple.scheme,
13521362
redirect_url_tuple.netloc,
13531363
redirect_url_tuple.path,
@@ -1366,7 +1376,7 @@ def verifyLogin(self, username, password):
13661376
# Prevents guessing of valid usernames by detecting
13671377
# delay caused by checking password only on valid
13681378
# users.
1369-
_discard = self.verifyPassword("2", password)
1379+
_discard = self.verifyPassword("2", password) # noqa: F841
13701380
raise exceptions.LoginError(self._('Invalid login'))
13711381

13721382
# verify the password
@@ -1502,7 +1512,7 @@ def fct(arg):
15021512
return ""
15031513
else:
15041514
if (arg.local(self.db.getUserTimezone()).pretty('%H:%M') ==
1505-
'00:00'):
1515+
'00:00'):
15061516
fmt = '%Y-%m-%d'
15071517
else:
15081518
fmt = '%Y-%m-%d %H:%M'
@@ -1701,8 +1711,8 @@ def __init__(self, *args):
17011711
# different Action interfaces, we have to look at the arguments to
17021712
# figure out how to complete construction.
17031713
if (len(args) == 1 and
1704-
hasattr(args[0], '__class__') and
1705-
args[0].__class__.__name__ == 'Client'):
1714+
hasattr(args[0], '__class__') and
1715+
args[0].__class__.__name__ == 'Client'):
17061716
self.cgi = True
17071717
self.execute = self.execute_cgi
17081718
self.client = args[0]

0 commit comments

Comments
 (0)