', force_text(form[cl.model._meta.pk.name]))
class ResultList(list):
# Wrapper class used to return items in a list_editable
@@ -267,7 +267,7 @@ def result_hidden_fields(cl):
if cl.formset:
for res, form in zip(cl.result_list, cl.formset.forms):
if form[cl.model._meta.pk.name].is_hidden:
- yield mark_safe(force_unicode(form[cl.model._meta.pk.name]))
+ yield mark_safe(force_text(form[cl.model._meta.pk.name]))
@register.inclusion_tag("admin/change_list_results.html")
def result_list(cl):
diff --git a/django/contrib/admin/util.py b/django/contrib/admin/util.py
index 16bdfe0566..ff90e1d007 100644
--- a/django/contrib/admin/util.py
+++ b/django/contrib/admin/util.py
@@ -12,7 +12,7 @@ from django.utils import formats
from django.utils.html import format_html
from django.utils.text import capfirst
from django.utils import timezone
-from django.utils.encoding import force_unicode, smart_unicode, smart_str
+from django.utils.encoding import force_text, smart_text, smart_bytes
from django.utils import six
from django.utils.translation import ungettext
from django.core.urlresolvers import reverse
@@ -132,7 +132,7 @@ def get_deleted_objects(objs, opts, user, admin_site, using):
# Don't display link to edit, because it either has no
# admin or is edited inline.
return '%s: %s' % (capfirst(opts.verbose_name),
- force_unicode(obj))
+ force_text(obj))
to_delete = collector.nested(format_callback)
@@ -207,8 +207,8 @@ def model_format_dict(obj):
else:
opts = obj
return {
- 'verbose_name': force_unicode(opts.verbose_name),
- 'verbose_name_plural': force_unicode(opts.verbose_name_plural)
+ 'verbose_name': force_text(opts.verbose_name),
+ 'verbose_name_plural': force_text(opts.verbose_name_plural)
}
@@ -274,10 +274,10 @@ def label_for_field(name, model, model_admin=None, return_attr=False):
label = field.verbose_name
except models.FieldDoesNotExist:
if name == "__unicode__":
- label = force_unicode(model._meta.verbose_name)
+ label = force_text(model._meta.verbose_name)
attr = six.text_type
elif name == "__str__":
- label = smart_str(model._meta.verbose_name)
+ label = smart_bytes(model._meta.verbose_name)
attr = bytes
else:
if callable(name):
@@ -311,7 +311,7 @@ def help_text_for_field(name, model):
help_text = model._meta.get_field_by_name(name)[0].help_text
except models.FieldDoesNotExist:
help_text = ""
- return smart_unicode(help_text)
+ return smart_text(help_text)
def display_for_field(value, field):
@@ -335,7 +335,7 @@ def display_for_field(value, field):
elif isinstance(field, models.FloatField):
return formats.number_format(value)
else:
- return smart_unicode(value)
+ return smart_text(value)
def display_for_value(value, boolean=False):
@@ -353,7 +353,7 @@ def display_for_value(value, boolean=False):
elif isinstance(value, six.integer_types + (decimal.Decimal, float)):
return formats.number_format(value)
else:
- return smart_unicode(value)
+ return smart_text(value)
class NotRelationField(Exception):
diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py
index 85e03f3b75..3eabf3dbeb 100644
--- a/django/contrib/admin/views/main.py
+++ b/django/contrib/admin/views/main.py
@@ -6,7 +6,7 @@ from django.core.paginator import InvalidPage
from django.db import models
from django.db.models.fields import FieldDoesNotExist
from django.utils.datastructures import SortedDict
-from django.utils.encoding import force_unicode, smart_str
+from django.utils.encoding import force_text, smart_bytes
from django.utils.translation import ugettext, ugettext_lazy
from django.utils.http import urlencode
@@ -75,7 +75,7 @@ class ChangeList(object):
title = ugettext('Select %s')
else:
title = ugettext('Select %s to change')
- self.title = title % force_unicode(self.opts.verbose_name)
+ self.title = title % force_text(self.opts.verbose_name)
self.pk_attname = self.lookup_opts.pk.attname
def get_filters(self, request):
@@ -94,7 +94,7 @@ class ChangeList(object):
# 'key' will be used as a keyword argument later, so Python
# requires it to be a string.
del lookup_params[key]
- lookup_params[smart_str(key)] = value
+ lookup_params[smart_bytes(key)] = value
if not self.model_admin.lookup_allowed(key, value):
raise SuspiciousOperation("Filtering by %s not allowed" % key)
diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py
index 550ed0f7e2..1e0bc2d366 100644
--- a/django/contrib/admin/widgets.py
+++ b/django/contrib/admin/widgets.py
@@ -14,7 +14,7 @@ from django.utils.html import escape, format_html, format_html_join
from django.utils.text import Truncator
from django.utils.translation import ugettext as _
from django.utils.safestring import mark_safe
-from django.utils.encoding import force_unicode
+from django.utils.encoding import force_text
from django.utils import six
@@ -96,7 +96,7 @@ class AdminRadioFieldRenderer(RadioFieldRenderer):
return format_html('
\n{1}\n
',
flatatt(self.attrs),
format_html_join('\n', '
{0}
',
- ((force_unicode(w),) for w in self)))
+ ((force_text(w),) for w in self)))
class AdminRadioSelect(forms.RadioSelect):
renderer = AdminRadioFieldRenderer
@@ -197,7 +197,7 @@ class ManyToManyRawIdWidget(ForeignKeyRawIdWidget):
# The related object is registered with the same AdminSite
attrs['class'] = 'vManyToManyRawIdAdminField'
if value:
- value = ','.join([force_unicode(v) for v in value])
+ value = ','.join([force_text(v) for v in value])
else:
value = ''
return super(ManyToManyRawIdWidget, self).render(name, value, attrs)
@@ -221,7 +221,7 @@ class ManyToManyRawIdWidget(ForeignKeyRawIdWidget):
if len(initial) != len(data):
return True
for pk1, pk2 in zip(initial, data):
- if force_unicode(pk1) != force_unicode(pk2):
+ if force_text(pk1) != force_text(pk2):
return True
return False
diff --git a/django/contrib/admindocs/utils.py b/django/contrib/admindocs/utils.py
index 4bf1250ac6..0e10eb4fa3 100644
--- a/django/contrib/admindocs/utils.py
+++ b/django/contrib/admindocs/utils.py
@@ -6,7 +6,7 @@ from email.errors import HeaderParseError
from django.utils.safestring import mark_safe
from django.core.urlresolvers import reverse
-from django.utils.encoding import smart_str
+from django.utils.encoding import smart_bytes
try:
import docutils.core
import docutils.nodes
@@ -66,7 +66,7 @@ def parse_rst(text, default_reference_context, thing_being_parsed=None):
"link_base" : reverse('django-admindocs-docroot').rstrip('/')
}
if thing_being_parsed:
- thing_being_parsed = smart_str("<%s>" % thing_being_parsed)
+ thing_being_parsed = smart_bytes("<%s>" % thing_being_parsed)
parts = docutils.core.publish_parts(text, source_path=thing_being_parsed,
destination_path=None, writer_name='html',
settings_overrides=overrides)
diff --git a/django/contrib/auth/hashers.py b/django/contrib/auth/hashers.py
index 96ec40ba60..c676cf84db 100644
--- a/django/contrib/auth/hashers.py
+++ b/django/contrib/auth/hashers.py
@@ -7,7 +7,7 @@ from django.conf import settings
from django.test.signals import setting_changed
from django.utils import importlib
from django.utils.datastructures import SortedDict
-from django.utils.encoding import smart_str
+from django.utils.encoding import smart_bytes
from django.core.exceptions import ImproperlyConfigured
from django.utils.crypto import (
pbkdf2, constant_time_compare, get_random_string)
@@ -298,7 +298,7 @@ class SHA1PasswordHasher(BasePasswordHasher):
def encode(self, password, salt):
assert password
assert salt and '$' not in salt
- hash = hashlib.sha1(smart_str(salt + password)).hexdigest()
+ hash = hashlib.sha1(smart_bytes(salt + password)).hexdigest()
return "%s$%s$%s" % (self.algorithm, salt, hash)
def verify(self, password, encoded):
@@ -326,7 +326,7 @@ class MD5PasswordHasher(BasePasswordHasher):
def encode(self, password, salt):
assert password
assert salt and '$' not in salt
- hash = hashlib.md5(smart_str(salt + password)).hexdigest()
+ hash = hashlib.md5(smart_bytes(salt + password)).hexdigest()
return "%s$%s$%s" % (self.algorithm, salt, hash)
def verify(self, password, encoded):
@@ -360,7 +360,7 @@ class UnsaltedMD5PasswordHasher(BasePasswordHasher):
return ''
def encode(self, password, salt):
- return hashlib.md5(smart_str(password)).hexdigest()
+ return hashlib.md5(smart_bytes(password)).hexdigest()
def verify(self, password, encoded):
encoded_2 = self.encode(password, '')
diff --git a/django/contrib/auth/tests/forms.py b/django/contrib/auth/tests/forms.py
index 2bfe35ac88..f917ea2601 100644
--- a/django/contrib/auth/tests/forms.py
+++ b/django/contrib/auth/tests/forms.py
@@ -8,7 +8,7 @@ from django.core import mail
from django.forms.fields import Field, EmailField
from django.test import TestCase
from django.test.utils import override_settings
-from django.utils.encoding import force_unicode
+from django.utils.encoding import force_text
from django.utils import six
from django.utils import translation
from django.utils.translation import ugettext as _
@@ -28,7 +28,7 @@ class UserCreationFormTest(TestCase):
form = UserCreationForm(data)
self.assertFalse(form.is_valid())
self.assertEqual(form["username"].errors,
- [force_unicode(form.error_messages['duplicate_username'])])
+ [force_text(form.error_messages['duplicate_username'])])
def test_invalid_data(self):
data = {
@@ -39,7 +39,7 @@ class UserCreationFormTest(TestCase):
form = UserCreationForm(data)
self.assertFalse(form.is_valid())
self.assertEqual(form["username"].errors,
- [force_unicode(form.fields['username'].error_messages['invalid'])])
+ [force_text(form.fields['username'].error_messages['invalid'])])
def test_password_verification(self):
# The verification password is incorrect.
@@ -51,13 +51,13 @@ class UserCreationFormTest(TestCase):
form = UserCreationForm(data)
self.assertFalse(form.is_valid())
self.assertEqual(form["password2"].errors,
- [force_unicode(form.error_messages['password_mismatch'])])
+ [force_text(form.error_messages['password_mismatch'])])
def test_both_passwords(self):
# One (or both) passwords weren't given
data = {'username': 'jsmith'}
form = UserCreationForm(data)
- required_error = [force_unicode(Field.default_error_messages['required'])]
+ required_error = [force_text(Field.default_error_messages['required'])]
self.assertFalse(form.is_valid())
self.assertEqual(form['password1'].errors, required_error)
self.assertEqual(form['password2'].errors, required_error)
@@ -96,7 +96,7 @@ class AuthenticationFormTest(TestCase):
form = AuthenticationForm(None, data)
self.assertFalse(form.is_valid())
self.assertEqual(form.non_field_errors(),
- [force_unicode(form.error_messages['invalid_login'])])
+ [force_text(form.error_messages['invalid_login'])])
def test_inactive_user(self):
# The user is inactive.
@@ -107,7 +107,7 @@ class AuthenticationFormTest(TestCase):
form = AuthenticationForm(None, data)
self.assertFalse(form.is_valid())
self.assertEqual(form.non_field_errors(),
- [force_unicode(form.error_messages['inactive'])])
+ [force_text(form.error_messages['inactive'])])
def test_inactive_user_i18n(self):
with self.settings(USE_I18N=True):
@@ -120,7 +120,7 @@ class AuthenticationFormTest(TestCase):
form = AuthenticationForm(None, data)
self.assertFalse(form.is_valid())
self.assertEqual(form.non_field_errors(),
- [force_unicode(form.error_messages['inactive'])])
+ [force_text(form.error_messages['inactive'])])
def test_success(self):
# The success case
@@ -148,7 +148,7 @@ class SetPasswordFormTest(TestCase):
form = SetPasswordForm(user, data)
self.assertFalse(form.is_valid())
self.assertEqual(form["new_password2"].errors,
- [force_unicode(form.error_messages['password_mismatch'])])
+ [force_text(form.error_messages['password_mismatch'])])
def test_success(self):
user = User.objects.get(username='testclient')
@@ -175,7 +175,7 @@ class PasswordChangeFormTest(TestCase):
form = PasswordChangeForm(user, data)
self.assertFalse(form.is_valid())
self.assertEqual(form["old_password"].errors,
- [force_unicode(form.error_messages['password_incorrect'])])
+ [force_text(form.error_messages['password_incorrect'])])
def test_password_verification(self):
# The two new passwords do not match.
@@ -188,7 +188,7 @@ class PasswordChangeFormTest(TestCase):
form = PasswordChangeForm(user, data)
self.assertFalse(form.is_valid())
self.assertEqual(form["new_password2"].errors,
- [force_unicode(form.error_messages['password_mismatch'])])
+ [force_text(form.error_messages['password_mismatch'])])
def test_success(self):
# The success case.
@@ -219,7 +219,7 @@ class UserChangeFormTest(TestCase):
form = UserChangeForm(data, instance=user)
self.assertFalse(form.is_valid())
self.assertEqual(form['username'].errors,
- [force_unicode(form.fields['username'].error_messages['invalid'])])
+ [force_text(form.fields['username'].error_messages['invalid'])])
def test_bug_14242(self):
# A regression test, introduce by adding an optimization for the
@@ -274,7 +274,7 @@ class PasswordResetFormTest(TestCase):
form = PasswordResetForm(data)
self.assertFalse(form.is_valid())
self.assertEqual(form['email'].errors,
- [force_unicode(EmailField.default_error_messages['invalid'])])
+ [force_text(EmailField.default_error_messages['invalid'])])
def test_nonexistant_email(self):
# Test nonexistant email address
@@ -282,7 +282,7 @@ class PasswordResetFormTest(TestCase):
form = PasswordResetForm(data)
self.assertFalse(form.is_valid())
self.assertEqual(form.errors,
- {'email': [force_unicode(form.error_messages['unknown'])]})
+ {'email': [force_text(form.error_messages['unknown'])]})
def test_cleaned_data(self):
# Regression test
diff --git a/django/contrib/auth/tests/views.py b/django/contrib/auth/tests/views.py
index e76e7dd10f..3c847f456a 100644
--- a/django/contrib/auth/tests/views.py
+++ b/django/contrib/auth/tests/views.py
@@ -7,7 +7,7 @@ from django.contrib.auth.models import User
from django.core import mail
from django.core.urlresolvers import reverse, NoReverseMatch
from django.http import QueryDict
-from django.utils.encoding import force_unicode
+from django.utils.encoding import force_text
from django.utils.html import escape
from django.utils.http import urlquote
from django.test import TestCase
@@ -46,7 +46,7 @@ class AuthViewsTestCase(TestCase):
self.assertTrue(SESSION_KEY in self.client.session)
def assertContainsEscaped(self, response, text, **kwargs):
- return self.assertContains(response, escape(force_unicode(text)), **kwargs)
+ return self.assertContains(response, escape(force_text(text)), **kwargs)
class AuthViewNamedURLTests(AuthViewsTestCase):
diff --git a/django/contrib/comments/forms.py b/django/contrib/comments/forms.py
index 830e24bca9..bd254d2733 100644
--- a/django/contrib/comments/forms.py
+++ b/django/contrib/comments/forms.py
@@ -5,7 +5,7 @@ from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.contrib.comments.models import Comment
from django.utils.crypto import salted_hmac, constant_time_compare
-from django.utils.encoding import force_unicode
+from django.utils.encoding import force_text
from django.utils.text import get_text_list
from django.utils import timezone
from django.utils.translation import ungettext, ugettext, ugettext_lazy as _
@@ -133,7 +133,7 @@ class CommentDetailsForm(CommentSecurityForm):
"""
return dict(
content_type = ContentType.objects.get_for_model(self.target_object),
- object_pk = force_unicode(self.target_object._get_pk_val()),
+ object_pk = force_text(self.target_object._get_pk_val()),
user_name = self.cleaned_data["name"],
user_email = self.cleaned_data["email"],
user_url = self.cleaned_data["url"],
diff --git a/django/contrib/comments/managers.py b/django/contrib/comments/managers.py
index 499feee6c3..bc0fc5f332 100644
--- a/django/contrib/comments/managers.py
+++ b/django/contrib/comments/managers.py
@@ -1,6 +1,6 @@
from django.db import models
from django.contrib.contenttypes.models import ContentType
-from django.utils.encoding import force_unicode
+from django.utils.encoding import force_text
class CommentManager(models.Manager):
@@ -18,5 +18,5 @@ class CommentManager(models.Manager):
ct = ContentType.objects.get_for_model(model)
qs = self.get_query_set().filter(content_type=ct)
if isinstance(model, models.Model):
- qs = qs.filter(object_pk=force_unicode(model._get_pk_val()))
+ qs = qs.filter(object_pk=force_text(model._get_pk_val()))
return qs
diff --git a/django/contrib/comments/templatetags/comments.py b/django/contrib/comments/templatetags/comments.py
index ce1825e529..4d4eb2322f 100644
--- a/django/contrib/comments/templatetags/comments.py
+++ b/django/contrib/comments/templatetags/comments.py
@@ -3,7 +3,7 @@ from django.template.loader import render_to_string
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.contrib import comments
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
register = template.Library()
@@ -75,7 +75,7 @@ class BaseCommentNode(template.Node):
qs = self.comment_model.objects.filter(
content_type = ctype,
- object_pk = smart_unicode(object_pk),
+ object_pk = smart_text(object_pk),
site__pk = settings.SITE_ID,
)
diff --git a/django/contrib/contenttypes/generic.py b/django/contrib/contenttypes/generic.py
index d5062cabf3..29e93eefe7 100644
--- a/django/contrib/contenttypes/generic.py
+++ b/django/contrib/contenttypes/generic.py
@@ -17,7 +17,7 @@ from django.forms import ModelForm
from django.forms.models import BaseModelFormSet, modelformset_factory, save_instance
from django.contrib.admin.options import InlineModelAdmin, flatten_fieldsets
from django.contrib.contenttypes.models import ContentType
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
class GenericForeignKey(object):
"""
@@ -169,7 +169,7 @@ class GenericRelation(RelatedField, Field):
def value_to_string(self, obj):
qs = getattr(obj, self.name).all()
- return smart_unicode([instance._get_pk_val() for instance in qs])
+ return smart_text([instance._get_pk_val() for instance in qs])
def m2m_db_table(self):
return self.rel.to._meta.db_table
diff --git a/django/contrib/contenttypes/management.py b/django/contrib/contenttypes/management.py
index 1b1c9c8562..11ca7e4763 100644
--- a/django/contrib/contenttypes/management.py
+++ b/django/contrib/contenttypes/management.py
@@ -1,6 +1,6 @@
from django.contrib.contenttypes.models import ContentType
from django.db.models import get_apps, get_models, signals
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
from django.utils import six
def update_contenttypes(app, created_models, verbosity=2, **kwargs):
@@ -31,7 +31,7 @@ def update_contenttypes(app, created_models, verbosity=2, **kwargs):
cts = ContentType.objects.bulk_create([
ContentType(
- name=smart_unicode(model._meta.verbose_name_raw),
+ name=smart_text(model._meta.verbose_name_raw),
app_label=app_label,
model=model_name,
)
diff --git a/django/contrib/contenttypes/models.py b/django/contrib/contenttypes/models.py
index 867351f6c8..e6d547a491 100644
--- a/django/contrib/contenttypes/models.py
+++ b/django/contrib/contenttypes/models.py
@@ -1,6 +1,6 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
-from django.utils.encoding import smart_unicode, force_unicode
+from django.utils.encoding import smart_text, force_text
class ContentTypeManager(models.Manager):
@@ -37,13 +37,13 @@ class ContentTypeManager(models.Manager):
try:
ct = self._get_from_cache(opts)
except KeyError:
- # Load or create the ContentType entry. The smart_unicode() is
+ # Load or create the ContentType entry. The smart_text() is
# needed around opts.verbose_name_raw because name_raw might be a
# django.utils.functional.__proxy__ object.
ct, created = self.get_or_create(
app_label = opts.app_label,
model = opts.object_name.lower(),
- defaults = {'name': smart_unicode(opts.verbose_name_raw)},
+ defaults = {'name': smart_text(opts.verbose_name_raw)},
)
self._add_to_cache(self.db, ct)
@@ -86,7 +86,7 @@ class ContentTypeManager(models.Manager):
ct = self.create(
app_label=opts.app_label,
model=opts.object_name.lower(),
- name=smart_unicode(opts.verbose_name_raw),
+ name=smart_text(opts.verbose_name_raw),
)
self._add_to_cache(self.db, ct)
results[ct.model_class()] = ct
@@ -147,7 +147,7 @@ class ContentType(models.Model):
if not model or self.name != model._meta.verbose_name_raw:
return self.name
else:
- return force_unicode(model._meta.verbose_name)
+ return force_text(model._meta.verbose_name)
def model_class(self):
"Returns the Python model class for this type of content."
diff --git a/django/contrib/databrowse/datastructures.py b/django/contrib/databrowse/datastructures.py
index 95d347cac0..810e039894 100644
--- a/django/contrib/databrowse/datastructures.py
+++ b/django/contrib/databrowse/datastructures.py
@@ -7,7 +7,7 @@ from __future__ import unicode_literals
from django.db import models
from django.utils import formats
from django.utils.text import capfirst
-from django.utils.encoding import smart_unicode, smart_str, iri_to_uri
+from django.utils.encoding import smart_text, smart_bytes, iri_to_uri
from django.db.models.query import QuerySet
EMPTY_VALUE = '(None)'
@@ -22,7 +22,7 @@ class EasyModel(object):
self.verbose_name_plural = model._meta.verbose_name_plural
def __repr__(self):
- return '' % smart_str(self.model._meta.object_name)
+ return '' % smart_bytes(self.model._meta.object_name)
def model_databrowse(self):
"Returns the ModelDatabrowse class for this model."
@@ -61,7 +61,7 @@ class EasyField(object):
self.model, self.field = easy_model, field
def __repr__(self):
- return smart_str('' % (self.model.model._meta.object_name, self.field.name))
+ return smart_bytes('' % (self.model.model._meta.object_name, self.field.name))
def choices(self):
for value, label in self.field.choices:
@@ -79,7 +79,7 @@ class EasyChoice(object):
self.value, self.label = value, label
def __repr__(self):
- return smart_str('' % (self.model.model._meta.object_name, self.field.name))
+ return smart_bytes('' % (self.model.model._meta.object_name, self.field.name))
def url(self):
return '%s%s/%s/%s/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name, self.field.field.name, iri_to_uri(self.value))
@@ -89,10 +89,10 @@ class EasyInstance(object):
self.model, self.instance = easy_model, instance
def __repr__(self):
- return smart_str('' % (self.model.model._meta.object_name, self.instance._get_pk_val()))
+ return smart_bytes('' % (self.model.model._meta.object_name, self.instance._get_pk_val()))
def __unicode__(self):
- val = smart_unicode(self.instance)
+ val = smart_text(self.instance)
if len(val) > DISPLAY_SIZE:
return val[:DISPLAY_SIZE] + '...'
return val
@@ -136,7 +136,7 @@ class EasyInstanceField(object):
self.raw_value = getattr(instance.instance, field.name)
def __repr__(self):
- return smart_str('' % (self.model.model._meta.object_name, self.field.name))
+ return smart_bytes('' % (self.model.model._meta.object_name, self.field.name))
def values(self):
"""
@@ -185,7 +185,7 @@ class EasyInstanceField(object):
if value is None:
continue
url = '%s%s/%s/objects/%s/' % (self.model.site.root_url, m.model._meta.app_label, m.model._meta.module_name, iri_to_uri(value._get_pk_val()))
- lst.append((smart_unicode(value), url))
+ lst.append((smart_text(value), url))
else:
lst = [(value, None) for value in self.values()]
elif self.field.choices:
diff --git a/django/contrib/databrowse/plugins/calendars.py b/django/contrib/databrowse/plugins/calendars.py
index 923adb90f6..a548c33c8f 100644
--- a/django/contrib/databrowse/plugins/calendars.py
+++ b/django/contrib/databrowse/plugins/calendars.py
@@ -7,7 +7,7 @@ from django.contrib.databrowse.sites import DatabrowsePlugin
from django.shortcuts import render_to_response
from django.utils.html import format_html, format_html_join
from django.utils.text import capfirst
-from django.utils.encoding import force_unicode
+from django.utils.encoding import force_text
from django.views.generic import dates
from django.utils import datetime_safe
@@ -66,7 +66,7 @@ class CalendarPlugin(DatabrowsePlugin):
return ''
return format_html('
View calendar by: {0}
',
format_html_join(', ', '{1}',
- ((f.name, force_unicode(capfirst(f.verbose_name))) for f in fields.values())))
+ ((f.name, force_text(capfirst(f.verbose_name))) for f in fields.values())))
def urls(self, plugin_name, easy_instance_field):
if isinstance(easy_instance_field.field, models.DateField):
diff --git a/django/contrib/databrowse/plugins/fieldchoices.py b/django/contrib/databrowse/plugins/fieldchoices.py
index 73298b8d56..dc5e9aef14 100644
--- a/django/contrib/databrowse/plugins/fieldchoices.py
+++ b/django/contrib/databrowse/plugins/fieldchoices.py
@@ -8,7 +8,7 @@ from django.shortcuts import render_to_response
from django.utils.html import format_html, format_html_join
from django.utils.http import urlquote
from django.utils.text import capfirst
-from django.utils.encoding import force_unicode
+from django.utils.encoding import force_text
class FieldChoicePlugin(DatabrowsePlugin):
@@ -35,7 +35,7 @@ class FieldChoicePlugin(DatabrowsePlugin):
return ''
return format_html('
View by: {0}
',
format_html_join(', ', '{1}',
- ((f.name, force_unicode(capfirst(f.verbose_name))) for f in fields.values())))
+ ((f.name, force_text(capfirst(f.verbose_name))) for f in fields.values())))
def urls(self, plugin_name, easy_instance_field):
if easy_instance_field.field in self.field_dict(easy_instance_field.model.model).values():
diff --git a/django/contrib/formtools/wizard/storage/base.py b/django/contrib/formtools/wizard/storage/base.py
index 7c802712c1..05c9f6f121 100644
--- a/django/contrib/formtools/wizard/storage/base.py
+++ b/django/contrib/formtools/wizard/storage/base.py
@@ -1,6 +1,6 @@
from django.core.files.uploadedfile import UploadedFile
from django.utils.datastructures import MultiValueDict
-from django.utils.encoding import smart_str
+from django.utils.encoding import smart_bytes
from django.utils.functional import lazy_property
from django.utils import six
@@ -74,7 +74,7 @@ class BaseStorage(object):
files = {}
for field, field_dict in six.iteritems(wizard_files):
- field_dict = dict((smart_str(k), v)
+ field_dict = dict((smart_bytes(k), v)
for k, v in six.iteritems(field_dict))
tmp_name = field_dict.pop('tmp_name')
files[field] = UploadedFile(
diff --git a/django/contrib/gis/sitemaps/views.py b/django/contrib/gis/sitemaps/views.py
index 6753b9e34a..8bcdba1b44 100644
--- a/django/contrib/gis/sitemaps/views.py
+++ b/django/contrib/gis/sitemaps/views.py
@@ -8,7 +8,7 @@ from django.core.paginator import EmptyPage, PageNotAnInteger
from django.contrib.gis.db.models.fields import GeometryField
from django.db import connections, DEFAULT_DB_ALIAS
from django.db.models import get_model
-from django.utils.encoding import smart_str
+from django.utils.encoding import smart_bytes
from django.utils import six
from django.utils.translation import ugettext as _
@@ -61,7 +61,7 @@ def sitemap(request, sitemaps, section=None):
raise Http404(_("Page %s empty") % page)
except PageNotAnInteger:
raise Http404(_("No page '%s'") % page)
- xml = smart_str(loader.render_to_string('gis/sitemaps/geo_sitemap.xml', {'urlset': urls}))
+ xml = smart_bytes(loader.render_to_string('gis/sitemaps/geo_sitemap.xml', {'urlset': urls}))
return HttpResponse(xml, content_type='application/xml')
def kml(request, label, model, field_name=None, compress=False, using=DEFAULT_DB_ALIAS):
diff --git a/django/contrib/humanize/templatetags/humanize.py b/django/contrib/humanize/templatetags/humanize.py
index 8f6c2602c9..7e8f163174 100644
--- a/django/contrib/humanize/templatetags/humanize.py
+++ b/django/contrib/humanize/templatetags/humanize.py
@@ -5,7 +5,7 @@ from datetime import date, datetime
from django import template
from django.conf import settings
from django.template import defaultfilters
-from django.utils.encoding import force_unicode
+from django.utils.encoding import force_text
from django.utils.formats import number_format
from django.utils.translation import pgettext, ungettext, ugettext as _
from django.utils.timezone import is_aware, utc
@@ -41,7 +41,7 @@ def intcomma(value, use_l10n=True):
return intcomma(value, False)
else:
return number_format(value, force_grouping=True)
- orig = force_unicode(value)
+ orig = force_text(value)
new = re.sub("^(-?\d+)(\d{3})", '\g<1>,\g<2>', orig)
if orig == new:
return new
diff --git a/django/contrib/localflavor/au/forms.py b/django/contrib/localflavor/au/forms.py
index 34170fabc8..d3a00e200c 100644
--- a/django/contrib/localflavor/au/forms.py
+++ b/django/contrib/localflavor/au/forms.py
@@ -10,7 +10,7 @@ from django.contrib.localflavor.au.au_states import STATE_CHOICES
from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
from django.forms.fields import Field, RegexField, Select
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
from django.utils.translation import ugettext_lazy as _
@@ -44,7 +44,7 @@ class AUPhoneNumberField(Field):
super(AUPhoneNumberField, self).clean(value)
if value in EMPTY_VALUES:
return ''
- value = re.sub('(\(|\)|\s+|-)', '', smart_unicode(value))
+ value = re.sub('(\(|\)|\s+|-)', '', smart_text(value))
phone_match = PHONE_DIGITS_RE.search(value)
if phone_match:
return '%s' % phone_match.group(1)
diff --git a/django/contrib/localflavor/br/forms.py b/django/contrib/localflavor/br/forms.py
index f287d46a9a..4d0d6815ba 100644
--- a/django/contrib/localflavor/br/forms.py
+++ b/django/contrib/localflavor/br/forms.py
@@ -11,7 +11,7 @@ from django.contrib.localflavor.br.br_states import STATE_CHOICES
from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
from django.forms.fields import Field, RegexField, CharField, Select
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
from django.utils.translation import ugettext_lazy as _
@@ -35,7 +35,7 @@ class BRPhoneNumberField(Field):
super(BRPhoneNumberField, self).clean(value)
if value in EMPTY_VALUES:
return ''
- value = re.sub('(\(|\)|\s+)', '', smart_unicode(value))
+ value = re.sub('(\(|\)|\s+)', '', smart_text(value))
m = phone_digits_re.search(value)
if m:
return '%s-%s-%s' % (m.group(1), m.group(2), m.group(3))
@@ -68,10 +68,10 @@ class BRStateChoiceField(Field):
value = super(BRStateChoiceField, self).clean(value)
if value in EMPTY_VALUES:
value = ''
- value = smart_unicode(value)
+ value = smart_text(value)
if value == '':
return value
- valid_values = set([smart_unicode(k) for k, v in self.widget.choices])
+ valid_values = set([smart_text(k) for k, v in self.widget.choices])
if value not in valid_values:
raise ValidationError(self.error_messages['invalid'])
return value
diff --git a/django/contrib/localflavor/ca/forms.py b/django/contrib/localflavor/ca/forms.py
index daa40044f9..4ebfb06c2b 100644
--- a/django/contrib/localflavor/ca/forms.py
+++ b/django/contrib/localflavor/ca/forms.py
@@ -9,7 +9,7 @@ import re
from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
from django.forms.fields import Field, CharField, Select
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
from django.utils.translation import ugettext_lazy as _
@@ -53,7 +53,7 @@ class CAPhoneNumberField(Field):
super(CAPhoneNumberField, self).clean(value)
if value in EMPTY_VALUES:
return ''
- value = re.sub('(\(|\)|\s+)', '', smart_unicode(value))
+ value = re.sub('(\(|\)|\s+)', '', smart_text(value))
m = phone_digits_re.search(value)
if m:
return '%s-%s-%s' % (m.group(1), m.group(2), m.group(3))
diff --git a/django/contrib/localflavor/ch/forms.py b/django/contrib/localflavor/ch/forms.py
index e844a3c57c..bf71eeea32 100644
--- a/django/contrib/localflavor/ch/forms.py
+++ b/django/contrib/localflavor/ch/forms.py
@@ -10,7 +10,7 @@ from django.contrib.localflavor.ch.ch_states import STATE_CHOICES
from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
from django.forms.fields import Field, RegexField, Select
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
from django.utils.translation import ugettext_lazy as _
@@ -41,7 +41,7 @@ class CHPhoneNumberField(Field):
super(CHPhoneNumberField, self).clean(value)
if value in EMPTY_VALUES:
return ''
- value = re.sub('(\.|\s|/|-)', '', smart_unicode(value))
+ value = re.sub('(\.|\s|/|-)', '', smart_text(value))
m = phone_digits_re.search(value)
if m:
return '%s %s %s %s' % (value[0:3], value[3:6], value[6:8], value[8:10])
diff --git a/django/contrib/localflavor/cl/forms.py b/django/contrib/localflavor/cl/forms.py
index 5991176382..a5340141ce 100644
--- a/django/contrib/localflavor/cl/forms.py
+++ b/django/contrib/localflavor/cl/forms.py
@@ -8,7 +8,7 @@ from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
from django.forms.fields import RegexField, Select
from django.utils.translation import ugettext_lazy as _
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
from .cl_regions import REGION_CHOICES
@@ -75,7 +75,7 @@ class CLRutField(RegexField):
Turns the RUT into one normalized format. Returns a (rut, verifier)
tuple.
"""
- rut = smart_unicode(rut).replace(' ', '').replace('.', '').replace('-', '')
+ rut = smart_text(rut).replace(' ', '').replace('.', '').replace('-', '')
return rut[:-1], rut[-1].upper()
def _format(self, code, verifier=None):
diff --git a/django/contrib/localflavor/fr/forms.py b/django/contrib/localflavor/fr/forms.py
index d836dd6397..8b841fff5f 100644
--- a/django/contrib/localflavor/fr/forms.py
+++ b/django/contrib/localflavor/fr/forms.py
@@ -9,7 +9,7 @@ from django.contrib.localflavor.fr.fr_department import DEPARTMENT_CHOICES
from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
from django.forms.fields import CharField, RegexField, Select
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
from django.utils.translation import ugettext_lazy as _
@@ -43,7 +43,7 @@ class FRPhoneNumberField(CharField):
super(FRPhoneNumberField, self).clean(value)
if value in EMPTY_VALUES:
return ''
- value = re.sub('(\.|\s)', '', smart_unicode(value))
+ value = re.sub('(\.|\s)', '', smart_text(value))
m = phone_digits_re.search(value)
if m:
return '%s %s %s %s %s' % (value[0:2], value[2:4], value[4:6], value[6:8], value[8:10])
diff --git a/django/contrib/localflavor/hk/forms.py b/django/contrib/localflavor/hk/forms.py
index 8cf9360e19..ab4f70f193 100644
--- a/django/contrib/localflavor/hk/forms.py
+++ b/django/contrib/localflavor/hk/forms.py
@@ -8,7 +8,7 @@ import re
from django.core.validators import EMPTY_VALUES
from django.forms import CharField
from django.forms import ValidationError
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
from django.utils.translation import ugettext_lazy as _
@@ -53,7 +53,7 @@ class HKPhoneNumberField(CharField):
if value in EMPTY_VALUES:
return ''
- value = re.sub('(\(|\)|\s+|\+)', '', smart_unicode(value))
+ value = re.sub('(\(|\)|\s+|\+)', '', smart_text(value))
m = hk_phone_digits_re.search(value)
if not m:
raise ValidationError(self.error_messages['invalid'])
diff --git a/django/contrib/localflavor/hr/forms.py b/django/contrib/localflavor/hr/forms.py
index eb4436a78c..b935fd8a3a 100644
--- a/django/contrib/localflavor/hr/forms.py
+++ b/django/contrib/localflavor/hr/forms.py
@@ -12,7 +12,7 @@ from django.contrib.localflavor.hr.hr_choices import (
from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
from django.forms.fields import Field, Select, RegexField
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
from django.utils.translation import ugettext_lazy as _
@@ -159,7 +159,7 @@ class HRLicensePlateField(Field):
if value in EMPTY_VALUES:
return ''
- value = re.sub(r'[\s\-]+', '', smart_unicode(value.strip())).upper()
+ value = re.sub(r'[\s\-]+', '', smart_text(value.strip())).upper()
matches = plate_re.search(value)
if matches is None:
@@ -225,7 +225,7 @@ class HRPhoneNumberField(Field):
if value in EMPTY_VALUES:
return ''
- value = re.sub(r'[\-\s\(\)]', '', smart_unicode(value))
+ value = re.sub(r'[\-\s\(\)]', '', smart_text(value))
matches = phone_re.search(value)
if matches is None:
diff --git a/django/contrib/localflavor/id/forms.py b/django/contrib/localflavor/id/forms.py
index f22b06134e..2005dbc75c 100644
--- a/django/contrib/localflavor/id/forms.py
+++ b/django/contrib/localflavor/id/forms.py
@@ -11,7 +11,7 @@ from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
from django.forms.fields import Field, Select
from django.utils.translation import ugettext_lazy as _
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
postcode_re = re.compile(r'^[1-9]\d{4}$')
@@ -77,10 +77,10 @@ class IDPhoneNumberField(Field):
if value in EMPTY_VALUES:
return ''
- phone_number = re.sub(r'[\-\s\(\)]', '', smart_unicode(value))
+ phone_number = re.sub(r'[\-\s\(\)]', '', smart_text(value))
if phone_re.search(phone_number):
- return smart_unicode(value)
+ return smart_text(value)
raise ValidationError(self.error_messages['invalid'])
@@ -120,7 +120,7 @@ class IDLicensePlateField(Field):
return ''
plate_number = re.sub(r'\s+', ' ',
- smart_unicode(value.strip())).upper()
+ smart_text(value.strip())).upper()
matches = plate_re.search(plate_number)
if matches is None:
@@ -181,7 +181,7 @@ class IDNationalIdentityNumberField(Field):
if value in EMPTY_VALUES:
return ''
- value = re.sub(r'[\s.]', '', smart_unicode(value))
+ value = re.sub(r'[\s.]', '', smart_text(value))
if not nik_re.search(value):
raise ValidationError(self.error_messages['invalid'])
diff --git a/django/contrib/localflavor/in_/forms.py b/django/contrib/localflavor/in_/forms.py
index b62ec7bdb2..5c1d009ef4 100644
--- a/django/contrib/localflavor/in_/forms.py
+++ b/django/contrib/localflavor/in_/forms.py
@@ -10,7 +10,7 @@ from django.contrib.localflavor.in_.in_states import STATES_NORMALIZED, STATE_CH
from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
from django.forms.fields import Field, RegexField, CharField, Select
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
from django.utils.translation import ugettext_lazy as _
@@ -74,7 +74,7 @@ class INStateField(Field):
pass
else:
try:
- return smart_unicode(STATES_NORMALIZED[value.strip().lower()])
+ return smart_text(STATES_NORMALIZED[value.strip().lower()])
except KeyError:
pass
raise ValidationError(self.error_messages['invalid'])
@@ -107,7 +107,7 @@ class INPhoneNumberField(CharField):
super(INPhoneNumberField, self).clean(value)
if value in EMPTY_VALUES:
return ''
- value = smart_unicode(value)
+ value = smart_text(value)
m = phone_digits_re.match(value)
if m:
return '%s' % (value)
diff --git a/django/contrib/localflavor/is_/forms.py b/django/contrib/localflavor/is_/forms.py
index 7af9f51cfb..1ae3e012a1 100644
--- a/django/contrib/localflavor/is_/forms.py
+++ b/django/contrib/localflavor/is_/forms.py
@@ -9,7 +9,7 @@ from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
from django.forms.fields import RegexField
from django.forms.widgets import Select
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
from django.utils.translation import ugettext_lazy as _
@@ -58,7 +58,7 @@ class ISIdNumberField(RegexField):
Takes in the value in canonical form and returns it in the common
display format.
"""
- return smart_unicode(value[:6]+'-'+value[6:])
+ return smart_text(value[:6]+'-'+value[6:])
class ISPhoneNumberField(RegexField):
"""
diff --git a/django/contrib/localflavor/it/forms.py b/django/contrib/localflavor/it/forms.py
index 60b1eff951..916ce9bb3d 100644
--- a/django/contrib/localflavor/it/forms.py
+++ b/django/contrib/localflavor/it/forms.py
@@ -13,7 +13,7 @@ from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
from django.forms.fields import Field, RegexField, Select
from django.utils.translation import ugettext_lazy as _
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
class ITZipCodeField(RegexField):
@@ -85,4 +85,4 @@ class ITVatNumberField(Field):
check_digit = vat_number_check_digit(vat_number[0:10])
if not vat_number[10] == check_digit:
raise ValidationError(self.error_messages['invalid'])
- return smart_unicode(vat_number)
+ return smart_text(vat_number)
diff --git a/django/contrib/localflavor/it/util.py b/django/contrib/localflavor/it/util.py
index ec1b7e3f83..e1aa9c0419 100644
--- a/django/contrib/localflavor/it/util.py
+++ b/django/contrib/localflavor/it/util.py
@@ -1,4 +1,4 @@
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
def ssn_check_digit(value):
"Calculate Italian social security number check digit."
@@ -34,11 +34,11 @@ def ssn_check_digit(value):
def vat_number_check_digit(vat_number):
"Calculate Italian VAT number check digit."
- normalized_vat_number = smart_unicode(vat_number).zfill(10)
+ normalized_vat_number = smart_text(vat_number).zfill(10)
total = 0
for i in range(0, 10, 2):
total += int(normalized_vat_number[i])
for i in range(1, 11, 2):
quotient , remainder = divmod(int(normalized_vat_number[i]) * 2, 10)
total += quotient + remainder
- return smart_unicode((10 - total % 10) % 10)
+ return smart_text((10 - total % 10) % 10)
diff --git a/django/contrib/localflavor/nl/forms.py b/django/contrib/localflavor/nl/forms.py
index bdd769bd39..a05dd38f7f 100644
--- a/django/contrib/localflavor/nl/forms.py
+++ b/django/contrib/localflavor/nl/forms.py
@@ -10,7 +10,7 @@ from django.contrib.localflavor.nl.nl_provinces import PROVINCE_CHOICES
from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
from django.forms.fields import Field, Select
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
from django.utils.translation import ugettext_lazy as _
@@ -61,7 +61,7 @@ class NLPhoneNumberField(Field):
if value in EMPTY_VALUES:
return ''
- phone_nr = re.sub('[\-\s\(\)]', '', smart_unicode(value))
+ phone_nr = re.sub('[\-\s\(\)]', '', smart_text(value))
if len(phone_nr) == 10 and numeric_re.search(phone_nr):
return value
diff --git a/django/contrib/localflavor/pt/forms.py b/django/contrib/localflavor/pt/forms.py
index b27fb577bd..01cdd101b2 100644
--- a/django/contrib/localflavor/pt/forms.py
+++ b/django/contrib/localflavor/pt/forms.py
@@ -8,7 +8,7 @@ import re
from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
from django.forms.fields import Field, RegexField
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
from django.utils.translation import ugettext_lazy as _
phone_digits_re = re.compile(r'^(\d{9}|(00|\+)\d*)$')
@@ -29,7 +29,7 @@ class PTZipCodeField(RegexField):
return '%s-%s' % (cleaned[:4],cleaned[4:])
else:
return cleaned
-
+
class PTPhoneNumberField(Field):
"""
Validate local Portuguese phone number (including international ones)
@@ -43,7 +43,7 @@ class PTPhoneNumberField(Field):
super(PTPhoneNumberField, self).clean(value)
if value in EMPTY_VALUES:
return ''
- value = re.sub('(\.|\s)', '', smart_unicode(value))
+ value = re.sub('(\.|\s)', '', smart_text(value))
m = phone_digits_re.search(value)
if m:
return '%s' % value
diff --git a/django/contrib/localflavor/tr/forms.py b/django/contrib/localflavor/tr/forms.py
index 15bc1f99bb..c4f928e670 100644
--- a/django/contrib/localflavor/tr/forms.py
+++ b/django/contrib/localflavor/tr/forms.py
@@ -10,7 +10,7 @@ from django.contrib.localflavor.tr.tr_provinces import PROVINCE_CHOICES
from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
from django.forms.fields import Field, RegexField, Select, CharField
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
from django.utils.translation import ugettext_lazy as _
@@ -46,7 +46,7 @@ class TRPhoneNumberField(CharField):
super(TRPhoneNumberField, self).clean(value)
if value in EMPTY_VALUES:
return ''
- value = re.sub('(\(|\)|\s+)', '', smart_unicode(value))
+ value = re.sub('(\(|\)|\s+)', '', smart_text(value))
m = phone_digits_re.search(value)
if m:
return '%s%s' % (m.group(2), m.group(4))
diff --git a/django/contrib/localflavor/us/forms.py b/django/contrib/localflavor/us/forms.py
index ef565163cd..437bb7c466 100644
--- a/django/contrib/localflavor/us/forms.py
+++ b/django/contrib/localflavor/us/forms.py
@@ -9,7 +9,7 @@ import re
from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
from django.forms.fields import Field, RegexField, Select, CharField
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
from django.utils.translation import ugettext_lazy as _
@@ -34,7 +34,7 @@ class USPhoneNumberField(CharField):
super(USPhoneNumberField, self).clean(value)
if value in EMPTY_VALUES:
return ''
- value = re.sub('(\(|\)|\s+)', '', smart_unicode(value))
+ value = re.sub('(\(|\)|\s+)', '', smart_text(value))
m = phone_digits_re.search(value)
if m:
return '%s-%s-%s' % (m.group(1), m.group(2), m.group(3))
diff --git a/django/contrib/markup/templatetags/markup.py b/django/contrib/markup/templatetags/markup.py
index 84251cf30a..af9c842f42 100644
--- a/django/contrib/markup/templatetags/markup.py
+++ b/django/contrib/markup/templatetags/markup.py
@@ -13,7 +13,7 @@ markup syntaxes to HTML; currently there is support for:
from django import template
from django.conf import settings
-from django.utils.encoding import smart_str, force_unicode
+from django.utils.encoding import smart_bytes, force_text
from django.utils.safestring import mark_safe
register = template.Library()
@@ -25,9 +25,9 @@ def textile(value):
except ImportError:
if settings.DEBUG:
raise template.TemplateSyntaxError("Error in 'textile' filter: The Python textile library isn't installed.")
- return force_unicode(value)
+ return force_text(value)
else:
- return mark_safe(force_unicode(textile.textile(smart_str(value), encoding='utf-8', output='utf-8')))
+ return mark_safe(force_text(textile.textile(smart_bytes(value), encoding='utf-8', output='utf-8')))
@register.filter(is_safe=True)
def markdown(value, arg=''):
@@ -52,23 +52,23 @@ def markdown(value, arg=''):
except ImportError:
if settings.DEBUG:
raise template.TemplateSyntaxError("Error in 'markdown' filter: The Python markdown library isn't installed.")
- return force_unicode(value)
+ return force_text(value)
else:
markdown_vers = getattr(markdown, "version_info", 0)
if markdown_vers < (2, 1):
if settings.DEBUG:
raise template.TemplateSyntaxError(
"Error in 'markdown' filter: Django does not support versions of the Python markdown library < 2.1.")
- return force_unicode(value)
+ return force_text(value)
else:
extensions = [e for e in arg.split(",") if e]
if extensions and extensions[0] == "safe":
extensions = extensions[1:]
return mark_safe(markdown.markdown(
- force_unicode(value), extensions, safe_mode=True, enable_attributes=False))
+ force_text(value), extensions, safe_mode=True, enable_attributes=False))
else:
return mark_safe(markdown.markdown(
- force_unicode(value), extensions, safe_mode=False))
+ force_text(value), extensions, safe_mode=False))
@register.filter(is_safe=True)
def restructuredtext(value):
@@ -77,8 +77,8 @@ def restructuredtext(value):
except ImportError:
if settings.DEBUG:
raise template.TemplateSyntaxError("Error in 'restructuredtext' filter: The Python docutils library isn't installed.")
- return force_unicode(value)
+ return force_text(value)
else:
docutils_settings = getattr(settings, "RESTRUCTUREDTEXT_FILTER_SETTINGS", {})
- parts = publish_parts(source=smart_str(value), writer_name="html4css1", settings_overrides=docutils_settings)
- return mark_safe(force_unicode(parts["fragment"]))
+ parts = publish_parts(source=smart_bytes(value), writer_name="html4css1", settings_overrides=docutils_settings)
+ return mark_safe(force_text(parts["fragment"]))
diff --git a/django/contrib/messages/storage/base.py b/django/contrib/messages/storage/base.py
index e80818e84e..5433bbff28 100644
--- a/django/contrib/messages/storage/base.py
+++ b/django/contrib/messages/storage/base.py
@@ -1,7 +1,7 @@
from __future__ import unicode_literals
from django.conf import settings
-from django.utils.encoding import force_unicode, StrAndUnicode
+from django.utils.encoding import force_text, StrAndUnicode
from django.contrib.messages import constants, utils
@@ -26,22 +26,22 @@ class Message(StrAndUnicode):
and ``extra_tags`` to unicode in case they are lazy translations.
Known "safe" types (None, int, etc.) are not converted (see Django's
- ``force_unicode`` implementation for details).
+ ``force_text`` implementation for details).
"""
- self.message = force_unicode(self.message, strings_only=True)
- self.extra_tags = force_unicode(self.extra_tags, strings_only=True)
+ self.message = force_text(self.message, strings_only=True)
+ self.extra_tags = force_text(self.extra_tags, strings_only=True)
def __eq__(self, other):
return isinstance(other, Message) and self.level == other.level and \
self.message == other.message
def __unicode__(self):
- return force_unicode(self.message)
+ return force_text(self.message)
def _get_tags(self):
- label_tag = force_unicode(LEVEL_TAGS.get(self.level, ''),
+ label_tag = force_text(LEVEL_TAGS.get(self.level, ''),
strings_only=True)
- extra_tags = force_unicode(self.extra_tags, strings_only=True)
+ extra_tags = force_text(self.extra_tags, strings_only=True)
if extra_tags and label_tag:
return ' '.join([extra_tags, label_tag])
elif extra_tags:
diff --git a/django/contrib/sessions/backends/db.py b/django/contrib/sessions/backends/db.py
index 3dd0d9516c..0cc17b44c3 100644
--- a/django/contrib/sessions/backends/db.py
+++ b/django/contrib/sessions/backends/db.py
@@ -1,7 +1,7 @@
from django.contrib.sessions.backends.base import SessionBase, CreateError
from django.core.exceptions import SuspiciousOperation
from django.db import IntegrityError, transaction, router
-from django.utils.encoding import force_unicode
+from django.utils.encoding import force_text
from django.utils import timezone
@@ -18,7 +18,7 @@ class SessionStore(SessionBase):
session_key = self.session_key,
expire_date__gt=timezone.now()
)
- return self.decode(force_unicode(s.session_data))
+ return self.decode(force_text(s.session_data))
except (Session.DoesNotExist, SuspiciousOperation):
self.create()
return {}
diff --git a/django/contrib/staticfiles/management/commands/collectstatic.py b/django/contrib/staticfiles/management/commands/collectstatic.py
index d3977213a9..45c5ecfe1f 100644
--- a/django/contrib/staticfiles/management/commands/collectstatic.py
+++ b/django/contrib/staticfiles/management/commands/collectstatic.py
@@ -6,7 +6,7 @@ from optparse import make_option
from django.core.files.storage import FileSystemStorage
from django.core.management.base import CommandError, NoArgsCommand
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
from django.utils.datastructures import SortedDict
from django.contrib.staticfiles import finders, storage
@@ -198,9 +198,9 @@ Type 'yes' to continue, or 'no' to cancel: """
fpath = os.path.join(path, f)
if self.dry_run:
self.log("Pretending to delete '%s'" %
- smart_unicode(fpath), level=1)
+ smart_text(fpath), level=1)
else:
- self.log("Deleting '%s'" % smart_unicode(fpath), level=1)
+ self.log("Deleting '%s'" % smart_text(fpath), level=1)
self.storage.delete(fpath)
for d in dirs:
self.clear_dir(os.path.join(path, d))
diff --git a/django/contrib/staticfiles/management/commands/findstatic.py b/django/contrib/staticfiles/management/commands/findstatic.py
index 772220b342..dc1e88d778 100644
--- a/django/contrib/staticfiles/management/commands/findstatic.py
+++ b/django/contrib/staticfiles/management/commands/findstatic.py
@@ -3,7 +3,7 @@ from __future__ import unicode_literals
import os
from optparse import make_option
from django.core.management.base import LabelCommand
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
from django.contrib.staticfiles import finders
@@ -19,12 +19,12 @@ class Command(LabelCommand):
def handle_label(self, path, **options):
verbosity = int(options.get('verbosity', 1))
result = finders.find(path, all=options['all'])
- path = smart_unicode(path)
+ path = smart_text(path)
if result:
if not isinstance(result, (list, tuple)):
result = [result]
output = '\n '.join(
- (smart_unicode(os.path.realpath(path)) for path in result))
+ (smart_text(os.path.realpath(path)) for path in result))
self.stdout.write("Found '%s' here:\n %s" % (path, output))
else:
if verbosity >= 1:
diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py
index a0133e1c6a..2ca54dde71 100644
--- a/django/contrib/staticfiles/storage.py
+++ b/django/contrib/staticfiles/storage.py
@@ -16,7 +16,7 @@ from django.core.exceptions import ImproperlyConfigured
from django.core.files.base import ContentFile
from django.core.files.storage import FileSystemStorage, get_storage_class
from django.utils.datastructures import SortedDict
-from django.utils.encoding import force_unicode, smart_str
+from django.utils.encoding import force_text, smart_bytes
from django.utils.functional import LazyObject
from django.utils.importlib import import_module
@@ -112,7 +112,7 @@ class CachedFilesMixin(object):
return urlunsplit(unparsed_name)
def cache_key(self, name):
- return 'staticfiles:%s' % hashlib.md5(smart_str(name)).hexdigest()
+ return 'staticfiles:%s' % hashlib.md5(smart_bytes(name)).hexdigest()
def url(self, name, force=False):
"""
@@ -248,9 +248,9 @@ class CachedFilesMixin(object):
if hashed_file_exists:
self.delete(hashed_name)
# then save the processed result
- content_file = ContentFile(smart_str(content))
+ content_file = ContentFile(smart_bytes(content))
saved_name = self._save(hashed_name, content_file)
- hashed_name = force_unicode(saved_name.replace('\\', '/'))
+ hashed_name = force_text(saved_name.replace('\\', '/'))
processed = True
else:
# or handle the case in which neither processing nor
@@ -258,7 +258,7 @@ class CachedFilesMixin(object):
if not hashed_file_exists:
processed = True
saved_name = self._save(hashed_name, original_file)
- hashed_name = force_unicode(saved_name.replace('\\', '/'))
+ hashed_name = force_text(saved_name.replace('\\', '/'))
# and then set the cache accordingly
hashed_paths[self.cache_key(name)] = hashed_name
diff --git a/django/contrib/syndication/views.py b/django/contrib/syndication/views.py
index 3c84f1f60c..bce7ef7cfb 100644
--- a/django/contrib/syndication/views.py
+++ b/django/contrib/syndication/views.py
@@ -6,7 +6,7 @@ from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
from django.http import HttpResponse, Http404
from django.template import loader, TemplateDoesNotExist, RequestContext
from django.utils import feedgenerator, tzinfo
-from django.utils.encoding import force_unicode, iri_to_uri, smart_unicode
+from django.utils.encoding import force_text, iri_to_uri, smart_text
from django.utils.html import escape
from django.utils.timezone import is_naive
@@ -43,10 +43,10 @@ class Feed(object):
def item_title(self, item):
# Titles should be double escaped by default (see #6533)
- return escape(force_unicode(item))
+ return escape(force_text(item))
def item_description(self, item):
- return force_unicode(item)
+ return force_text(item)
def item_link(self, item):
try:
@@ -154,9 +154,9 @@ class Feed(object):
enc_url = self.__get_dynamic_attr('item_enclosure_url', item)
if enc_url:
enc = feedgenerator.Enclosure(
- url = smart_unicode(enc_url),
- length = smart_unicode(self.__get_dynamic_attr('item_enclosure_length', item)),
- mime_type = smart_unicode(self.__get_dynamic_attr('item_enclosure_mime_type', item))
+ url = smart_text(enc_url),
+ length = smart_text(self.__get_dynamic_attr('item_enclosure_length', item)),
+ mime_type = smart_text(self.__get_dynamic_attr('item_enclosure_mime_type', item))
)
author_name = self.__get_dynamic_attr('item_author_name', item)
if author_name is not None:
diff --git a/django/core/cache/backends/base.py b/django/core/cache/backends/base.py
index f7573b2e31..d527e44d8b 100644
--- a/django/core/cache/backends/base.py
+++ b/django/core/cache/backends/base.py
@@ -3,7 +3,7 @@
import warnings
from django.core.exceptions import ImproperlyConfigured, DjangoRuntimeWarning
-from django.utils.encoding import smart_str
+from django.utils.encoding import smart_bytes
from django.utils.importlib import import_module
class InvalidCacheBackendError(ImproperlyConfigured):
@@ -23,7 +23,7 @@ def default_key_func(key, key_prefix, version):
the `key_prefix'. KEY_FUNCTION can be used to specify an alternate
function with custom key making behavior.
"""
- return ':'.join([key_prefix, str(version), smart_str(key)])
+ return ':'.join([key_prefix, str(version), smart_bytes(key)])
def get_key_func(key_func):
"""
@@ -62,7 +62,7 @@ class BaseCache(object):
except (ValueError, TypeError):
self._cull_frequency = 3
- self.key_prefix = smart_str(params.get('KEY_PREFIX', ''))
+ self.key_prefix = smart_bytes(params.get('KEY_PREFIX', ''))
self.version = params.get('VERSION', 1)
self.key_func = get_key_func(params.get('KEY_FUNCTION', None))
diff --git a/django/core/context_processors.py b/django/core/context_processors.py
index 325f64d224..a503270cf4 100644
--- a/django/core/context_processors.py
+++ b/django/core/context_processors.py
@@ -9,7 +9,7 @@ RequestContext.
from django.conf import settings
from django.middleware.csrf import get_token
-from django.utils.encoding import smart_str
+from django.utils.encoding import smart_bytes
from django.utils.functional import lazy
def csrf(request):
@@ -25,7 +25,7 @@ def csrf(request):
# instead of returning an empty dict.
return b'NOTPROVIDED'
else:
- return smart_str(token)
+ return smart_bytes(token)
_get_val = lazy(_get_val, str)
return {'csrf_token': _get_val() }
diff --git a/django/core/exceptions.py b/django/core/exceptions.py
index e3d1dc9c7e..f0f14cffda 100644
--- a/django/core/exceptions.py
+++ b/django/core/exceptions.py
@@ -43,7 +43,7 @@ class ValidationError(Exception):
"""An error while validating data."""
def __init__(self, message, code=None, params=None):
import operator
- from django.utils.encoding import force_unicode
+ from django.utils.encoding import force_text
"""
ValidationError can be passed any object that can be printed (usually
a string), a list of objects or a dictionary.
@@ -54,11 +54,11 @@ class ValidationError(Exception):
message = reduce(operator.add, message.values())
if isinstance(message, list):
- self.messages = [force_unicode(msg) for msg in message]
+ self.messages = [force_text(msg) for msg in message]
else:
self.code = code
self.params = params
- message = force_unicode(message)
+ message = force_text(message)
self.messages = [message]
def __str__(self):
diff --git a/django/core/files/base.py b/django/core/files/base.py
index 04853fad0c..37b1be89b3 100644
--- a/django/core/files/base.py
+++ b/django/core/files/base.py
@@ -3,7 +3,7 @@ from __future__ import unicode_literals
import os
from io import BytesIO
-from django.utils.encoding import smart_str, smart_unicode
+from django.utils.encoding import smart_bytes, smart_text
from django.core.files.utils import FileProxyMixin
class File(FileProxyMixin):
@@ -18,10 +18,10 @@ class File(FileProxyMixin):
self.mode = file.mode
def __str__(self):
- return smart_str(self.name or '')
+ return smart_bytes(self.name or '')
def __unicode__(self):
- return smart_unicode(self.name or '')
+ return smart_text(self.name or '')
def __repr__(self):
return "<%s: %s>" % (self.__class__.__name__, self or "None")
diff --git a/django/core/files/storage.py b/django/core/files/storage.py
index 5179980513..7542dcda46 100644
--- a/django/core/files/storage.py
+++ b/django/core/files/storage.py
@@ -11,7 +11,7 @@ from django.conf import settings
from django.core.exceptions import ImproperlyConfigured, SuspiciousOperation
from django.core.files import locks, File
from django.core.files.move import file_move_safe
-from django.utils.encoding import force_unicode, filepath_to_uri
+from django.utils.encoding import force_text, filepath_to_uri
from django.utils.functional import LazyObject
from django.utils.importlib import import_module
from django.utils.text import get_valid_filename
@@ -48,7 +48,7 @@ class Storage(object):
name = self._save(name, content)
# Store filenames with forward slashes, even on Windows
- return force_unicode(name.replace('\\', '/'))
+ return force_text(name.replace('\\', '/'))
# These methods are part of the public API, with default implementations.
diff --git a/django/core/files/uploadedfile.py b/django/core/files/uploadedfile.py
index 97d53482e4..3a6c632975 100644
--- a/django/core/files/uploadedfile.py
+++ b/django/core/files/uploadedfile.py
@@ -8,7 +8,7 @@ from io import BytesIO
from django.conf import settings
from django.core.files.base import File
from django.core.files import temp as tempfile
-from django.utils.encoding import smart_str
+from django.utils.encoding import smart_bytes
__all__ = ('UploadedFile', 'TemporaryUploadedFile', 'InMemoryUploadedFile',
'SimpleUploadedFile')
@@ -30,7 +30,7 @@ class UploadedFile(File):
self.charset = charset
def __repr__(self):
- return smart_str("<%s: %s (%s)>" % (
+ return smart_bytes("<%s: %s (%s)>" % (
self.__class__.__name__, self.name, self.content_type))
def _get_name(self):
diff --git a/django/core/handlers/base.py b/django/core/handlers/base.py
index 7fd7d19c4a..5a6825f0a7 100644
--- a/django/core/handlers/base.py
+++ b/django/core/handlers/base.py
@@ -4,7 +4,7 @@ import sys
from django import http
from django.core import signals
-from django.utils.encoding import force_unicode
+from django.utils.encoding import force_text
from django.utils.importlib import import_module
from django.utils.log import getLogger
from django.utils import six
@@ -250,7 +250,7 @@ def get_script_name(environ):
"""
from django.conf import settings
if settings.FORCE_SCRIPT_NAME is not None:
- return force_unicode(settings.FORCE_SCRIPT_NAME)
+ return force_text(settings.FORCE_SCRIPT_NAME)
# If Apache's mod_rewrite had a whack at the URL, Apache set either
# SCRIPT_URL or REDIRECT_URL to the full resource URL before applying any
@@ -261,5 +261,5 @@ def get_script_name(environ):
if not script_url:
script_url = environ.get('REDIRECT_URL', '')
if script_url:
- return force_unicode(script_url[:-len(environ.get('PATH_INFO', ''))])
- return force_unicode(environ.get('SCRIPT_NAME', ''))
+ return force_text(script_url[:-len(environ.get('PATH_INFO', ''))])
+ return force_text(environ.get('SCRIPT_NAME', ''))
diff --git a/django/core/handlers/wsgi.py b/django/core/handlers/wsgi.py
index 51ad2be002..70b23f8515 100644
--- a/django/core/handlers/wsgi.py
+++ b/django/core/handlers/wsgi.py
@@ -9,7 +9,7 @@ from django.core import signals
from django.core.handlers import base
from django.core.urlresolvers import set_script_prefix
from django.utils import datastructures
-from django.utils.encoding import force_unicode, smart_str, iri_to_uri
+from django.utils.encoding import force_text, smart_bytes, iri_to_uri
from django.utils.log import getLogger
logger = getLogger('django.request')
@@ -127,7 +127,7 @@ class LimitedStream(object):
class WSGIRequest(http.HttpRequest):
def __init__(self, environ):
script_name = base.get_script_name(environ)
- path_info = force_unicode(environ.get('PATH_INFO', '/'))
+ path_info = force_text(environ.get('PATH_INFO', '/'))
if not path_info or path_info == script_name:
# Sometimes PATH_INFO exists, but is empty (e.g. accessing
# the SCRIPT_NAME URL without a trailing slash). We really need to
@@ -246,5 +246,5 @@ class WSGIHandler(base.BaseHandler):
response_headers = [(str(k), str(v)) for k, v in response.items()]
for c in response.cookies.values():
response_headers.append((str('Set-Cookie'), str(c.output(header=''))))
- start_response(smart_str(status), response_headers)
+ start_response(smart_bytes(status), response_headers)
return response
diff --git a/django/core/mail/message.py b/django/core/mail/message.py
index 629ad464f9..8f589ae33d 100644
--- a/django/core/mail/message.py
+++ b/django/core/mail/message.py
@@ -15,7 +15,7 @@ from io import BytesIO
from django.conf import settings
from django.core.mail.utils import DNS_NAME
-from django.utils.encoding import smart_str, force_unicode
+from django.utils.encoding import smart_bytes, force_text
from django.utils import six
@@ -79,7 +79,7 @@ ADDRESS_HEADERS = set([
def forbid_multi_line_headers(name, val, encoding):
"""Forbids multi-line headers, to prevent header injection."""
encoding = encoding or settings.DEFAULT_CHARSET
- val = force_unicode(val)
+ val = force_text(val)
if '\n' in val or '\r' in val:
raise BadHeaderError("Header values can't contain newlines (got %r for header %r)" % (val, name))
try:
@@ -93,12 +93,12 @@ def forbid_multi_line_headers(name, val, encoding):
else:
if name.lower() == 'subject':
val = Header(val)
- return smart_str(name), val
+ return smart_bytes(name), val
def sanitize_address(addr, encoding):
if isinstance(addr, six.string_types):
- addr = parseaddr(force_unicode(addr))
+ addr = parseaddr(force_text(addr))
nm, addr = addr
nm = str(Header(nm, encoding))
try:
@@ -210,7 +210,7 @@ class EmailMessage(object):
def message(self):
encoding = self.encoding or settings.DEFAULT_CHARSET
- msg = SafeMIMEText(smart_str(self.body, encoding),
+ msg = SafeMIMEText(smart_bytes(self.body, encoding),
self.content_subtype, encoding)
msg = self._create_message(msg)
msg['Subject'] = self.subject
@@ -293,7 +293,7 @@ class EmailMessage(object):
basetype, subtype = mimetype.split('/', 1)
if basetype == 'text':
encoding = self.encoding or settings.DEFAULT_CHARSET
- attachment = SafeMIMEText(smart_str(content, encoding), subtype, encoding)
+ attachment = SafeMIMEText(smart_bytes(content, encoding), subtype, encoding)
else:
# Encode non-text attachments with base64.
attachment = MIMEBase(basetype, subtype)
diff --git a/django/core/management/commands/createcachetable.py b/django/core/management/commands/createcachetable.py
index fd6dbbbd2c..411042ee76 100644
--- a/django/core/management/commands/createcachetable.py
+++ b/django/core/management/commands/createcachetable.py
@@ -4,7 +4,7 @@ from django.core.cache.backends.db import BaseDatabaseCache
from django.core.management.base import LabelCommand, CommandError
from django.db import connections, router, transaction, models, DEFAULT_DB_ALIAS
from django.db.utils import DatabaseError
-from django.utils.encoding import force_unicode
+from django.utils.encoding import force_text
class Command(LabelCommand):
@@ -60,7 +60,7 @@ class Command(LabelCommand):
transaction.rollback_unless_managed(using=db)
raise CommandError(
"Cache table '%s' could not be created.\nThe error was: %s." %
- (tablename, force_unicode(e)))
+ (tablename, force_text(e)))
for statement in index_output:
curs.execute(statement)
transaction.commit_unless_managed(using=db)
diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py
index 34f8041d33..1896e53cee 100644
--- a/django/core/management/commands/loaddata.py
+++ b/django/core/management/commands/loaddata.py
@@ -14,7 +14,7 @@ from django.core.management.color import no_style
from django.db import (connections, router, transaction, DEFAULT_DB_ALIAS,
IntegrityError, DatabaseError)
from django.db.models import get_apps
-from django.utils.encoding import force_unicode
+from django.utils.encoding import force_text
from itertools import product
try:
@@ -189,7 +189,7 @@ class Command(BaseCommand):
'app_label': obj.object._meta.app_label,
'object_name': obj.object._meta.object_name,
'pk': obj.object.pk,
- 'error_msg': force_unicode(e)
+ 'error_msg': force_text(e)
},)
raise
diff --git a/django/core/serializers/base.py b/django/core/serializers/base.py
index 19886f7d53..78a01c7098 100644
--- a/django/core/serializers/base.py
+++ b/django/core/serializers/base.py
@@ -5,7 +5,7 @@ Module for abstract serializer/unserializer base classes.
from io import BytesIO
from django.db import models
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
from django.utils import six
class SerializerDoesNotExist(KeyError):
diff --git a/django/core/serializers/json.py b/django/core/serializers/json.py
index 8b56d0e7b8..3bac24d33a 100644
--- a/django/core/serializers/json.py
+++ b/django/core/serializers/json.py
@@ -12,7 +12,7 @@ import json
from django.core.serializers.base import DeserializationError
from django.core.serializers.python import Serializer as PythonSerializer
from django.core.serializers.python import Deserializer as PythonDeserializer
-from django.utils.encoding import smart_str
+from django.utils.encoding import smart_bytes
from django.utils import six
from django.utils.timezone import is_aware
diff --git a/django/core/serializers/python.py b/django/core/serializers/python.py
index 83c6eb6739..348ff1dada 100644
--- a/django/core/serializers/python.py
+++ b/django/core/serializers/python.py
@@ -8,7 +8,7 @@ from __future__ import unicode_literals
from django.conf import settings
from django.core.serializers import base
from django.db import models, DEFAULT_DB_ALIAS
-from django.utils.encoding import smart_unicode, is_protected_type
+from django.utils.encoding import smart_text, is_protected_type
from django.utils import six
class Serializer(base.Serializer):
@@ -34,8 +34,8 @@ class Serializer(base.Serializer):
def get_dump_object(self, obj):
return {
- "pk": smart_unicode(obj._get_pk_val(), strings_only=True),
- "model": smart_unicode(obj._meta),
+ "pk": smart_text(obj._get_pk_val(), strings_only=True),
+ "model": smart_text(obj._meta),
"fields": self._current
}
@@ -65,7 +65,7 @@ class Serializer(base.Serializer):
if self.use_natural_keys and hasattr(field.rel.to, 'natural_key'):
m2m_value = lambda value: value.natural_key()
else:
- m2m_value = lambda value: smart_unicode(value._get_pk_val(), strings_only=True)
+ m2m_value = lambda value: smart_text(value._get_pk_val(), strings_only=True)
self._current[field.name] = [m2m_value(related)
for related in getattr(obj, field.name).iterator()]
@@ -90,7 +90,7 @@ def Deserializer(object_list, **options):
# Handle each field
for (field_name, field_value) in six.iteritems(d["fields"]):
if isinstance(field_value, str):
- field_value = smart_unicode(field_value, options.get("encoding", settings.DEFAULT_CHARSET), strings_only=True)
+ field_value = smart_text(field_value, options.get("encoding", settings.DEFAULT_CHARSET), strings_only=True)
field = Model._meta.get_field(field_name)
@@ -101,9 +101,9 @@ def Deserializer(object_list, **options):
if hasattr(value, '__iter__'):
return field.rel.to._default_manager.db_manager(db).get_by_natural_key(*value).pk
else:
- return smart_unicode(field.rel.to._meta.pk.to_python(value))
+ return smart_text(field.rel.to._meta.pk.to_python(value))
else:
- m2m_convert = lambda v: smart_unicode(field.rel.to._meta.pk.to_python(v))
+ m2m_convert = lambda v: smart_text(field.rel.to._meta.pk.to_python(v))
m2m_data[field.name] = [m2m_convert(pk) for pk in field_value]
# Handle FK fields
diff --git a/django/core/serializers/pyyaml.py b/django/core/serializers/pyyaml.py
index ac0e6cf82d..9be1ea4492 100644
--- a/django/core/serializers/pyyaml.py
+++ b/django/core/serializers/pyyaml.py
@@ -12,7 +12,7 @@ from django.db import models
from django.core.serializers.base import DeserializationError
from django.core.serializers.python import Serializer as PythonSerializer
from django.core.serializers.python import Deserializer as PythonDeserializer
-from django.utils.encoding import smart_str
+from django.utils.encoding import smart_bytes
from django.utils import six
diff --git a/django/core/serializers/xml_serializer.py b/django/core/serializers/xml_serializer.py
index 9d9c023b64..c4e4dd189e 100644
--- a/django/core/serializers/xml_serializer.py
+++ b/django/core/serializers/xml_serializer.py
@@ -8,7 +8,7 @@ from django.conf import settings
from django.core.serializers import base
from django.db import models, DEFAULT_DB_ALIAS
from django.utils.xmlutils import SimplerXMLGenerator
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
from xml.dom import pulldom
class Serializer(base.Serializer):
@@ -46,11 +46,11 @@ class Serializer(base.Serializer):
self.indent(1)
obj_pk = obj._get_pk_val()
if obj_pk is None:
- attrs = {"model": smart_unicode(obj._meta),}
+ attrs = {"model": smart_text(obj._meta),}
else:
attrs = {
- "pk": smart_unicode(obj._get_pk_val()),
- "model": smart_unicode(obj._meta),
+ "pk": smart_text(obj._get_pk_val()),
+ "model": smart_text(obj._meta),
}
self.xml.startElement("object", attrs)
@@ -96,10 +96,10 @@ class Serializer(base.Serializer):
# Iterable natural keys are rolled out as subelements
for key_value in related:
self.xml.startElement("natural", {})
- self.xml.characters(smart_unicode(key_value))
+ self.xml.characters(smart_text(key_value))
self.xml.endElement("natural")
else:
- self.xml.characters(smart_unicode(related_att))
+ self.xml.characters(smart_text(related_att))
else:
self.xml.addQuickElement("None")
self.xml.endElement("field")
@@ -120,13 +120,13 @@ class Serializer(base.Serializer):
self.xml.startElement("object", {})
for key_value in natural:
self.xml.startElement("natural", {})
- self.xml.characters(smart_unicode(key_value))
+ self.xml.characters(smart_text(key_value))
self.xml.endElement("natural")
self.xml.endElement("object")
else:
def handle_m2m(value):
self.xml.addQuickElement("object", attrs={
- 'pk' : smart_unicode(value._get_pk_val())
+ 'pk' : smart_text(value._get_pk_val())
})
for relobj in getattr(obj, field.name).iterator():
handle_m2m(relobj)
@@ -141,7 +141,7 @@ class Serializer(base.Serializer):
self.xml.startElement("field", {
"name" : field.name,
"rel" : field.rel.__class__.__name__,
- "to" : smart_unicode(field.rel.to._meta),
+ "to" : smart_text(field.rel.to._meta),
})
class Deserializer(base.Deserializer):
diff --git a/django/core/signing.py b/django/core/signing.py
index cd9759e536..9ab8c5b8b0 100644
--- a/django/core/signing.py
+++ b/django/core/signing.py
@@ -41,7 +41,7 @@ from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils import baseconv
from django.utils.crypto import constant_time_compare, salted_hmac
-from django.utils.encoding import force_unicode, smart_str
+from django.utils.encoding import force_text, smart_bytes
from django.utils.importlib import import_module
@@ -135,7 +135,7 @@ def loads(s, key=None, salt='django.core.signing', serializer=JSONSerializer, ma
"""
Reverse of dumps(), raises BadSignature if signature fails
"""
- base64d = smart_str(
+ base64d = smart_bytes(
TimestampSigner(key, salt=salt).unsign(s, max_age=max_age))
decompress = False
if base64d[0] == '.':
@@ -159,16 +159,16 @@ class Signer(object):
return base64_hmac(self.salt + 'signer', value, self.key)
def sign(self, value):
- value = smart_str(value)
+ value = smart_bytes(value)
return '%s%s%s' % (value, self.sep, self.signature(value))
def unsign(self, signed_value):
- signed_value = smart_str(signed_value)
+ signed_value = smart_bytes(signed_value)
if not self.sep in signed_value:
raise BadSignature('No "%s" found in value' % self.sep)
value, sig = signed_value.rsplit(self.sep, 1)
if constant_time_compare(sig, self.signature(value)):
- return force_unicode(value)
+ return force_text(value)
raise BadSignature('Signature "%s" does not match' % sig)
@@ -178,7 +178,7 @@ class TimestampSigner(Signer):
return baseconv.base62.encode(int(time.time()))
def sign(self, value):
- value = smart_str('%s%s%s' % (value, self.sep, self.timestamp()))
+ value = smart_bytes('%s%s%s' % (value, self.sep, self.timestamp()))
return '%s%s%s' % (value, self.sep, self.signature(value))
def unsign(self, value, max_age=None):
diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py
index c17168f8cb..2fe744e8eb 100644
--- a/django/core/urlresolvers.py
+++ b/django/core/urlresolvers.py
@@ -14,7 +14,7 @@ from threading import local
from django.http import Http404
from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist
from django.utils.datastructures import MultiValueDict
-from django.utils.encoding import iri_to_uri, force_unicode, smart_str
+from django.utils.encoding import iri_to_uri, force_text, smart_bytes
from django.utils.functional import memoize, lazy
from django.utils.importlib import import_module
from django.utils.module_loading import module_has_submodule
@@ -163,7 +163,7 @@ class LocaleRegexProvider(object):
if isinstance(self._regex, six.string_types):
regex = self._regex
else:
- regex = force_unicode(self._regex)
+ regex = force_text(self._regex)
try:
compiled_regex = re.compile(regex, re.UNICODE)
except re.error as e:
@@ -190,7 +190,7 @@ class RegexURLPattern(LocaleRegexProvider):
self.name = name
def __repr__(self):
- return smart_str('<%s %s %s>' % (self.__class__.__name__, self.name, self.regex.pattern))
+ return smart_bytes('<%s %s %s>' % (self.__class__.__name__, self.name, self.regex.pattern))
def add_prefix(self, prefix):
"""
@@ -240,7 +240,7 @@ class RegexURLResolver(LocaleRegexProvider):
self._app_dict = {}
def __repr__(self):
- return smart_str('<%s %s (%s:%s) %s>' % (self.__class__.__name__, self.urlconf_name, self.app_name, self.namespace, self.regex.pattern))
+ return smart_bytes('<%s %s (%s:%s) %s>' % (self.__class__.__name__, self.urlconf_name, self.app_name, self.namespace, self.regex.pattern))
def _populate(self):
lookups = MultiValueDict()
@@ -373,7 +373,7 @@ class RegexURLResolver(LocaleRegexProvider):
if args:
if len(args) != len(params) + len(prefix_args):
continue
- unicode_args = [force_unicode(val) for val in args]
+ unicode_args = [force_text(val) for val in args]
candidate = (prefix_norm + result) % dict(zip(prefix_args + params, unicode_args))
else:
if set(kwargs.keys()) | set(defaults.keys()) != set(params) | set(defaults.keys()) | set(prefix_args):
@@ -385,7 +385,7 @@ class RegexURLResolver(LocaleRegexProvider):
break
if not matches:
continue
- unicode_kwargs = dict([(k, force_unicode(v)) for (k, v) in kwargs.items()])
+ unicode_kwargs = dict([(k, force_text(v)) for (k, v) in kwargs.items()])
candidate = (prefix_norm + result) % unicode_kwargs
if re.search('^%s%s' % (_prefix, pattern), candidate, re.UNICODE):
return candidate
diff --git a/django/core/validators.py b/django/core/validators.py
index 91d6f62dcf..fd5dfa28d6 100644
--- a/django/core/validators.py
+++ b/django/core/validators.py
@@ -8,7 +8,7 @@ except ImportError: # Python 2
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
from django.utils.ipv6 import is_valid_ipv6_address
from django.utils import six
@@ -36,7 +36,7 @@ class RegexValidator(object):
"""
Validates that the input matches the regular expression.
"""
- if not self.regex.search(smart_unicode(value)):
+ if not self.regex.search(smart_text(value)):
raise ValidationError(self.message, code=self.code)
class URLValidator(RegexValidator):
@@ -54,7 +54,7 @@ class URLValidator(RegexValidator):
except ValidationError as e:
# Trivial case failed. Try for possible IDN domain
if value:
- value = smart_unicode(value)
+ value = smart_text(value)
scheme, netloc, path, query, fragment = urlsplit(value)
try:
netloc = netloc.encode('idna') # IDN -> ACE
diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
index 6e23ad5bb5..9606245162 100644
--- a/django/db/backends/__init__.py
+++ b/django/db/backends/__init__.py
@@ -607,16 +607,16 @@ class BaseDatabaseOperations(object):
exists for database backends to provide a better implementation
according to their own quoting schemes.
"""
- from django.utils.encoding import smart_unicode, force_unicode
+ from django.utils.encoding import smart_text, force_text
# Convert params to contain Unicode values.
- to_unicode = lambda s: force_unicode(s, strings_only=True, errors='replace')
+ to_unicode = lambda s: force_text(s, strings_only=True, errors='replace')
if isinstance(params, (list, tuple)):
u_params = tuple([to_unicode(val) for val in params])
else:
u_params = dict([(to_unicode(k), to_unicode(v)) for k, v in params.items()])
- return smart_unicode(sql) % u_params
+ return smart_text(sql) % u_params
def last_insert_id(self, cursor, table_name, pk_name):
"""
@@ -800,8 +800,8 @@ class BaseDatabaseOperations(object):
def prep_for_like_query(self, x):
"""Prepares a value for use in a LIKE query."""
- from django.utils.encoding import smart_unicode
- return smart_unicode(x).replace("\\", "\\\\").replace("%", "\%").replace("_", "\_")
+ from django.utils.encoding import smart_text
+ return smart_text(x).replace("\\", "\\\\").replace("%", "\%").replace("_", "\_")
# Same as prep_for_like_query(), but called for "iexact" matches, which
# need not necessarily be implemented using "LIKE" in the backend.
diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py
index b08113fed7..0f16130477 100644
--- a/django/db/backends/oracle/base.py
+++ b/django/db/backends/oracle/base.py
@@ -53,7 +53,7 @@ from django.db.backends.signals import connection_created
from django.db.backends.oracle.client import DatabaseClient
from django.db.backends.oracle.creation import DatabaseCreation
from django.db.backends.oracle.introspection import DatabaseIntrospection
-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 import timezone
@@ -64,9 +64,9 @@ IntegrityError = Database.IntegrityError
# Check whether cx_Oracle was compiled with the WITH_UNICODE option. This will
# also be True in Python 3.0.
if int(Database.version.split('.', 1)[0]) >= 5 and not hasattr(Database, 'UNICODE'):
- convert_unicode = force_unicode
+ convert_unicode = force_text
else:
- convert_unicode = smart_str
+ convert_unicode = smart_bytes
class DatabaseFeatures(BaseDatabaseFeatures):
@@ -162,7 +162,7 @@ WHEN (new.%(col_name)s IS NULL)
if isinstance(value, Database.LOB):
value = value.read()
if field and field.get_internal_type() == 'TextField':
- value = force_unicode(value)
+ value = force_text(value)
# Oracle stores empty strings as null. We need to undo this in
# order to adhere to the Django convention of using the empty
@@ -245,7 +245,7 @@ WHEN (new.%(col_name)s IS NULL)
def process_clob(self, value):
if value is None:
return ''
- return force_unicode(value.read())
+ return force_text(value.read())
def quote_name(self, name):
# SQL92 requires delimited (quoted) names to be case-sensitive. When
@@ -595,9 +595,9 @@ class OracleParam(object):
param = param.astimezone(timezone.utc).replace(tzinfo=None)
if hasattr(param, 'bind_parameter'):
- self.smart_str = param.bind_parameter(cursor)
+ self.smart_bytes = param.bind_parameter(cursor)
else:
- self.smart_str = convert_unicode(param, cursor.charset,
+ self.smart_bytes = convert_unicode(param, cursor.charset,
strings_only)
if hasattr(param, 'input_size'):
# If parameter has `input_size` attribute, use that.
@@ -676,7 +676,7 @@ class FormatStylePlaceholderCursor(object):
self.setinputsizes(*sizes)
def _param_generator(self, params):
- return [p.smart_str for p in params]
+ return [p.smart_bytes for p in params]
def execute(self, query, params=None):
if params is None:
@@ -831,7 +831,7 @@ def to_unicode(s):
unchanged).
"""
if isinstance(s, six.string_types):
- return force_unicode(s)
+ return force_text(s)
return s
diff --git a/django/db/models/base.py b/django/db/models/base.py
index a25c106290..4568430bfa 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -23,7 +23,7 @@ from django.db.models import signals
from django.db.models.loading import register_models, get_model
from django.utils.translation import ugettext_lazy as _
from django.utils.functional import curry
-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.text import get_text_list, capfirst
@@ -380,11 +380,11 @@ class Model(six.with_metaclass(ModelBase, object)):
u = six.text_type(self)
except (UnicodeEncodeError, UnicodeDecodeError):
u = '[Bad Unicode data]'
- return smart_str('<%s: %s>' % (self.__class__.__name__, u))
+ return smart_bytes('<%s: %s>' % (self.__class__.__name__, u))
def __str__(self):
if hasattr(self, '__unicode__'):
- return force_unicode(self).encode('utf-8')
+ return force_text(self).encode('utf-8')
return '%s object' % self.__class__.__name__
def __eq__(self, other):
@@ -605,14 +605,14 @@ class Model(six.with_metaclass(ModelBase, object)):
def _get_FIELD_display(self, field):
value = getattr(self, field.attname)
- return force_unicode(dict(field.flatchoices).get(value, value), strings_only=True)
+ return force_text(dict(field.flatchoices).get(value, value), strings_only=True)
def _get_next_or_previous_by_FIELD(self, field, is_next, **kwargs):
if not self.pk:
raise ValueError("get_next/get_previous cannot be used on unsaved objects.")
op = is_next and 'gt' or 'lt'
order = not is_next and '-' or ''
- param = smart_str(getattr(self, field.attname))
+ param = smart_bytes(getattr(self, field.attname))
q = Q(**{'%s__%s' % (field.name, op): param})
q = q|Q(**{field.name: param, 'pk__%s' % op: self.pk})
qs = self.__class__._default_manager.using(self._state.db).filter(**kwargs).filter(q).order_by('%s%s' % (order, field.name), '%spk' % order)
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index de24a24ed1..2c738d6a20 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -19,7 +19,7 @@ from django.utils.functional import curry, total_ordering
from django.utils.text import capfirst
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
-from django.utils.encoding import smart_unicode, force_unicode
+from django.utils.encoding import smart_text, force_text
from django.utils.ipv6 import clean_ipv6_address
from django.utils import six
@@ -386,7 +386,7 @@ class Field(object):
if self.has_default():
if callable(self.default):
return self.default()
- return force_unicode(self.default, strings_only=True)
+ return force_text(self.default, strings_only=True)
if (not self.empty_strings_allowed or (self.null and
not connection.features.interprets_empty_strings_as_nulls)):
return None
@@ -404,11 +404,11 @@ class Field(object):
rel_model = self.rel.to
if hasattr(self.rel, 'get_related_field'):
lst = [(getattr(x, self.rel.get_related_field().attname),
- smart_unicode(x))
+ smart_text(x))
for x in rel_model._default_manager.complex_filter(
self.rel.limit_choices_to)]
else:
- lst = [(x._get_pk_val(), smart_unicode(x))
+ lst = [(x._get_pk_val(), smart_text(x))
for x in rel_model._default_manager.complex_filter(
self.rel.limit_choices_to)]
return first_choice + lst
@@ -435,7 +435,7 @@ class Field(object):
Returns a string value of this field from the passed obj.
This is used by the serialization framework.
"""
- return smart_unicode(self._get_val_from_obj(obj))
+ return smart_text(self._get_val_from_obj(obj))
def bind(self, fieldmapping, original, bound_field_class):
return bound_field_class(self, fieldmapping, original)
@@ -629,7 +629,7 @@ class CharField(Field):
def to_python(self, value):
if isinstance(value, six.string_types) or value is None:
return value
- return smart_unicode(value)
+ return smart_text(value)
def get_prep_value(self, value):
return self.to_python(value)
@@ -1189,7 +1189,7 @@ class TextField(Field):
def get_prep_value(self, value):
if isinstance(value, six.string_types) or value is None:
return value
- return smart_unicode(value)
+ return smart_text(value)
def formfield(self, **kwargs):
defaults = {'widget': forms.Textarea}
diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py
index b51ef1d5d6..ad4c36ca0d 100644
--- a/django/db/models/fields/files.py
+++ b/django/db/models/fields/files.py
@@ -8,7 +8,7 @@ from django.core.files.base import File
from django.core.files.storage import default_storage
from django.core.files.images import ImageFile
from django.db.models import signals
-from django.utils.encoding import force_unicode, smart_str
+from django.utils.encoding import force_text, smart_bytes
from django.utils import six
from django.utils.translation import ugettext_lazy as _
@@ -280,7 +280,7 @@ class FileField(Field):
setattr(cls, self.name, self.descriptor_class(self))
def get_directory_name(self):
- return os.path.normpath(force_unicode(datetime.datetime.now().strftime(smart_str(self.upload_to))))
+ return os.path.normpath(force_text(datetime.datetime.now().strftime(smart_bytes(self.upload_to))))
def get_filename(self, filename):
return os.path.normpath(self.storage.get_valid_name(os.path.basename(filename)))
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
index bfa8feee9f..eaa62c6061 100644
--- a/django/db/models/fields/related.py
+++ b/django/db/models/fields/related.py
@@ -9,7 +9,7 @@ from django.db.models.related import RelatedObject
from django.db.models.query import QuerySet
from django.db.models.query_utils import QueryWrapper
from django.db.models.deletion import CASCADE
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
from django.utils import six
from django.utils.translation import ugettext_lazy as _, string_concat
from django.utils.functional import curry, cached_property
@@ -999,7 +999,7 @@ class ForeignKey(RelatedField, Field):
if not self.blank and self.choices:
choice_list = self.get_choices_default()
if len(choice_list) == 2:
- return smart_unicode(choice_list[1][0])
+ return smart_text(choice_list[1][0])
return Field.value_to_string(self, obj)
def contribute_to_class(self, cls, name):
@@ -1205,7 +1205,7 @@ class ManyToManyField(RelatedField, Field):
choices_list = self.get_choices_default()
if len(choices_list) == 1:
data = [choices_list[0][0]]
- return smart_unicode(data)
+ return smart_text(data)
def contribute_to_class(self, cls, name):
# To support multiple relations to self, it's useful to have a non-None
diff --git a/django/db/models/options.py b/django/db/models/options.py
index 9e8d4120e9..239ad30b06 100644
--- a/django/db/models/options.py
+++ b/django/db/models/options.py
@@ -8,7 +8,7 @@ from django.db.models.fields import AutoField, FieldDoesNotExist
from django.db.models.fields.proxy import OrderWrt
from django.db.models.loading import get_models, app_cache_ready
from django.utils.translation import activate, deactivate_all, get_language, string_concat
-from django.utils.encoding import force_unicode, smart_str
+from django.utils.encoding import force_text, smart_bytes
from django.utils.datastructures import SortedDict
from django.utils import six
@@ -199,7 +199,7 @@ class Options(object):
return '' % self.object_name
def __str__(self):
- return "%s.%s" % (smart_str(self.app_label), smart_str(self.module_name))
+ return "%s.%s" % (smart_bytes(self.app_label), smart_bytes(self.module_name))
def verbose_name_raw(self):
"""
@@ -209,7 +209,7 @@ class Options(object):
"""
lang = get_language()
deactivate_all()
- raw = force_unicode(self.verbose_name)
+ raw = force_text(self.verbose_name)
activate(lang)
return raw
verbose_name_raw = property(verbose_name_raw)
diff --git a/django/db/models/related.py b/django/db/models/related.py
index 90995d749f..a0dcec7132 100644
--- a/django/db/models/related.py
+++ b/django/db/models/related.py
@@ -1,4 +1,4 @@
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
from django.db.models.fields import BLANK_CHOICE_DASH
class BoundRelatedObject(object):
@@ -34,9 +34,9 @@ class RelatedObject(object):
if limit_to_currently_related:
queryset = queryset.complex_filter(
{'%s__isnull' % self.parent_model._meta.module_name: False})
- lst = [(x._get_pk_val(), smart_unicode(x)) for x in queryset]
+ lst = [(x._get_pk_val(), smart_text(x)) for x in queryset]
return first_choice + lst
-
+
def get_db_prep_lookup(self, lookup_type, value, connection, prepared=False):
# Defer to the actual field definition for db prep
return self.field.get_db_prep_lookup(lookup_type, value,
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index 9cf732f263..69dda228bd 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -10,7 +10,7 @@ all about the internals of models in order to get the information it needs.
import copy
from django.utils.datastructures import SortedDict
-from django.utils.encoding import force_unicode
+from django.utils.encoding import force_text
from django.utils.tree import Node
from django.utils import six
from django.db import connections, DEFAULT_DB_ALIAS
@@ -1776,7 +1776,7 @@ class Query(object):
else:
param_iter = iter([])
for name, entry in select.items():
- entry = force_unicode(entry)
+ entry = force_text(entry)
entry_params = []
pos = entry.find("%s")
while pos != -1:
diff --git a/django/db/models/sql/subqueries.py b/django/db/models/sql/subqueries.py
index cc7da0eeaf..937505b9b0 100644
--- a/django/db/models/sql/subqueries.py
+++ b/django/db/models/sql/subqueries.py
@@ -10,7 +10,7 @@ from django.db.models.sql.query import Query
from django.db.models.sql.where import AND, Constraint
from django.utils.datastructures import SortedDict
from django.utils.functional import Promise
-from django.utils.encoding import force_unicode
+from django.utils.encoding import force_text
from django.utils import six
@@ -105,7 +105,7 @@ class UpdateQuery(Query):
saving models.
"""
# Check that no Promise object passes to the query. Refs #10498.
- values_seq = [(value[0], value[1], force_unicode(value[2]))
+ values_seq = [(value[0], value[1], force_text(value[2]))
if isinstance(value[2], Promise) else value
for value in values_seq]
self.values.extend(values_seq)
@@ -171,7 +171,7 @@ class InsertQuery(Query):
for obj in objs:
value = getattr(obj, field.attname)
if isinstance(value, Promise):
- setattr(obj, field.attname, force_unicode(value))
+ setattr(obj, field.attname, force_text(value))
self.objs = objs
self.raw = raw
diff --git a/django/forms/fields.py b/django/forms/fields.py
index cdb1d7be67..7f0d26d1aa 100644
--- a/django/forms/fields.py
+++ b/django/forms/fields.py
@@ -23,7 +23,7 @@ from django.forms.widgets import (TextInput, PasswordInput, HiddenInput,
NullBooleanSelect, SelectMultiple, DateInput, DateTimeInput, TimeInput,
SplitDateTimeWidget, SplitHiddenDateTimeWidget, FILE_INPUT_CONTRADICTION)
from django.utils import formats
-from django.utils.encoding import smart_unicode, force_unicode
+from django.utils.encoding import smart_text, force_text
from django.utils.ipv6 import clean_ipv6_address
from django.utils import six
from django.utils.translation import ugettext_lazy as _
@@ -78,13 +78,13 @@ class Field(object):
# validators -- List of addtional validators to use
# localize -- Boolean that specifies if the field should be localized.
if label is not None:
- label = smart_unicode(label)
+ label = smart_text(label)
self.required, self.label, self.initial = required, label, initial
self.show_hidden_initial = show_hidden_initial
if help_text is None:
self.help_text = ''
else:
- self.help_text = smart_unicode(help_text)
+ self.help_text = smart_text(help_text)
widget = widget or self.widget
if isinstance(widget, type):
widget = widget()
@@ -195,7 +195,7 @@ class CharField(Field):
"Returns a Unicode object."
if value in validators.EMPTY_VALUES:
return ''
- return smart_unicode(value)
+ return smart_text(value)
def widget_attrs(self, widget):
attrs = super(CharField, self).widget_attrs(widget)
@@ -288,7 +288,7 @@ class DecimalField(Field):
return None
if self.localize:
value = formats.sanitize_separators(value)
- value = smart_unicode(value).strip()
+ value = smart_text(value).strip()
try:
value = Decimal(value)
except DecimalException:
@@ -333,7 +333,7 @@ class BaseTemporalField(Field):
def to_python(self, value):
# Try to coerce the value to unicode.
- unicode_value = force_unicode(value, strings_only=True)
+ unicode_value = force_text(value, strings_only=True)
if isinstance(unicode_value, six.text_type):
value = unicode_value.strip()
# If unicode, try to strptime against each input format.
@@ -692,7 +692,7 @@ class ChoiceField(Field):
"Returns a Unicode object."
if value in validators.EMPTY_VALUES:
return ''
- return smart_unicode(value)
+ return smart_text(value)
def validate(self, value):
"""
@@ -708,10 +708,10 @@ class ChoiceField(Field):
if isinstance(v, (list, tuple)):
# This is an optgroup, so look inside the group for options
for k2, v2 in v:
- if value == smart_unicode(k2):
+ if value == smart_text(k2):
return True
else:
- if value == smart_unicode(k):
+ if value == smart_text(k):
return True
return False
@@ -752,7 +752,7 @@ class MultipleChoiceField(ChoiceField):
return []
elif not isinstance(value, (list, tuple)):
raise ValidationError(self.error_messages['invalid_list'])
- return [smart_unicode(val) for val in value]
+ return [smart_text(val) for val in value]
def validate(self, value):
"""
diff --git a/django/forms/forms.py b/django/forms/forms.py
index 0f3fdb2e40..45b758202a 100644
--- a/django/forms/forms.py
+++ b/django/forms/forms.py
@@ -12,7 +12,7 @@ from django.forms.util import flatatt, ErrorDict, ErrorList
from django.forms.widgets import Media, media_property, TextInput, Textarea
from django.utils.datastructures import SortedDict
from django.utils.html import conditional_escape, format_html
-from django.utils.encoding import StrAndUnicode, smart_unicode, force_unicode
+from django.utils.encoding import StrAndUnicode, smart_text, force_text
from django.utils.safestring import mark_safe
from django.utils import six
@@ -150,7 +150,7 @@ class BaseForm(StrAndUnicode):
bf_errors = self.error_class([conditional_escape(error) for error in bf.errors]) # Escape and cache in local variable.
if bf.is_hidden:
if bf_errors:
- top_errors.extend(['(Hidden field %s) %s' % (name, force_unicode(e)) for e in bf_errors])
+ top_errors.extend(['(Hidden field %s) %s' % (name, force_text(e)) for e in bf_errors])
hidden_fields.append(six.text_type(bf))
else:
# Create a 'class="..."' atribute if the row should have any
@@ -160,10 +160,10 @@ class BaseForm(StrAndUnicode):
html_class_attr = ' class="%s"' % css_classes
if errors_on_separate_row and bf_errors:
- output.append(error_row % force_unicode(bf_errors))
+ output.append(error_row % force_text(bf_errors))
if bf.label:
- label = conditional_escape(force_unicode(bf.label))
+ label = conditional_escape(force_text(bf.label))
# Only add the suffix if the label does not end in
# punctuation.
if self.label_suffix:
@@ -174,20 +174,20 @@ class BaseForm(StrAndUnicode):
label = ''
if field.help_text:
- help_text = help_text_html % force_unicode(field.help_text)
+ help_text = help_text_html % force_text(field.help_text)
else:
help_text = ''
output.append(normal_row % {
- 'errors': force_unicode(bf_errors),
- 'label': force_unicode(label),
+ 'errors': force_text(bf_errors),
+ 'label': force_text(label),
'field': six.text_type(bf),
'help_text': help_text,
'html_class_attr': html_class_attr
})
if top_errors:
- output.insert(0, error_row % force_unicode(top_errors))
+ output.insert(0, error_row % force_text(top_errors))
if hidden_fields: # Insert any hidden fields in the last row.
str_hidden = ''.join(hidden_fields)
@@ -535,8 +535,8 @@ class BoundField(StrAndUnicode):
associated Form has specified auto_id. Returns an empty string otherwise.
"""
auto_id = self.form.auto_id
- if auto_id and '%s' in smart_unicode(auto_id):
- return smart_unicode(auto_id) % self.html_name
+ if auto_id and '%s' in smart_text(auto_id):
+ return smart_text(auto_id) % self.html_name
elif auto_id:
return self.html_name
return ''
diff --git a/django/forms/models.py b/django/forms/models.py
index a2b5448b14..80d2a6536f 100644
--- a/django/forms/models.py
+++ b/django/forms/models.py
@@ -13,7 +13,7 @@ from django.forms.formsets import BaseFormSet, formset_factory
from django.forms.util import ErrorList
from django.forms.widgets import (SelectMultiple, HiddenInput,
MultipleHiddenInput, media_property)
-from django.utils.encoding import smart_unicode, force_unicode
+from django.utils.encoding import smart_text, force_text
from django.utils.datastructures import SortedDict
from django.utils import six
from django.utils.text import get_text_list, capfirst
@@ -875,7 +875,7 @@ class InlineForeignKeyField(Field):
orig = getattr(self.parent_instance, self.to_field)
else:
orig = self.parent_instance.pk
- if force_unicode(value) != force_unicode(orig):
+ if force_text(value) != force_text(orig):
raise ValidationError(self.error_messages['invalid_choice'])
return self.parent_instance
@@ -953,7 +953,7 @@ class ModelChoiceField(ChoiceField):
generate the labels for the choices presented by this object. Subclasses
can override this method to customize the display of the choices.
"""
- return smart_unicode(obj)
+ return smart_text(obj)
def _get_choices(self):
# If self._choices is set, then somebody must have manually set
@@ -1025,9 +1025,9 @@ class ModelMultipleChoiceField(ModelChoiceField):
except ValueError:
raise ValidationError(self.error_messages['invalid_pk_value'] % pk)
qs = self.queryset.filter(**{'%s__in' % key: value})
- pks = set([force_unicode(getattr(o, key)) for o in qs])
+ pks = set([force_text(getattr(o, key)) for o in qs])
for val in value:
- if force_unicode(val) not in pks:
+ if force_text(val) not in pks:
raise ValidationError(self.error_messages['invalid_choice'] % val)
# Since this overrides the inherited ModelChoiceField.clean
# we run custom validators here
diff --git a/django/forms/util.py b/django/forms/util.py
index 8cf03d38af..cd6b52df6f 100644
--- a/django/forms/util.py
+++ b/django/forms/util.py
@@ -2,7 +2,7 @@ from __future__ import unicode_literals
from django.conf import settings
from django.utils.html import format_html, format_html_join
-from django.utils.encoding import StrAndUnicode, force_unicode
+from django.utils.encoding import StrAndUnicode, force_text
from django.utils.safestring import mark_safe
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
@@ -35,12 +35,12 @@ class ErrorDict(dict, StrAndUnicode):
if not self: return ''
return format_html('
{0}
',
format_html_join('', '
{0}{1}
',
- ((k, force_unicode(v))
+ ((k, force_text(v))
for k, v in self.items())
))
def as_text(self):
- return '\n'.join(['* %s\n%s' % (k, '\n'.join([' * %s' % force_unicode(i) for i in v])) for k, v in self.items()])
+ return '\n'.join(['* %s\n%s' % (k, '\n'.join([' * %s' % force_text(i) for i in v])) for k, v in self.items()])
class ErrorList(list, StrAndUnicode):
"""
@@ -53,16 +53,16 @@ class ErrorList(list, StrAndUnicode):
if not self: return ''
return format_html('
{0}
',
format_html_join('', '
{0}
',
- ((force_unicode(e),) for e in self)
+ ((force_text(e),) for e in self)
)
)
def as_text(self):
if not self: return ''
- return '\n'.join(['* %s' % force_unicode(e) for e in self])
+ return '\n'.join(['* %s' % force_text(e) for e in self])
def __repr__(self):
- return repr([force_unicode(e) for e in self])
+ return repr([force_text(e) for e in self])
# Utilities for time zone support in DateTimeField et al.
diff --git a/django/forms/widgets.py b/django/forms/widgets.py
index 13b7d8e7f6..be9ac8eb8f 100644
--- a/django/forms/widgets.py
+++ b/django/forms/widgets.py
@@ -17,7 +17,7 @@ from django.forms.util import flatatt, to_current_timezone
from django.utils.datastructures import MultiValueDict, MergeDict
from django.utils.html import conditional_escape, format_html, format_html_join
from django.utils.translation import ugettext, ugettext_lazy
-from django.utils.encoding import StrAndUnicode, force_unicode
+from django.utils.encoding import StrAndUnicode, force_text
from django.utils.safestring import mark_safe
from django.utils import six
from django.utils import datetime_safe, formats
@@ -223,7 +223,7 @@ class Widget(six.with_metaclass(MediaDefiningClass)):
initial_value = ''
else:
initial_value = initial
- if force_unicode(initial_value) != force_unicode(data_value):
+ if force_text(initial_value) != force_text(data_value):
return True
return False
@@ -257,7 +257,7 @@ class Input(Widget):
final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
if value != '':
# Only add the 'value' attribute if a value is non-empty.
- final_attrs['value'] = force_unicode(self._format_value(value))
+ final_attrs['value'] = force_text(self._format_value(value))
return format_html('', flatatt(final_attrs))
class TextInput(Input):
@@ -294,7 +294,7 @@ class MultipleHiddenInput(HiddenInput):
id_ = final_attrs.get('id', None)
inputs = []
for i, v in enumerate(value):
- input_attrs = dict(value=force_unicode(v), **final_attrs)
+ input_attrs = dict(value=force_text(v), **final_attrs)
if id_:
# An ID attribute was given. Add a numeric index as a suffix
# so that the inputs don't all have the same ID attribute.
@@ -361,7 +361,7 @@ class ClearableFileInput(FileInput):
template = self.template_with_initial
substitutions['initial'] = format_html('{1}',
value.url,
- force_unicode(value))
+ force_text(value))
if not self.is_required:
checkbox_name = self.clear_checkbox_name(name)
checkbox_id = self.clear_checkbox_id(checkbox_name)
@@ -398,7 +398,7 @@ class Textarea(Widget):
final_attrs = self.build_attrs(attrs, name=name)
return format_html('',
flatatt(final_attrs),
- force_unicode(value))
+ force_text(value))
class DateInput(Input):
input_type = 'text'
@@ -515,7 +515,7 @@ class CheckboxInput(Widget):
final_attrs['checked'] = 'checked'
if not (value is True or value is False or value is None or value == ''):
# Only add the 'value' attribute if a value is non-empty.
- final_attrs['value'] = force_unicode(value)
+ final_attrs['value'] = force_text(value)
return format_html('', flatatt(final_attrs))
def value_from_datadict(self, data, files, name):
@@ -556,7 +556,7 @@ class Select(Widget):
return mark_safe('\n'.join(output))
def render_option(self, selected_choices, option_value, option_label):
- option_value = force_unicode(option_value)
+ option_value = force_text(option_value)
if option_value in selected_choices:
selected_html = mark_safe(' selected="selected"')
if not self.allow_multiple_selected:
@@ -567,15 +567,15 @@ class Select(Widget):
return format_html('',
option_value,
selected_html,
- force_unicode(option_label))
+ force_text(option_label))
def render_options(self, choices, selected_choices):
# Normalize to strings.
- selected_choices = set(force_unicode(v) for v in selected_choices)
+ selected_choices = set(force_text(v) for v in selected_choices)
output = []
for option_value, option_label in chain(self.choices, choices):
if isinstance(option_label, (list, tuple)):
- output.append(format_html('