Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #5964 -- Added unicode-aware versions of urlunquote and urlunqu…

…ote_plus.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17407 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit d9061c01a975c3313a815f793cd773d3e657c3cf 1 parent 7ad7a8d
Aymeric Augustin authored January 29, 2012
17  django/utils/http.py
@@ -31,7 +31,6 @@ def urlquote(url, safe='/'):
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,6 +43,22 @@ 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 force_unicode(urllib.unquote(smart_str(quoted_url)))
  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 force_unicode(urllib.unquote_plus(smart_str(quoted_url)))
  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
16  tests/regressiontests/text/tests.py
@@ -3,7 +3,8 @@
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 (cookie_date, http_date,
  7
+    urlquote, urlquote_plus, urlunquote, urlunquote_plus)
7 8
 from django.utils.text import get_text_list, smart_split
8 9
 from django.utils.translation import override
9 10
 
@@ -60,15 +61,26 @@ def test_smart_split(self):
60 61
             [u"cut:','|cut:' '"])
61 62
 
62 63
     def test_urlquote(self):
63  
-
64 64
         self.assertEqual(urlquote(u'Paris & Orl\xe9ans'),
65 65
             u'Paris%20%26%20Orl%C3%A9ans')
66 66
         self.assertEqual(urlquote(u'Paris & Orl\xe9ans', safe="&"),
67 67
             u'Paris%20&%20Orl%C3%A9ans')
  68
+        self.assertEqual(
  69
+            urlunquote(u'Paris%20%26%20Orl%C3%A9ans'),
  70
+            u'Paris & Orl\xe9ans')
  71
+        self.assertEqual(
  72
+            urlunquote(u'Paris%20&%20Orl%C3%A9ans'),
  73
+            u'Paris & Orl\xe9ans')
68 74
         self.assertEqual(urlquote_plus(u'Paris & Orl\xe9ans'),
69 75
             u'Paris+%26+Orl%C3%A9ans')
70 76
         self.assertEqual(urlquote_plus(u'Paris & Orl\xe9ans', safe="&"),
71 77
             u'Paris+&+Orl%C3%A9ans')
  78
+        self.assertEqual(
  79
+            urlunquote_plus(u'Paris+%26+Orl%C3%A9ans'),
  80
+            u'Paris & Orl\xe9ans')
  81
+        self.assertEqual(
  82
+            urlunquote_plus(u'Paris+&+Orl%C3%A9ans'),
  83
+            u'Paris & Orl\xe9ans')
72 84
 
73 85
     def test_cookie_date(self):
74 86
         t = 1167616461.0

0 notes on commit d9061c0

Please sign in to comment.
Something went wrong with that request. Please try again.