[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher/Browser - BrowserRequest.py:1.4
Steve Alexander
steve@cat-box.net
Tue, 11 Jun 2002 11:53:55 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/Publisher/Browser
In directory cvs.zope.org:/tmp/cvs-serv23763/lib/python/Zope/Publisher/Browser
Modified Files:
BrowserRequest.py
Log Message:
various reformatting.
fixed bugs with :list in BrowserRequest
made various tests use publish(request, handle_errors=0)
increased test coverage of testBrowserRequest
=== Zope3/lib/python/Zope/Publisher/Browser/BrowserRequest.py 1.3 => 1.4 ===
# Insert in dictionary
if key in mapping_object:
- if flags & RECORDS:
- #Get the list and the last record
- #in the list
- reclist = mapping_object[key]
- reclist.reverse()
- x=reclist[0]
- reclist.reverse()
- if not hasattr(x,attr):
- #If the attribute does not
- #exist, setit
- if flags&SEQUENCE: item=[item]
- reclist.remove(x)
- setattr(x,attr,item)
- reclist.append(x)
- mapping_object[key] = reclist
- else:
- if flags&SEQUENCE:
- # If the attribute is a
- # sequence, append the item
- # to the existing attribute
- reclist.remove(x)
- y = getattr(x, attr)
- y.append(item)
- setattr(x, attr, y)
- reclist.append(x)
- mapping_object[key] = reclist
+ if flags & RECORDS:
+ #Get the list and the last record
+ #in the list
+ reclist = mapping_object[key]
+ reclist.reverse()
+ x=reclist[0]
+ reclist.reverse()
+ if not hasattr(x,attr):
+ #If the attribute does not
+ #exist, setit
+ if flags&SEQUENCE: item=[item]
+ reclist.remove(x)
+ setattr(x,attr,item)
+ reclist.append(x)
+ mapping_object[key] = reclist
+ else:
+ if flags&SEQUENCE:
+ # If the attribute is a
+ # sequence, append the item
+ # to the existing attribute
+ reclist.remove(x)
+ y = getattr(x, attr)
+ y.append(item)
+ setattr(x, attr, y)
+ reclist.append(x)
+ mapping_object[key] = reclist
+ else:
+ # Create a new record and add
+ # it to the list
+ n=record()
+ setattr(n,attr,item)
+ reclist.append(n)
+ mapping_object[key]=reclist
+ elif flags&RECORD:
+ b=mapping_object[key]
+ if flags&SEQUENCE:
+ item=[item]
+ if not hasattr(b,attr):
+ # if it does not have the
+ # attribute, set it
+ setattr(b,attr,item)
else:
- # Create a new record and add
- # it to the list
- n=record()
- setattr(n,attr,item)
- reclist.append(n)
- mapping_object[key]=reclist
- elif flags&RECORD:
- b=mapping_object[key]
- if flags&SEQUENCE:
- item=[item]
- if not hasattr(b,attr):
- # if it does not have the
- # attribute, set it
- setattr(b,attr,item)
- else:
- # it has the attribute so
- # append the item to it
- setattr(b,attr,getattr(b,attr)+item)
- else:
- # it is not a sequence so
- # set the attribute
- setattr(b,attr,item)
- else:
- # it is not a record or list of records
- found=mapping_object[key]
- if isinstance(found, ListType):
- found.append(item)
- else:
- found=[found,item]
- mapping_object[key]=found
+ # it has the attribute so
+ # append the item to it
+ setattr(b,attr,getattr(b,attr)+item)
+ else:
+ # it is not a sequence so
+ # set the attribute
+ setattr(b,attr,item)
+ else:
+ # it is not a record or list of records
+ found=mapping_object[key]
+ if isinstance(found, list):
+ found.append(item)
+ else:
+ found=[found,item]
+ mapping_object[key]=found
else:
- # The dictionary does not have the key
- if flags&RECORDS:
- # Create a new record, set its attribute
- # and put it in the dictionary as a list
- a = record()
- if flags&SEQUENCE: item=[item]
- setattr(a,attr,item)
- mapping_object[key]=[a]
- elif flags&RECORD:
- # Create a new record, set its attribute
- # and put it in the dictionary
- if flags&SEQUENCE: item=[item]
- r = mapping_object[key]=record()
- setattr(r,attr,item)
- else:
- # it is not a record or list of records
- if flags&SEQUENCE: item=[item]
- mapping_object[key]=item
+ # The dictionary does not have the key
+ if flags&RECORDS:
+ # Create a new record, set its attribute
+ # and put it in the dictionary as a list
+ a = record()
+ if flags&SEQUENCE: item=[item]
+ setattr(a,attr,item)
+ mapping_object[key]=[a]
+ elif flags&RECORD:
+ # Create a new record, set its attribute
+ # and put it in the dictionary
+ if flags&SEQUENCE: item=[item]
+ r = mapping_object[key]=record()
+ setattr(r,attr,item)
+ else:
+ # it is not a record or list of records
+ if flags&SEQUENCE: item=[item]
+ mapping_object[key]=item
else:
# This branch is for case when no type was specified.
@@ -303,7 +303,7 @@
if key in mapping_object:
# it is not a record or list of records
found=mapping_object[key]
- if isinstance(found, ListType):
+ if isinstance(found, list):
found.append(item)
else:
found=[found,item]
@@ -321,47 +321,47 @@
else:
#The form has the key
if isinstance(values, 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
- # 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 isinstance(values, ListType):
- # the key is mapped to a list
- lst = form[keys]
- for val in values:
- # for each val in the list
- if isinstance(val, record):
- # if the val is a record
- for k, v in val.__dict__.items():
+ # 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
+ # 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 isinstance(values, list):
+ # the key is mapped to a list
+ lst = form[keys]
+ for val in values:
+ # for each val in the list
+ if isinstance(val, record):
+ # if the val is a record
+ for k, v in val.__dict__.items():
- # loop through each
- # attribute and value in
- # the record
+ # loop through each
+ # attribute and value in
+ # the record
- for y in lst:
+ for y in lst:
- # loop through each
- # record in the form
- # list if it doesn't
- # have the attributes
- # in the default
- # dictionary, set them
-
- if not hasattr(y, k):
- setattr(y, k, v)
- else:
- # val is not a record
- if not a in lst:
- lst.append(a)
- form[keys] = lst
+ # loop through each
+ # record in the form
+ # list if it doesn't
+ # have the attributes
+ # in the default
+ # dictionary, set them
+
+ if not hasattr(y, k):
+ setattr(y, k, v)
+ else:
+ # val is not a record
+ if not a in lst:
+ lst.append(a)
+ form[keys] = lst
else:
# The form has the key, the key is not mapped
# to a record or sequence so do nothing
@@ -370,44 +370,44 @@
# Convert to tuples
if tuple_items:
for key in tuple_items.keys():
- # Split the key and get the attr
- k=key.split(".")
- k, attr=".".join(k[:-1]), k[-1]
-
- # remove any type_names in the attr
- while not attr == '':
- attr = attr.split(":")
- attr, new = ":".join(attr[:-1]), attr[-1]
- attr = new
-
- if k in form:
- # If the form has the split key get its value
- item = form[k]
- if isinstance(item, record):
- # if the value is mapped to a record, check if it
- # has the attribute, if it has it, convert it to
- # a tuple and set it
- if hasattr(item, attr):
- value = tuple(getattr(item, attr))
- setattr(item, attr, value)
- else:
- # It is mapped to a list of records
- for x in item:
- # loop through the records
- if hasattr(x, attr):
- # If the record has the attribute
- # convert it to a tuple and set it
- value = tuple(getattr(x, attr))
- setattr(x, attr, value)
- else:
- # the form does not have the split key
- if key in form:
- # if it has the original key, get the item
- # convert it to a tuple
- item = form[key]
- item = tuple(form[key])
- form[key] = item
-
+ # Split the key and get the attr
+ k=key.split(".")
+ k, attr=".".join(k[:-1]), k[-1]
+
+ # remove any type_names in the attr
+ while not attr == '':
+ attr = attr.split(":")
+ attr, new = ":".join(attr[:-1]), attr[-1]
+ attr = new
+
+ if k in form:
+ # If the form has the split key get its value
+ item = form[k]
+ if isinstance(item, record):
+ # if the value is mapped to a record, check if it
+ # has the attribute, if it has it, convert it to
+ # a tuple and set it
+ if hasattr(item, attr):
+ value = tuple(getattr(item, attr))
+ setattr(item, attr, value)
+ else:
+ # It is mapped to a list of records
+ for x in item:
+ # loop through the records
+ if hasattr(x, attr):
+ # If the record has the attribute
+ # convert it to a tuple and set it
+ value = tuple(getattr(x, attr))
+ setattr(x, attr, value)
+ else:
+ # the form does not have the split key
+ if key in form:
+ # if it has the original key, get the item
+ # convert it to a tuple
+ item = form[key]
+ item = tuple(form[key])
+ form[key] = item
+
if meth:
self.setPathSuffix((meth,))