Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
|
|
|
import urllib
|
|
|
|
from django.utils.encoding import smart_str, force_unicode
|
|
|
|
from django.utils.functional import allow_lazy
|
|
|
|
|
|
|
|
def urlquote(url, safe='/'):
|
|
|
|
"""
|
|
|
|
A version of Python's urllib.quote() function that can operate on unicode
|
|
|
|
strings. The url is first UTF-8 encoded before quoting. The returned string
|
|
|
|
can safely be used as part of an argument to a subsequent iri_to_uri() call
|
|
|
|
without double-quoting occurring.
|
|
|
|
"""
|
|
|
|
return force_unicode(urllib.quote(smart_str(url)))
|
|
|
|
urlquote = allow_lazy(urlquote, unicode)
|
|
|
|
|
|
|
|
def urlquote_plus(url, safe=''):
|
|
|
|
"""
|
|
|
|
A version of Python's urllib.quote_plus() function that can operate on
|
|
|
|
unicode strings. The url is first UTF-8 encoded before quoting. The
|
|
|
|
returned string can safely be used as part of an argument to a subsequent
|
|
|
|
iri_to_uri() call without double-quoting occurring.
|
|
|
|
"""
|
|
|
|
return force_unicode(urllib.quote_plus(smart_str(url), safe))
|
|
|
|
urlquote_plus = allow_lazy(urlquote_plus, unicode)
|
|
|
|
|
|
|
|
def urlencode(query, doseq=0):
|
|
|
|
"""
|
|
|
|
A version of Python's urllib.urlencode() function that can operate on
|
|
|
|
unicode strings. The parameters are first case to UTF-8 encoded strings and
|
|
|
|
then encoded as per normal.
|
|
|
|
"""
|
|
|
|
if hasattr(query, 'items'):
|
|
|
|
query = query.items()
|
2007-07-21 13:17:20 +08:00
|
|
|
return urllib.urlencode(
|
|
|
|
[(smart_str(k),
|
|
|
|
isinstance(v, (list,tuple)) and [smart_str(i) for i in v] or smart_str(v))
|
|
|
|
for k, v in query],
|
|
|
|
doseq)
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
|
|
|
|