mirror of
https://github.com/django/django.git
synced 2025-07-04 09:49:12 +00:00
unicode: Fixed the urlencode filter to work with non-ASCII strings. Fixed a
similar error in HttpRedirect processing. git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5461 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
75d29fa448
commit
0b4122d138
@ -1,9 +1,9 @@
|
|||||||
import os
|
import os
|
||||||
from Cookie import SimpleCookie
|
from Cookie import SimpleCookie
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
from urllib import urlencode, quote
|
from urllib import urlencode
|
||||||
from django.utils.datastructures import MultiValueDict
|
from django.utils.datastructures import MultiValueDict
|
||||||
from django.utils.encoding import smart_str
|
from django.utils.encoding import smart_str, iri_to_uri
|
||||||
|
|
||||||
RESERVED_CHARS="!*'();:@&=+$,/?%#[]"
|
RESERVED_CHARS="!*'();:@&=+$,/?%#[]"
|
||||||
|
|
||||||
@ -334,14 +334,14 @@ class HttpResponseRedirect(HttpResponse):
|
|||||||
|
|
||||||
def __init__(self, redirect_to):
|
def __init__(self, redirect_to):
|
||||||
HttpResponse.__init__(self)
|
HttpResponse.__init__(self)
|
||||||
self['Location'] = quote(redirect_to, safe=RESERVED_CHARS)
|
self['Location'] = iri_to_uri(redirect_to)
|
||||||
|
|
||||||
class HttpResponsePermanentRedirect(HttpResponse):
|
class HttpResponsePermanentRedirect(HttpResponse):
|
||||||
status_code = 301
|
status_code = 301
|
||||||
|
|
||||||
def __init__(self, redirect_to):
|
def __init__(self, redirect_to):
|
||||||
HttpResponse.__init__(self)
|
HttpResponse.__init__(self)
|
||||||
self['Location'] = quote(redirect_to, safe=RESERVED_CHARS)
|
self['Location'] = iri_to_uri(redirect_to)
|
||||||
|
|
||||||
class HttpResponseNotModified(HttpResponse):
|
class HttpResponseNotModified(HttpResponse):
|
||||||
status_code = 304
|
status_code = 304
|
||||||
|
@ -175,8 +175,8 @@ upper = stringfilter(upper)
|
|||||||
|
|
||||||
def urlencode(value):
|
def urlencode(value):
|
||||||
"Escapes a value for use in a URL"
|
"Escapes a value for use in a URL"
|
||||||
import urllib
|
from django.utils.http import urlquote
|
||||||
return force_unicode(urllib.quote(value))
|
return urlquote(value)
|
||||||
urlencode = stringfilter(urlencode)
|
urlencode = stringfilter(urlencode)
|
||||||
|
|
||||||
def urlize(value):
|
def urlize(value):
|
||||||
|
@ -111,14 +111,14 @@ u'MIXED CASE INPUT'
|
|||||||
u'\xcb'
|
u'\xcb'
|
||||||
|
|
||||||
|
|
||||||
>>> urlencode(u'jack & jill')
|
>>> urlencode(u'fran\xe7ois & jill')
|
||||||
u'jack%20%26%20jill'
|
u'fran%C3%A7ois%20%26%20jill'
|
||||||
>>> urlencode(1)
|
>>> urlencode(1)
|
||||||
u'1'
|
u'1'
|
||||||
>>> iriencode(u'S\xf8r-Tr\xf8ndelag')
|
>>> iriencode(u'S\xf8r-Tr\xf8ndelag')
|
||||||
u'S%C3%B8r-Tr%C3%B8ndelag'
|
u'S%C3%B8r-Tr%C3%B8ndelag'
|
||||||
>>> iriencode(urlencode(u'jack & jill'))
|
>>> iriencode(urlencode(u'fran\xe7ois & jill'))
|
||||||
u'jack%20%26%20jill'
|
u'fran%C3%A7ois%20%26%20jill'
|
||||||
|
|
||||||
>>> urlizetrunc(u'http://short.com/', 20)
|
>>> urlizetrunc(u'http://short.com/', 20)
|
||||||
u'<a href="http://short.com/" rel="nofollow">http://short.com/</a>'
|
u'<a href="http://short.com/" rel="nofollow">http://short.com/</a>'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user