1
0
mirror of https://github.com/django/django.git synced 2025-10-26 07:06:08 +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

@@ -41,7 +41,7 @@ from django.test.utils import (get_warnings_state, restore_warnings_state,
override_settings)
from django.test.utils import ContextList
from django.utils import unittest as ut2
from django.utils.encoding import smart_str, force_unicode
from django.utils.encoding import smart_bytes, force_text
from django.utils import six
from django.utils.unittest.util import safe_repr
from django.views.static import serve
@@ -398,7 +398,7 @@ class SimpleTestCase(ut2.TestCase):
optional.clean(input)
self.assertEqual(context_manager.exception.messages, errors)
# test required inputs
error_required = [force_unicode(required.error_messages['required'])]
error_required = [force_text(required.error_messages['required'])]
for e in EMPTY_VALUES:
with self.assertRaises(ValidationError) as context_manager:
required.clean(e)
@@ -647,7 +647,7 @@ class TransactionTestCase(SimpleTestCase):
self.assertEqual(response.status_code, status_code,
msg_prefix + "Couldn't retrieve content: Response code was %d"
" (expected %d)" % (response.status_code, status_code))
enc_text = smart_str(text, response._charset)
enc_text = smart_bytes(text, response._charset)
content = response.content
if html:
content = assert_and_parse_html(self, content, None,
@@ -683,7 +683,7 @@ class TransactionTestCase(SimpleTestCase):
self.assertEqual(response.status_code, status_code,
msg_prefix + "Couldn't retrieve content: Response code was %d"
" (expected %d)" % (response.status_code, status_code))
enc_text = smart_str(text, response._charset)
enc_text = smart_bytes(text, response._charset)
content = response.content
if html:
content = assert_and_parse_html(self, content, None,