Ticket #9089: urlencode-multivaluedict.diff
File urlencode-multivaluedict.diff, 2.0 KB (added by , 16 years ago) |
---|
-
django/utils/http.py
3 3 4 4 from django.utils.encoding import smart_str, force_unicode 5 5 from django.utils.functional import allow_lazy 6 from django.utils.datastructures import MultiValueDict 6 7 7 8 def urlquote(url, safe='/'): 8 9 """ … … 31 32 unicode strings. The parameters are first case to UTF-8 encoded strings and 32 33 then encoded as per normal. 33 34 """ 34 if hasattr(query, 'items'): 35 if isinstance(query, MultiValueDict): 36 query = query.lists() 37 elif hasattr(query, 'items'): 35 38 query = query.items() 36 39 return urllib.urlencode( 37 40 [(smart_str(k), -
tests/regressiontests/utils/http.py
1 """ 2 >>> from django.utils.http import urlencode 3 4 >>> urlencode({ 'a': 1, 'b': 2, 'c': 3}) 5 'a=1&c=3&b=2' 6 7 >>> from django.utils.datastructures import MultiValueDict 8 >>> urlencode(MultiValueDict({'name': ['Adrian', 'Simon'], 'position': ['Developer']}), doseq=True) 9 'position=Developer&name=Adrian&name=Simon' 10 >>> urlencode(MultiValueDict({'test': [1, 2, 3]}), doseq=True) 11 'test=1&test=2&test=3' 12 """ -
tests/regressiontests/utils/tests.py
9 9 import timesince 10 10 import datastructures 11 11 import itercompat 12 import http 12 13 from decorators import DecoratorFromMiddlewareTests 13 14 14 15 # We need this because "datastructures" uses sorted() and the tests are run in … … 23 24 'timesince': timesince, 24 25 'datastructures': datastructures, 25 26 'itercompat': itercompat, 27 'http': http, 26 28 } 27 29 28 30 class TestUtilsHtml(TestCase):