diff -r 45c3e62075e8 django/utils/http.py
a
|
b
|
|
31 | 31 | without double-quoting occurring. |
32 | 32 | """ |
33 | 33 | return force_unicode(urllib.quote(smart_str(url), smart_str(safe))) |
34 | | |
35 | 34 | urlquote = allow_lazy(urlquote, unicode) |
36 | 35 | |
37 | 36 | def urlquote_plus(url, safe=''): |
… |
… |
|
44 | 43 | return force_unicode(urllib.quote_plus(smart_str(url), smart_str(safe))) |
45 | 44 | urlquote_plus = allow_lazy(urlquote_plus, unicode) |
46 | 45 | |
| 46 | def 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') |
| 52 | urlunquote = allow_lazy(urlunquote, unicode) |
| 53 | |
| 54 | def 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') |
| 60 | urlunquote_plus = allow_lazy(urlunquote_plus, unicode) |
| 61 | |
47 | 62 | def urlencode(query, doseq=0): |
48 | 63 | """ |
49 | 64 | A version of Python's urllib.urlencode() function that can operate on |
diff -r 45c3e62075e8 tests/regressiontests/text/tests.py
a
|
b
|
|
3 | 3 | |
4 | 4 | from django.test import TestCase |
5 | 5 | from django.utils.encoding import iri_to_uri |
6 | | from django.utils.http import urlquote, urlquote_plus, cookie_date, http_date |
| 6 | from django.utils.http import ( |
| 7 | urlquote, urlquote_plus, urlunquote, urlunquote_plus, cookie_date, |
| 8 | http_date) |
7 | 9 | from django.utils.text import get_text_list, smart_split |
8 | 10 | from django.utils.translation import override |
9 | 11 | |
… |
… |
|
60 | 62 | [u"cut:','|cut:' '"]) |
61 | 63 | |
62 | 64 | def test_urlquote(self): |
63 | | |
64 | 65 | self.assertEqual(urlquote(u'Paris & Orl\xe9ans'), |
65 | 66 | u'Paris%20%26%20Orl%C3%A9ans') |
66 | 67 | self.assertEqual(urlquote(u'Paris & Orl\xe9ans', safe="&"), |
67 | 68 | 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') |
68 | 75 | self.assertEqual(urlquote_plus(u'Paris & Orl\xe9ans'), |
69 | 76 | u'Paris+%26+Orl%C3%A9ans') |
70 | 77 | self.assertEqual(urlquote_plus(u'Paris & Orl\xe9ans', safe="&"), |
71 | 78 | 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 | |
72 | 86 | |
73 | 87 | def test_cookie_date(self): |
74 | 88 | t = 1167616461.0 |