Anonymous committed b0ea49a

Changed usage of MultiDict to util.multidict

  • Participants
  • Parent commits 1007dfe

Comments (0)

Files changed (4)

File docs/news.txt

   particular Firefox would then only send ``If-None-Match`` and so
   conditional requests never worked.
+* Changed usage of ``paste.request.MultiDict`` to
+  ``paste.util.multidict``, particularly in ``paste.wsgiwrappers``
+  where ``request.GET`` returns a new style of dictionary interface.

File paste/

 from Cookie import SimpleCookie
 import urlparse
 from util.UserDict24 import DictMixin, IterableUserDict, UserDict
+from paste.util.multidict import multidict
 __all__ = ['get_cookies', 'get_cookie_dict', 'parse_querystring',
            'parse_formvars', 'construct_url', 'path_info_split',
            'path_info_pop', 'resolve_relative_url', 'EnvironHeaders']
-class MultiDict(IterableUserDict):
-    """Acts as a normal dict, but assumes all values are lists, and
-    retrieving an item retrieves the first value in the list. getlist
-    retrieves the full list"""
-    def __getitem__(self, key):
-        return[key][0]
-    def getlist(self, key):
-        return[key]
-    def update(self, dict):
-        if isinstance(dict, UserDict):
-        elif isinstance(dict, type(
-        else:
-            for k, v in dict.items():
-                if self.has_key(k) and isinstance(v, list):
-                    self[k].extend(v)
-                elif self.has_key(k):
-                    self[k].append(v)
-                elif not isinstance(v, list):
-                    self[k] = [v]
-                else:
-                    self[k] = v
 def get_cookies(environ):
     Gets a cookie object (which is a dictionary-like object) from the
         parsed, check_source = environ['paste.parsed_dict_querystring']
         if check_source == source:
             return parsed
-    parsed = cgi.parse_qs(source, keep_blank_values=True,
+    parsed = cgi.parse_qsl(source, keep_blank_values=True,
-    multi = MultiDict()
-    multi.update(parsed)
+    multi = multidict(parsed)
     environ['paste.parsed_dict_querystring'] = (multi, source)
     return multi

File paste/

 # (c) 2005 Ian Bicking and contributors; written for Paste (
 # Licensed under the MIT license:
 import paste.httpexceptions
-from paste.request import EnvironHeaders, parse_formvars, parse_dict_querystring, get_cookie_dict, MultiDict
+from paste.request import EnvironHeaders, parse_formvars, parse_dict_querystring, get_cookie_dict
+from paste.util.multidict import multidict
 from paste.response import HeaderDict
 import paste.registry as registry
 import paste.httpexceptions
         but the output will be put in environ['paste.post_vars']
-        formvars = MultiDict()
+        formvars = multidict()
         formvars.update(parse_formvars(self.environ, all_as_list=True, include_get_vars=False))
         return formvars
     POST = property(POST, doc=POST.__doc__)

File tests/

     start_response(status, response_headers)
     request = WSGIRequest(environ)
     return ['Hello world!\n', 'The get is %s' % str(request.GET),
-        'Val is %s' % request.GET.get('name')]
+        ' and Val is %s' % request.GET.get('name')]
 def test_gets():
     app = TestApp(simpleapp)
     assert "get is {}" in res
     res = app.get('/?name=george')
-    assert "get is {'name': ['george']}" in res
-    assert "Val is george" in res
+    res.mustcontain("get is multidict([('name', 'george')])")
+    res.mustcontain("Val is george")