Ticket #12140: 12140-2.diff

File 12140-2.diff, 1.6 KB (added by Claude Paroz, 13 years ago)

Patch updated to current trunk

  • django/utils/http.py

    diff --git a/django/utils/http.py b/django/utils/http.py
    index d343a37..9da5a14 100644
    a b def urlencode(query, doseq=0):  
    7171        query = query.items()
    7272    return urllib.urlencode(
    7373        [(smart_str(k),
    74          isinstance(v, (list,tuple)) and [smart_str(i) for i in v] or smart_str(v))
     74         [smart_str(i) for i in v] if isinstance(v, (list,tuple)) else smart_str(v))
    7575            for k, v in query],
    7676        doseq)
    7777
  • tests/regressiontests/utils/http.py

    diff --git a/tests/regressiontests/utils/http.py b/tests/regressiontests/utils/http.py
    index 16c7daa..67dcd7a 100644
    a b class TestUtilsHttp(unittest.TestCase):  
    3131        # 2-tuples (the norm)
    3232        result = http.urlencode((('a', 1), ('b', 2), ('c', 3)))
    3333        self.assertEqual(result, 'a=1&b=2&c=3')
     34
    3435        # A dictionary
    3536        result = http.urlencode({ 'a': 1, 'b': 2, 'c': 3})
    3637        acceptable_results = [
    class TestUtilsHttp(unittest.TestCase):  
    4445            'c=3&b=2&a=1'
    4546        ]
    4647        self.assertTrue(result in acceptable_results)
     48        result = http.urlencode({'a': [1, 2]}, doseq=False)
     49        self.assertEqual(result, 'a=%5B%271%27%2C+%272%27%5D')
     50        result = http.urlencode({'a': [1, 2]}, doseq=True)
     51        self.assertEqual(result, 'a=1&a=2')
     52        result = http.urlencode({'a': []}, doseq=True)
     53        self.assertEqual(result, '')
     54
    4755        # A MultiValueDict
    4856        result = http.urlencode(MultiValueDict({
    4957            'name': ['Adrian', 'Simon'],
Back to Top