diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2012-07-20 14:48:51 +0200 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2012-07-22 09:29:54 +0200 |
| commit | bdca5ea345c548a82a80d198906818c9ccbef896 (patch) | |
| tree | 5c3f5fe5ad2522175d67b96a1fce1ff1763ba125 /django/template | |
| parent | 3cb2457f46b3e40ff6b6acffcb3fd44cbea091e5 (diff) | |
[py3] Replaced unicode/str by six.text_type/bytes.
Diffstat (limited to 'django/template')
| -rw-r--r-- | django/template/base.py | 2 | ||||
| -rw-r--r-- | django/template/defaultfilters.py | 9 |
2 files changed, 6 insertions, 5 deletions
diff --git a/django/template/base.py b/django/template/base.py index cbf6de2d40..489b1681e0 100644 --- a/django/template/base.py +++ b/django/template/base.py @@ -86,7 +86,7 @@ class VariableDoesNotExist(Exception): self.params = params def __str__(self): - return unicode(self).encode('utf-8') + return six.text_type(self).encode('utf-8') def __unicode__(self): return self.msg % tuple([force_unicode(p, errors='replace') diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index b9cdd94296..fa799cd46f 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -18,6 +18,7 @@ from django.utils.html import (conditional_escape, escapejs, fix_ampersands, from django.utils.http import urlquote from django.utils.text import Truncator, wrap, phone2numeric from django.utils.safestring import mark_safe, SafeData, mark_for_escaping +from django.utils import six from django.utils.timesince import timesince, timeuntil from django.utils.translation import ugettext, ungettext from django.utils.text import normalize_newlines @@ -176,7 +177,7 @@ def floatformat(text, arg=-1): # and `exponent` from `Decimal.as_tuple()` directly. sign, digits, exponent = d.quantize(exp, ROUND_HALF_UP, Context(prec=prec)).as_tuple() - digits = [unicode(digit) for digit in reversed(digits)] + digits = [six.text_type(digit) for digit in reversed(digits)] while len(digits) <= abs(exponent): digits.append('0') digits.insert(-exponent, '.') @@ -200,7 +201,7 @@ def linenumbers(value, autoescape=None): lines = value.split('\n') # Find the maximum width of the line count, for use with zero padding # string format command - width = unicode(len(unicode(len(lines)))) + width = six.text_type(len(six.text_type(len(lines)))) if not autoescape or isinstance(value, SafeData): for i, line in enumerate(lines): lines[i] = ("%0" + width + "d. %s") % (i + 1, line) @@ -234,7 +235,7 @@ def slugify(value): and converts spaces to hyphens. """ value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore') - value = unicode(re.sub('[^\w\s-]', '', value).strip().lower()) + value = six.text_type(re.sub('[^\w\s-]', '', value).strip().lower()) return mark_safe(re.sub('[-\s]+', '-', value)) @register.filter(is_safe=True) @@ -249,7 +250,7 @@ def stringformat(value, arg): of Python string formatting """ try: - return ("%" + unicode(arg)) % value + return ("%" + six.text_type(arg)) % value except (ValueError, TypeError): return "" |
