1
0
mirror of https://github.com/django/django.git synced 2025-10-29 08:36:09 +00:00

[py3] Ported django.utils.encoding.

* Renamed smart_unicode to smart_text (but kept the old name under
  Python 2 for backwards compatibility).
* Renamed smart_str to smart_bytes.
* Re-introduced smart_str as an alias for smart_text under Python 3
  and smart_bytes under Python 2 (which is backwards compatible).
  Thus smart_str always returns a str objects.
* Used the new smart_str in a few places where both Python 2 and 3
  want a str.
This commit is contained in:
Aymeric Augustin
2012-07-21 10:00:10 +02:00
parent ee191715ea
commit c5ef65bcf3
125 changed files with 629 additions and 583 deletions

View File

@@ -3,7 +3,7 @@ from __future__ import unicode_literals
import json
from django.db import models
from django.utils.encoding import force_unicode
from django.utils.encoding import force_text
from django.utils import six
@@ -16,7 +16,7 @@ class Small(object):
self.first, self.second = first, second
def __unicode__(self):
return '%s%s' % (force_unicode(self.first), force_unicode(self.second))
return '%s%s' % (force_text(self.first), force_text(self.second))
def __str__(self):
return six.text_type(self).encode('utf-8')
@@ -46,9 +46,9 @@ class SmallField(models.Field):
def get_prep_lookup(self, lookup_type, value):
if lookup_type == 'exact':
return force_unicode(value)
return force_text(value)
if lookup_type == 'in':
return [force_unicode(v) for v in value]
return [force_text(v) for v in value]
if lookup_type == 'isnull':
return []
raise TypeError('Invalid lookup type: %r' % lookup_type)