new url_parse_qs method on base request to parse unicode url formatted query strings
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 21 Jan 2010 10:19:38 +0100
changeset 4300 03430023ce82
parent 4297 5f2081181055
child 4301 59cb004db889
new url_parse_qs method on base request to parse unicode url formatted query strings
req.py
--- 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