req.py
branchstable
changeset 4891 90203ec7b3e3
parent 4466 8b0ca7904820
child 4892 7ee8f128be9e
equal deleted inserted replaced
4890:b54255f82812 4891:90203ec7b3e3
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     6 :license: Library General Public License version 2 - http://www.gnu.org/licenses
     6 :license: Library General Public License version 2 - http://www.gnu.org/licenses
     7 """
     7 """
     8 __docformat__ = "restructuredtext en"
     8 __docformat__ = "restructuredtext en"
     9 
     9 
       
    10 from urlparse import urlsplit, urlunsplit
    10 from urllib import quote as urlquote, unquote as urlunquote
    11 from urllib import quote as urlquote, unquote as urlunquote
    11 from datetime import time, datetime, timedelta
    12 from datetime import time, datetime, timedelta
    12 from cgi import parse_qsl
    13 from cgi import parse_qs, parse_qsl
    13 
    14 
    14 from logilab.common.decorators import cached
    15 from logilab.common.decorators import cached
    15 from logilab.common.deprecation import deprecated
    16 from logilab.common.deprecation import deprecated
    16 from logilab.common.date import ustrftime, strptime, todate, todatetime
    17 from logilab.common.date import ustrftime, strptime, todate, todatetime
    17 
    18 
   268             try:
   269             try:
   269                 yield unicode(key, self.encoding), unicode(val, self.encoding)
   270                 yield unicode(key, self.encoding), unicode(val, self.encoding)
   270             except UnicodeDecodeError: # might occurs on manually typed URLs
   271             except UnicodeDecodeError: # might occurs on manually typed URLs
   271                 yield unicode(key, 'iso-8859-1'), unicode(val, 'iso-8859-1')
   272                 yield unicode(key, 'iso-8859-1'), unicode(val, 'iso-8859-1')
   272 
   273 
       
   274 
       
   275     def rebuild_url(self, url, **newparams):
       
   276         """return the given url with newparams inserted. If any new params
       
   277         is already specified in the url, it's overriden by the new value
       
   278 
       
   279         newparams may only be mono-valued.
       
   280         """
       
   281         if isinstance(url, unicode):
       
   282             url = url.encode(self.encoding)
       
   283         schema, netloc, path, query, fragment = urlsplit(url)
       
   284         query = parse_qs(query)
       
   285         # sort for testing predictability
       
   286         for key, val in sorted(newparams.iteritems()):
       
   287             query[key] = (self.url_quote(val),)
       
   288         query = '&'.join(u'%s=%s' % (param, value)
       
   289                          for param, values in query.items()
       
   290                          for value in values)
       
   291         return urlunsplit((schema, netloc, path, query, fragment))
       
   292 
   273     # bound user related methods ###############################################
   293     # bound user related methods ###############################################
   274 
   294 
   275     @cached
   295     @cached
   276     def user_data(self):
   296     def user_data(self):
   277         """returns a dictionnary with this user's information"""
   297         """returns a dictionnary with this user's information"""