Ticket #5964: 5964.diff

File 5964.diff, 2.8 KB (added by Simon Meers, 13 years ago)
  • django/utils/http.py

    diff -r 45c3e62075e8 django/utils/http.py
    a b  
    3131    without double-quoting occurring.
    3232    """
    3333    return force_unicode(urllib.quote(smart_str(url), smart_str(safe)))
    34 
    3534urlquote = allow_lazy(urlquote, unicode)
    3635
    3736def urlquote_plus(url, safe=''):
     
    4443    return force_unicode(urllib.quote_plus(smart_str(url), smart_str(safe)))
    4544urlquote_plus = allow_lazy(urlquote_plus, unicode)
    4645
     46def urlunquote(quoted_url):
     47    """
     48    A wrapper for Python's urllib.unquote() function that can operate on
     49    the result of django.utils.http.urlquote().
     50    """
     51    return unicode(urllib.unquote(str(quoted_url)), 'utf-8')
     52urlunquote = allow_lazy(urlunquote, unicode)
     53
     54def urlunquote_plus(quoted_url):
     55    """
     56    A wrapper for Python's urllib.unquote_plus() function that can operate on
     57    the result of django.utils.http.urlquote_plus().
     58    """
     59    return unicode(urllib.unquote_plus(str(quoted_url)), 'utf-8')
     60urlunquote_plus = allow_lazy(urlunquote_plus, unicode)
     61
    4762def urlencode(query, doseq=0):
    4863    """
    4964    A version of Python's urllib.urlencode() function that can operate on
  • tests/regressiontests/text/tests.py

    diff -r 45c3e62075e8 tests/regressiontests/text/tests.py
    a b  
    33
    44from django.test import TestCase
    55from django.utils.encoding import iri_to_uri
    6 from django.utils.http import urlquote, urlquote_plus, cookie_date, http_date
     6from django.utils.http import (
     7    urlquote, urlquote_plus, urlunquote, urlunquote_plus, cookie_date,
     8    http_date)
    79from django.utils.text import get_text_list, smart_split
    810from django.utils.translation import override
    911
     
    6062            [u"cut:','|cut:' '"])
    6163
    6264    def test_urlquote(self):
    63 
    6465        self.assertEqual(urlquote(u'Paris & Orl\xe9ans'),
    6566            u'Paris%20%26%20Orl%C3%A9ans')
    6667        self.assertEqual(urlquote(u'Paris & Orl\xe9ans', safe="&"),
    6768            u'Paris%20&%20Orl%C3%A9ans')
     69        self.assertEqual(
     70            urlunquote(u'Paris%20%26%20Orl%C3%A9ans'),
     71            u'Paris & Orl\xe9ans')
     72        self.assertEqual(
     73            urlunquote(u'Paris%20&%20Orl%C3%A9ans'),
     74            u'Paris & Orl\xe9ans')
    6875        self.assertEqual(urlquote_plus(u'Paris & Orl\xe9ans'),
    6976            u'Paris+%26+Orl%C3%A9ans')
    7077        self.assertEqual(urlquote_plus(u'Paris & Orl\xe9ans', safe="&"),
    7178            u'Paris+&+Orl%C3%A9ans')
     79        self.assertEqual(
     80            urlunquote_plus(u'Paris+%26+Orl%C3%A9ans'),
     81            u'Paris & Orl\xe9ans')
     82        self.assertEqual(
     83            urlunquote_plus(u'Paris+&+Orl%C3%A9ans'),
     84            u'Paris & Orl\xe9ans')
     85
    7286
    7387    def test_cookie_date(self):
    7488        t = 1167616461.0
Back to Top