mirror of
https://github.com/django/django.git
synced 2025-07-04 17:59:13 +00:00
unicode: Fixed iri_to_uri() to be not quite as broken (I think it's spec
compliant now). Removed use of iri_to_uri() in the urlencode filter and made a new iriencode filter, because IRI->URI conversionis are not a superset of URL quoting converstions. git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5283 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
68a0f4f51b
commit
3d74a68a51
@ -3,7 +3,7 @@
|
|||||||
from django.template import resolve_variable, Library
|
from django.template import resolve_variable, Library
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.translation import ugettext, ungettext
|
from django.utils.translation import ugettext, ungettext
|
||||||
from django.utils.encoding import smart_unicode, smart_str
|
from django.utils.encoding import smart_unicode, smart_str, iri_to_uri
|
||||||
import re
|
import re
|
||||||
import random as random_module
|
import random as random_module
|
||||||
|
|
||||||
@ -84,6 +84,11 @@ def floatformat(text, arg=-1):
|
|||||||
formatstr = u'%%.%df' % abs(d)
|
formatstr = u'%%.%df' % abs(d)
|
||||||
return formatstr % f
|
return formatstr % f
|
||||||
|
|
||||||
|
def iriencode(value):
|
||||||
|
"Escapes an IRI value for use in a URL"
|
||||||
|
return smart_unicode(iri_to_uri(value))
|
||||||
|
iriencode = stringfilter(iriencode)
|
||||||
|
|
||||||
def linenumbers(value):
|
def linenumbers(value):
|
||||||
"Displays text with line numbers"
|
"Displays text with line numbers"
|
||||||
from django.utils.html import escape
|
from django.utils.html import escape
|
||||||
@ -170,7 +175,7 @@ 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
|
import urllib
|
||||||
return smart_unicode(urllib.quote(smart_str(value)))
|
return smart_unicode(urllib.quote(value))
|
||||||
urlencode = stringfilter(urlencode)
|
urlencode = stringfilter(urlencode)
|
||||||
|
|
||||||
def urlize(value):
|
def urlize(value):
|
||||||
@ -566,6 +571,7 @@ register.filter(first)
|
|||||||
register.filter(fix_ampersands)
|
register.filter(fix_ampersands)
|
||||||
register.filter(floatformat)
|
register.filter(floatformat)
|
||||||
register.filter(get_digit)
|
register.filter(get_digit)
|
||||||
|
register.filter(iriencode)
|
||||||
register.filter(join)
|
register.filter(join)
|
||||||
register.filter(length)
|
register.filter(length)
|
||||||
register.filter(length_is)
|
register.filter(length_is)
|
||||||
|
@ -66,5 +66,8 @@ def iri_to_uri(iri):
|
|||||||
|
|
||||||
Returns an ASCII string containing the encoded result.
|
Returns an ASCII string containing the encoded result.
|
||||||
"""
|
"""
|
||||||
return urllib.quote(smart_str(iri), safe='/#%[]')
|
# The list of safe characters here is constructed from the printable ASCII
|
||||||
|
# characters that are not explicitly excluded by the list at the end of
|
||||||
|
# section 3.1 of RFC 3987.
|
||||||
|
return urllib.quote(smart_str(iri), safe='/#%[]=:;$&()+,!?')
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ u'\xcb'
|
|||||||
u'jack%20%26%20jill'
|
u'jack%20%26%20jill'
|
||||||
>>> urlencode(1)
|
>>> urlencode(1)
|
||||||
u'1'
|
u'1'
|
||||||
>>> urlencode(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'
|
||||||
|
|
||||||
>>> urlizetrunc(u'http://short.com/', 20)
|
>>> urlizetrunc(u'http://short.com/', 20)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user