Django

Code

Changeset 5283

Show
Ignore:
Timestamp:
05/18/07 19:17:23 (2 years ago)
Author:
mtredinnick
Message:

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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/unicode/django/template/defaultfilters.py

    r5273 r5283  
    44from django.conf import settings 
    55from django.utils.translation import ugettext, ungettext 
    6 from django.utils.encoding import smart_unicode, smart_str 
     6from django.utils.encoding import smart_unicode, smart_str, iri_to_uri 
    77import re 
    88import random as random_module 
     
    8484        formatstr = u'%%.%df' % abs(d) 
    8585        return formatstr % f 
     86 
     87def iriencode(value): 
     88    "Escapes an IRI value for use in a URL" 
     89    return smart_unicode(iri_to_uri(value)) 
     90iriencode = stringfilter(iriencode) 
    8691 
    8792def linenumbers(value): 
     
    171176    "Escapes a value for use in a URL" 
    172177    import urllib 
    173     return smart_unicode(urllib.quote(smart_str(value))) 
     178    return smart_unicode(urllib.quote(value)) 
    174179urlencode = stringfilter(urlencode) 
    175180 
     
    567572register.filter(floatformat) 
    568573register.filter(get_digit) 
     574register.filter(iriencode) 
    569575register.filter(join) 
    570576register.filter(length) 
  • django/branches/unicode/django/utils/encoding.py

    r5278 r5283  
    6767    Returns an ASCII string containing the encoded result. 
    6868    """ 
    69     return urllib.quote(smart_str(iri), safe='/#%[]') 
     69    # The list of safe characters here is constructed from the printable ASCII 
     70    # characters that are not explicitly excluded by the list at the end of 
     71    # section 3.1 of RFC 3987. 
     72    return urllib.quote(smart_str(iri), safe='/#%[]=:;$&()+,!?') 
    7073 
  • django/branches/unicode/tests/regressiontests/defaultfilters/tests.py

    r5273 r5283  
    116116>>> urlencode(1) 
    117117u'1' 
    118 >>> urlencode(u'S\xf8r-Tr\xf8ndelag') 
     118>>> iriencode(u'S\xf8r-Tr\xf8ndelag') 
    119119u'S%C3%B8r-Tr%C3%B8ndelag' 
    120120