Skip to content

Commit ac9ed78

Browse files
committed
flake8 fixes: lambda assign squash, over/under indent, var names
Fix: Squashed with a noqa: E731 do not assign a lambda expression, use a def fixed some of the rest. E741 ambiguous variable name 'l' E128 continuation line under-indented for visual indent E701 multiple statements on one line (colon) E127 continuation line over-indented for visual indent E111 indentation is not a multiple of 4 first tranch of changes about 1/3 of the number of warnings.
1 parent 921f581 commit ac9ed78

File tree

1 file changed

+63
-58
lines changed

1 file changed

+63
-58
lines changed

roundup/cgi/templating.py

Lines changed: 63 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def _extras(config):
7373
extras['break-on-newline'] = True
7474
return extras
7575

76-
markdown = lambda s, c: Markdown(safe_mode='escape', extras=_extras(c)).convert(s)
76+
markdown = lambda s, c: Markdown(safe_mode='escape', extras=_extras(c)).convert(s) # noqa: E731
7777
except ImportError:
7878
markdown = None
7979

@@ -136,7 +136,7 @@ def _extensions(config):
136136
extensions.append('nl2br')
137137
return extensions
138138

139-
markdown = lambda s, c: markdown_impl(s, extensions=_extensions(c))
139+
markdown = lambda s, c: markdown_impl(s, extensions=_extensions(c)) # noqa: E731
140140
except ImportError:
141141
markdown = None
142142

@@ -189,7 +189,7 @@ def _options(config):
189189
options['hard_wrap'] = True
190190
return options
191191

192-
markdown = lambda s, c: mistune.markdown(s, **_options(c))
192+
markdown = lambda s, c: mistune.markdown(s, **_options(c)) # noqa: E731
193193
except ImportError:
194194
markdown = None
195195

@@ -238,8 +238,8 @@ def __init__(self, action, klass, translator=None):
238238

239239
def __str__(self):
240240
return self._('You are not allowed to %(action)s '
241-
'items of class %(class)s') % {
242-
'action': self.action, 'class': self.klass}
241+
'items of class %(class)s') % {
242+
'action': self.action, 'class': self.klass}
243243

244244

245245
# --- Template Loader API
@@ -328,14 +328,14 @@ def add_loader(self, loader):
328328
self.loaders.append(loader)
329329

330330
def check(self, name):
331-
for l in self.loaders:
332-
if l.check(name):
331+
for loader in self.loaders:
332+
if loader.check(name):
333333
return True
334334

335335
def load(self, name):
336-
for l in self.loaders:
337-
if l.check(name):
338-
return l.load(name)
336+
for loader in self.loaders:
337+
if loader.check(name):
338+
return loader.load(name)
339339

340340
def __getitem__(self, name):
341341
"""Needed for TAL templates compatibility"""
@@ -460,7 +460,7 @@ def context(client, template=None, classname=None, request=None):
460460
# add in the item if there is one
461461
if client.nodeid:
462462
c['context'] = HTMLItem(client, classname, client.nodeid,
463-
anonymous=1)
463+
anonymous=1)
464464
elif classname in client.db.classes:
465465
c['context'] = HTMLClass(client, classname, anonymous=1)
466466
return c
@@ -495,9 +495,9 @@ def __getattr__(self, attr):
495495
raise AttributeError(attr)
496496

497497
def classes(self):
498-
l = sorted(self._client.db.classes.keys())
498+
class_keys = sorted(self._client.db.classes.keys())
499499
m = []
500-
for item in l:
500+
for item in class_keys:
501501
m.append(HTMLClass(self._client, item))
502502
return m
503503

@@ -546,7 +546,8 @@ def lookupKeys(linkcl, key, ids, num_re=num_re):
546546
# fall back to id if illegal (avoid template crash)
547547
label = entry
548548
# fall back to designator if label is None
549-
if label is None: label = '%s%s' % (linkcl.classname, entry)
549+
if label is None:
550+
label = '%s%s' % (linkcl.classname, entry)
550551
l.append(label)
551552
else:
552553
l.append(entry)
@@ -577,8 +578,8 @@ def html4_cgi_escape_attrs(**attrs):
577578
Code can use None to indicate a pure boolean.
578579
'''
579580
return ' '.join(['%s="%s"' % (k, html_escape(str(v), True))
580-
if v is not None else '%s' % (k)
581-
for k, v in sorted(attrs.items())])
581+
if v is not None else '%s' % (k)
582+
for k, v in sorted(attrs.items())])
582583

583584

584585
def xhtml_cgi_escape_attrs(**attrs):
@@ -591,8 +592,8 @@ def xhtml_cgi_escape_attrs(**attrs):
591592
Code can use None to indicate a pure boolean.
592593
'''
593594
return ' '.join(['%s="%s"' % (k, html_escape(str(v), True))
594-
if v is not None else '%s="%s"' % (k, k)
595-
for k, v in sorted(attrs.items())])
595+
if v is not None else '%s="%s"' % (k, k)
596+
for k, v in sorted(attrs.items())])
596597

597598

598599
def input_html4(**attrs):
@@ -627,8 +628,8 @@ def gettext(self, msgid):
627628
"""Return the localized translation of msgid"""
628629
if self._context is None:
629630
self._context = context(self._client)
630-
return self._client.translator.translate(domain="roundup",
631-
msgid=msgid, context=self._context)
631+
return self._client.translator.translate(
632+
domain="roundup", msgid=msgid, context=self._context)
632633

633634
_ = gettext
634635

@@ -641,23 +642,23 @@ def view_check(self):
641642
"""
642643
if not self.is_view_ok():
643644
raise Unauthorised("view", self._classname,
644-
translator=self._client.translator)
645+
translator=self._client.translator)
645646

646647
def edit_check(self):
647648
""" Raise the Unauthorised exception if the user's not permitted to
648649
edit items of this class.
649650
"""
650651
if not self.is_edit_ok():
651652
raise Unauthorised("edit", self._classname,
652-
translator=self._client.translator)
653+
translator=self._client.translator)
653654

654655
def retire_check(self):
655656
""" Raise the Unauthorised exception if the user's not permitted to
656657
retire items of this class.
657658
"""
658659
if not self.is_retire_ok():
659660
raise Unauthorised("retire", self._classname,
660-
translator=self._client.translator)
661+
translator=self._client.translator)
661662

662663

663664
class HTMLClass(HTMLInputMixin, HTMLPermissions):
@@ -681,29 +682,29 @@ def is_edit_ok(self):
681682
""" Is the user allowed to Create the current class?
682683
"""
683684
perm = self._db.security.hasPermission
684-
return perm('Web Access', self._client.userid) and perm('Create',
685-
self._client.userid, self._classname)
685+
return perm('Web Access', self._client.userid) and perm(
686+
'Create', self._client.userid, self._classname)
686687

687688
def is_retire_ok(self):
688689
""" Is the user allowed to retire items of the current class?
689690
"""
690691
perm = self._db.security.hasPermission
691-
return perm('Web Access', self._client.userid) and perm('Retire',
692-
self._client.userid, self._classname)
692+
return perm('Web Access', self._client.userid) and perm(
693+
'Retire', self._client.userid, self._classname)
693694

694695
def is_restore_ok(self):
695696
""" Is the user allowed to restore retired items of the current class?
696697
"""
697698
perm = self._db.security.hasPermission
698-
return perm('Web Access', self._client.userid) and perm('Restore',
699-
self._client.userid, self._classname)
699+
return perm('Web Access', self._client.userid) and perm(
700+
'Restore', self._client.userid, self._classname)
700701

701702
def is_view_ok(self):
702703
""" Is the user allowed to View the current class?
703704
"""
704705
perm = self._db.security.hasPermission
705-
return perm('Web Access', self._client.userid) and perm('View',
706-
self._client.userid, self._classname)
706+
return perm('Web Access', self._client.userid) and perm(
707+
'View', self._client.userid, self._classname)
707708

708709
def is_only_view_ok(self):
709710
""" Is the user only allowed to View (ie. not Create) the current class?
@@ -733,7 +734,7 @@ def __getitem__(self, item):
733734
if not isinstance(prop, klass):
734735
continue
735736
return htmlklass(self._client, self._classname, None, prop, item,
736-
None, self._anonymous)
737+
None, self._anonymous)
737738

738739
# no good
739740
raise KeyError(item)
@@ -785,20 +786,21 @@ def list(self, sort_on=None):
785786
""" List all items in this class.
786787
"""
787788
# get the list and sort it nicely
788-
l = self._klass.list()
789+
class_list = self._klass.list()
789790
keyfunc = make_key_function(self._db, self._classname, sort_on)
790-
l.sort(key=keyfunc)
791+
class_list.sort(key=keyfunc)
791792

792793
# check perms
793794
check = self._client.db.security.hasPermission
794795
userid = self._client.userid
795796
if not check('Web Access', userid):
796797
return []
797798

798-
l = [HTMLItem(self._client, self._classname, id) for id in l
799-
if check('View', userid, self._classname, itemid=id)]
799+
class_list = [HTMLItem(self._client, self._classname, id)
800+
for id in class_list if
801+
check('View', userid, self._classname, itemid=id)]
800802

801-
return l
803+
return class_list
802804

803805
def csv(self):
804806
""" Return the items of this class as a chunk of CSV text.
@@ -816,9 +818,9 @@ def csv(self):
816818
for name in props:
817819
# check permission to view this property on this item
818820
if not check('View', userid, itemid=nodeid,
819-
classname=self._klass.classname, property=name):
821+
classname=self._klass.classname, property=name):
820822
raise Unauthorised('view', self._klass.classname,
821-
translator=self._client.translator)
823+
translator=self._client.translator)
822824
value = self._klass.get(nodeid, name)
823825
if value is None:
824826
l.append('')
@@ -859,15 +861,15 @@ def filter(self, request=None, filterspec={}, sort=[], group=[]):
859861
if not check('Web Access', userid):
860862
return []
861863

862-
l = [HTMLItem(self._client, self.classname, id)
863-
for id in self._klass.filter(None, filterspec, sort, group)
864-
if check('View', userid, self.classname, itemid=id)]
865-
return l
864+
filtered = [HTMLItem(self._client, self.classname, id)
865+
for id in self._klass.filter(None, filterspec, sort, group)
866+
if check('View', userid, self.classname, itemid=id)]
867+
return filtered
866868

867869
def classhelp(self, properties=None, label=''"(list)", width='500',
868-
height='600', property='', form='itemSynopsis',
869-
pagesize=50, inputtype="checkbox", html_kwargs={},
870-
group='', sort=None, filter=None):
870+
height='600', property='', form='itemSynopsis',
871+
pagesize=50, inputtype="checkbox", html_kwargs={},
872+
group='', sort=None, filter=None):
871873
"""Pop up a javascript window with class help
872874
873875
This generates a link to a popup window which displays the
@@ -925,11 +927,11 @@ def classhelp(self, properties=None, label=''"(list)", width='500',
925927
filtervalues.append('&%s=%s' % (name, urllib_.quote(values)))
926928
filter = '&@filter=%s%s' % (','.join(names), ''.join(filtervalues))
927929
else:
928-
filter = ''
930+
filter = ''
929931
help_url = "%s?@startwith=0&@template=help&"\
930932
"properties=%s%s%s%s%s%s&@pagesize=%s%s" % \
931933
(self.classname, properties, property, form, type,
932-
group, sort, pagesize, filter)
934+
group, sort, pagesize, filter)
933935
onclick = "javascript:help_window('%s', '%s', '%s');return false;" % \
934936
(help_url, width, height)
935937
return ('<a class="classhelp" data-helpurl="%s" '
@@ -952,10 +954,10 @@ def submit(self, label=''"Submit New Entry", action="new", html_kwargs={}):
952954

953955
return \
954956
self.input(type="submit", name="submit_button",
955-
value=self._(label), **html_kwargs) + \
957+
value=self._(label), **html_kwargs) + \
956958
'\n' + \
957959
self.input(type="hidden", name="@csrf",
958-
value=anti_csrf_nonce(self._client)) + \
960+
value=anti_csrf_nonce(self._client)) + \
959961
'\n' + \
960962
self.input(type="hidden", name="@action", value=action)
961963

@@ -1005,15 +1007,16 @@ def is_edit_ok(self):
10051007
""" Is the user allowed to Edit this item?
10061008
"""
10071009
perm = self._db.security.hasPermission
1008-
return perm('Web Access', self._client.userid) and perm('Edit',
1009-
self._client.userid, self._classname, itemid=self._nodeid)
1010+
return perm('Web Access', self._client.userid) and perm(
1011+
'Edit', self._client.userid, self._classname, itemid=self._nodeid)
10101012

10111013
def is_retire_ok(self):
10121014
""" Is the user allowed to Reture this item?
10131015
"""
10141016
perm = self._db.security.hasPermission
1015-
return perm('Web Access', self._client.userid) and perm('Retire',
1016-
self._client.userid, self._classname, itemid=self._nodeid)
1017+
return perm('Web Access', self._client.userid) and perm(
1018+
'Retire', self._client.userid, self._classname,
1019+
itemid=self._nodeid)
10171020

10181021
def is_restore_ok(self):
10191022
""" Is the user allowed to restore this item?
@@ -1026,8 +1029,9 @@ def is_view_ok(self):
10261029
""" Is the user allowed to View this item?
10271030
"""
10281031
perm = self._db.security.hasPermission
1029-
if perm('Web Access', self._client.userid) and perm('View',
1030-
self._client.userid, self._classname, itemid=self._nodeid):
1032+
if perm('Web Access', self._client.userid) and perm(
1033+
'View', self._client.userid, self._classname,
1034+
itemid=self._nodeid):
10311035
return 1
10321036
return self.is_edit_ok()
10331037

@@ -1038,7 +1042,7 @@ def is_only_view_ok(self):
10381042

10391043
def __repr__(self):
10401044
return '<HTMLItem(0x%x) %s %s>' % (id(self), self._classname,
1041-
self._nodeid)
1045+
self._nodeid)
10421046

10431047
def __getitem__(self, item):
10441048
""" return an HTMLProperty instance
@@ -1073,7 +1077,8 @@ def __getitem__(self, item):
10731077
for klass, htmlklass in propclasses:
10741078
if isinstance(prop, klass):
10751079
htmlprop = htmlklass(self._client, self._classname,
1076-
self._nodeid, prop, items[0], value, self._anonymous)
1080+
self._nodeid, prop, items[0],
1081+
value, self._anonymous)
10771082
if htmlprop is not None:
10781083
if has_rest:
10791084
if isinstance(htmlprop, MultilinkHTMLProperty):

0 commit comments

Comments
 (0)