req.py
changeset 4300 03430023ce82
parent 4222 5667f493c505
child 4307 7fba9c34c88f
--- a/req.py	Wed Jan 20 15:03:30 2010 +0100
+++ b/req.py	Thu Jan 21 10:19:38 2010 +0100
@@ -9,6 +9,7 @@
 
 from urllib import quote as urlquote, unquote as urlunquote
 from datetime import time, datetime, timedelta
+from cgi import parse_qsl
 
 from logilab.common.decorators import cached
 from logilab.common.deprecation import deprecated
@@ -259,6 +260,16 @@
         except UnicodeDecodeError: # might occurs on manually typed URLs
             return unicode(urlunquote(quoted), 'iso-8859-1')
 
+    def url_parse_qsl(self, querystring):
+        """return a list of (key, val) found in the url quoted query string"""
+        if isinstance(querystring, unicode):
+            querystring = querystring.encode(self.encoding)
+        for key, val in parse_qsl(querystring):
+            try:
+                yield unicode(key, self.encoding), unicode(val, self.encoding)
+            except UnicodeDecodeError: # might occurs on manually typed URLs
+                yield unicode(key, 'iso-8859-1'), unicode(val, 'iso-8859-1')
+
     # bound user related methods ###############################################
 
     @cached