[Zope-Checkins] CVS: Zope/lib/python/ZPublisher - HTTPRequest.py:1.72
Martijn Pieters
mj@zope.com
Sat, 20 Jul 2002 21:50:00 -0400
Update of /cvs-repository/Zope/lib/python/ZPublisher
In directory cvs.zope.org:/tmp/cvs-serv7345/lib/python/ZPublisher
Modified Files:
HTTPRequest.py
Log Message:
Further cleanups in defaults handling code.
- Clear up a comment
- Rename 'keys, values' to 'key, value'
- Fix potential bug: If the default for a given form entry is a list, but
the form provided only one value (and didn't indicate it should be a list
with :list), appending the defaults would fail.
- Fix bug: If the default is a list of primitive items (not records), none
of them would be added to the form field due to the use of the wrong
(potentially non-existing) variable name.
- Use isinstance(var, lt) instead of type(var) == type([]).
=== Zope/lib/python/ZPublisher/HTTPRequest.py 1.71 => 1.72 ===
#insert defaults into form dictionary
if defaults:
- for keys, values in defaults.items():
- if not form.has_key(keys):
+ for key, value in defaults.items():
+ if not form.has_key(key):
# if the form does not have the key,
# set the default
- form[keys]=values
+ form[key]=value
else:
#The form has the key
- if isinstance(values, record):
+ if isinstance(value, record):
# if the key is mapped to a record, get the
# record
- r = form[keys]
- for k, v in values.__dict__.items():
- # loop through the attributes and values
+ r = form[key]
+ for k, v in value.__dict__.items():
+ # loop through the attributes and value
# in the default dictionary
if not hasattr(r, k):
# if the form dictionary doesn't have
# the attribute, set it to the default
setattr(r,k,v)
- form[keys] = r
- elif values == type([]):
- # the key is mapped to a list
- l = form[keys]
- for x in values:
- # for each x in the list
+ form[key] = r
+ elif isinstance(value, lt):
+ # the default value is a list
+ l = form[key]
+ if not isinstance(l, lt):
+ l = [l]
+ for x in value:
if isinstance(x, record):
# if the x is a record
for k, v in x.__dict__.items():
@@ -627,9 +628,9 @@
setattr(y, k, v)
else:
# x is not a record
- if not a in l:
- l.append(a)
- form[keys] = l
+ if not x in l:
+ l.append(x)
+ form[key] = l
else:
# The form has the key, the key is not mapped
# to a record or sequence so do nothing