1.1 --- a/WebStack/Helpers/Request.py Sat Aug 28 16:51:53 2004 +0000
1.2 +++ b/WebStack/Helpers/Request.py Sat Aug 28 16:52:11 2004 +0000
1.3 @@ -82,4 +82,53 @@
1.4 self.name = name
1.5 self.value = value
1.6
1.7 +def get_storage_items(storage_body):
1.8 +
1.9 + """
1.10 + Return the items (2-tuples of the form key, values) from the 'storage_body'.
1.11 + This is used in conjunction with FieldStorage objects.
1.12 + """
1.13 +
1.14 + items = []
1.15 + for key in storage_body.keys():
1.16 + items.append((key, storage_body[key]))
1.17 + return items
1.18 +
1.19 +def get_body_fields(field_items, encoding):
1.20 +
1.21 + """
1.22 + Returns a dictionary mapping field names to lists of field values for all
1.23 + entries in the given 'field_items' (2-tuples of the form key, values) using
1.24 + the given 'encoding'.
1.25 + This is used in conjunction with FieldStorage objects.
1.26 + """
1.27 +
1.28 + fields = {}
1.29 +
1.30 + for field_name, field_values in field_items:
1.31 + if type(field_values) == type([]):
1.32 + fields[field_name] = []
1.33 + for field_value in field_values:
1.34 + fields[field_name].append(get_body_field(field_value.value, encoding))
1.35 + else:
1.36 + fields[field_name] = [get_body_field(field_values.value, encoding)]
1.37 +
1.38 + return fields
1.39 +
1.40 +def get_body_field(field_str, encoding):
1.41 +
1.42 + """
1.43 + Returns the appropriate value for the given 'field_str' string using the
1.44 + given 'encoding'.
1.45 + """
1.46 +
1.47 + # Detect stray FieldStorage objects (eg. with Webware).
1.48 +
1.49 + if hasattr(field_str, "value"):
1.50 + return get_body_field(field_str.value, encoding)
1.51 + elif encoding is not None:
1.52 + return unicode(field_str, encoding)
1.53 + else:
1.54 + return field_str
1.55 +
1.56 # vim: tabstop=4 expandtab shiftwidth=4