Skip to content

Commit a7de476

Browse files
committed
flake8 fixes - also change signature of parse()
removed num_re from parse. Variable is not used in method. Nothing seems to call parse with the num_re. Also remove flake8 warning about running compile when defining argument to method.
1 parent d8ef641 commit a7de476

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

roundup/cgi/form_parser.py

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import re, mimetypes
1+
import mimetypes
2+
import re
23

34
from roundup import hyperdb, date, password
4-
from roundup.cgi import templating, TranslationService
5+
from roundup.cgi import TranslationService
56
from roundup.cgi.exceptions import FormError
67

78

@@ -42,7 +43,7 @@ def __init__(self, client):
4243
self._ = self.gettext = _translator.gettext
4344
self.ngettext = _translator.ngettext
4445

45-
def parse(self, create=0, num_re=re.compile(r'^\d+$')):
46+
def parse(self, create=0):
4647
""" Item properties and their values are edited with html FORM
4748
variables and their values. You can:
4849
@@ -287,7 +288,8 @@ def parse(self, create=0, num_re=re.compile(r'^\d+$')):
287288
for entry in self.extractFormList(form[key]):
288289
m = self.FV_DESIGNATOR.match(entry)
289290
if not m:
290-
raise FormError(self._('link "%(key)s" '
291+
raise FormError(self._(
292+
'link "%(key)s" '
291293
'value "%(entry)s" not a designator') % locals())
292294
value.append((m.group(1), m.group(2)))
293295

@@ -305,9 +307,10 @@ def parse(self, create=0, num_re=re.compile(r'^\d+$')):
305307
# make sure the link property is valid
306308
if (not isinstance(propdef[propname], hyperdb.Multilink) and
307309
not isinstance(propdef[propname], hyperdb.Link)):
308-
raise FormError(self._('%(class)s %(property)s '
309-
'is not a link or multilink property') % {
310-
'class':cn, 'property':propname})
310+
raise FormError(self._(
311+
'%(class)s %(property)s '
312+
'is not a link or multilink property') % {
313+
'class': cn, 'property': propname})
311314

312315
all_links.append((cn, nodeid, propname, value))
313316
continue
@@ -317,10 +320,11 @@ def parse(self, create=0, num_re=re.compile(r'^\d+$')):
317320
for entry in self.extractFormList(form[key]):
318321
m = self.FV_SPECIAL.match(entry)
319322
if not m:
320-
raise FormError(self._('The form action claims to '
323+
raise FormError(self._(
324+
'The form action claims to '
321325
'require property "%(property)s" '
322326
'which doesn\'t exist') % {
323-
'property':propname})
327+
'property': propname})
324328
if m.group('classname'):
325329
this = (m.group('classname'), m.group('id'))
326330
entry = m.group('propname')
@@ -339,10 +343,11 @@ def parse(self, create=0, num_re=re.compile(r'^\d+$')):
339343
# does the property exist?
340344
if propname not in propdef:
341345
if mlaction != 'set':
342-
raise FormError(self._('You have submitted a %(action)s '
346+
raise FormError(self._(
347+
'You have submitted a %(action)s '
343348
'action for the property "%(property)s" '
344349
'which doesn\'t exist') % {
345-
'action': mlaction, 'property': propname})
350+
'action': mlaction, 'property': propname})
346351
# the form element is probably just something we don't care
347352
# about - ignore it
348353
continue
@@ -364,7 +369,8 @@ def parse(self, create=0, num_re=re.compile(r'^\d+$')):
364369
else:
365370
# multiple values are not OK
366371
if isinstance(value, type([])):
367-
raise FormError(self._('You have submitted more than one '
372+
raise FormError(self._(
373+
'You have submitted more than one '
368374
'value for the %s property') % propname)
369375
# value might be a single file upload
370376
if not getattr(value, 'filename', None):
@@ -392,7 +398,8 @@ def parse(self, create=0, num_re=re.compile(r'^\d+$')):
392398
raise FormError(self._('Password and confirmation text '
393399
'do not match'))
394400
if isinstance(confirm, type([])):
395-
raise FormError(self._('You have submitted more than one '
401+
raise FormError(self._(
402+
'You have submitted more than one '
396403
'value for the %s property') % propname)
397404
if value != confirm.value:
398405
raise FormError(self._('Password and confirmation text '
@@ -432,14 +439,14 @@ def parse(self, create=0, num_re=re.compile(r'^\d+$')):
432439
elif isinstance(proptype, hyperdb.Multilink):
433440
# convert input to list of ids
434441
try:
435-
l = hyperdb.rawToHyperdb(self.db, cl, nodeid,
436-
propname, value)
442+
id_list = hyperdb.rawToHyperdb(self.db, cl, nodeid,
443+
propname, value)
437444
except hyperdb.HyperdbValueError as msg:
438445
raise FormError(msg)
439446

440447
# now use that list of ids to modify the multilink
441448
if mlaction == 'set':
442-
value = l
449+
value = id_list
443450
else:
444451
# we're modifying the list - get the current list of ids
445452
if propname in props:
@@ -453,17 +460,18 @@ def parse(self, create=0, num_re=re.compile(r'^\d+$')):
453460
if mlaction == 'remove':
454461
# remove - handle situation where the id isn't in
455462
# the list
456-
for entry in l:
463+
for entry in id_list:
457464
try:
458465
existing.remove(entry)
459466
except ValueError:
460-
raise FormError(self._('property '
467+
raise FormError(self._(
468+
'property '
461469
'"%(propname)s": "%(value)s" '
462470
'not currently in list') % {
463-
'propname': propname, 'value': entry})
471+
'propname': propname, 'value': entry})
464472
else:
465473
# add - easy, just don't dupe
466-
for entry in l:
474+
for entry in id_list:
467475
if entry not in existing:
468476
existing.append(entry)
469477
value = existing
@@ -479,8 +487,8 @@ def parse(self, create=0, num_re=re.compile(r'^\d+$')):
479487
try:
480488
# Try handling file upload
481489
if (isinstance(proptype, hyperdb.String) and
482-
hasattr(value, 'filename') and
483-
value.filename is not None):
490+
hasattr(value, 'filename') and
491+
value.filename is not None):
484492
value = self.parse_file(propdef, props, value)
485493
else:
486494
value = hyperdb.rawToHyperdb(self.db, cl, nodeid,
@@ -522,8 +530,8 @@ def parse(self, create=0, num_re=re.compile(r'^\d+$')):
522530
# empty strings
523531
if existing == self.db.BACKEND_MISSING_STRING:
524532
existing = None
525-
elif isinstance(proptype, hyperdb.Number) or \
526-
isinstance(proptype, hyperdb.Integer):
533+
elif (isinstance(proptype, hyperdb.Number) or
534+
isinstance(proptype, hyperdb.Integer)):
527535
# some backends store "missing" Numbers as 0 :(
528536
if existing == self.db.BACKEND_MISSING_NUMBER:
529537
existing = None

0 commit comments

Comments
 (0)