1.1 --- a/WebStack/Helpers/Request.py Mon Sep 06 21:31:04 2004 +0000
1.2 +++ b/WebStack/Helpers/Request.py Mon Sep 06 21:35:14 2004 +0000
1.3 @@ -130,7 +130,14 @@
1.4 elif hasattr(field_str, "read"):
1.5 return field_str.read()
1.6 elif encoding is not None:
1.7 - return unicode(field_str, encoding)
1.8 + try:
1.9 + return unicode(field_str, encoding)
1.10 + except UnicodeError:
1.11 + # NOTE: Hacks to permit graceful failure.
1.12 + try:
1.13 + return unicode(field_str, "iso-8859-1")
1.14 + except UnicodeError:
1.15 + return u""
1.16 else:
1.17 return field_str
1.18
1.19 @@ -159,4 +166,39 @@
1.20
1.21 return fields
1.22
1.23 +def filter_fields(all_fields, fields_from_path):
1.24 +
1.25 + """
1.26 + Taking items from the 'all_fields' dictionary, produce a new dictionary
1.27 + which does not contain items from the 'fields_from_path' dictionary.
1.28 + Return a new dictionary.
1.29 + """
1.30 +
1.31 + fields = {}
1.32 + for field_name, field_values in all_fields.items():
1.33 +
1.34 + # Find the path values for this field (for filtering below).
1.35 +
1.36 + if fields_from_path.has_key(field_name):
1.37 + field_from_path_values = fields_from_path[field_name]
1.38 + if type(field_from_path_values) != type([]):
1.39 + field_from_path_values = [field_from_path_values]
1.40 + else:
1.41 + field_from_path_values = []
1.42 +
1.43 + fields[field_name] = []
1.44 + for field_value in field_values:
1.45 +
1.46 + # Filter path values.
1.47 +
1.48 + if field_value not in field_from_path_values:
1.49 + fields[field_name].append(field_value)
1.50 +
1.51 + # Remove filtered fields.
1.52 +
1.53 + if fields[field_name] == []:
1.54 + del fields[field_name]
1.55 +
1.56 + return fields
1.57 +
1.58 # vim: tabstop=4 expandtab shiftwidth=4