Ticket #9089: urlencode-multivaluedict.diff

File urlencode-multivaluedict.diff, 2.0 KB (added by Thomas Güttler, 16 years ago)

The new patch includes the unittest written by kratorius.

  • django/utils/http.py

     
    33
    44from django.utils.encoding import smart_str, force_unicode
    55from django.utils.functional import allow_lazy
     6from django.utils.datastructures import MultiValueDict
    67
    78def urlquote(url, safe='/'):
    89    """
     
    3132    unicode strings. The parameters are first case to UTF-8 encoded strings and
    3233    then encoded as per normal.
    3334    """
    34     if hasattr(query, 'items'):
     35    if isinstance(query, MultiValueDict):
     36        query = query.lists()
     37    elif hasattr(query, 'items'):
    3538        query = query.items()
    3639    return urllib.urlencode(
    3740        [(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

     
    99import timesince
    1010import datastructures
    1111import itercompat
     12import http
    1213from decorators import DecoratorFromMiddlewareTests
    1314
    1415# We need this because "datastructures" uses sorted() and the tests are run in
     
    2324    'timesince': timesince,
    2425    'datastructures': datastructures,
    2526    'itercompat': itercompat,
     27    'http': http,
    2628}
    2729
    2830class TestUtilsHtml(TestCase):
Back to Top