summaryrefslogtreecommitdiff
path: root/django/db
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2012-07-20 14:48:51 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2012-07-22 09:29:54 +0200
commitbdca5ea345c548a82a80d198906818c9ccbef896 (patch)
tree5c3f5fe5ad2522175d67b96a1fce1ff1763ba125 /django/db
parent3cb2457f46b3e40ff6b6acffcb3fd44cbea091e5 (diff)
[py3] Replaced unicode/str by six.text_type/bytes.
Diffstat (limited to 'django/db')
-rw-r--r--django/db/backends/__init__.py7
-rw-r--r--django/db/backends/mysql/base.py8
-rw-r--r--django/db/backends/oracle/base.py2
-rw-r--r--django/db/backends/sqlite3/base.py4
-rw-r--r--django/db/models/base.py14
-rw-r--r--django/db/models/fields/files.py2
6 files changed, 19 insertions, 18 deletions
diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
index 3075bdb3e4..b416343f88 100644
--- a/django/db/backends/__init__.py
+++ b/django/db/backends/__init__.py
@@ -12,6 +12,7 @@ from django.db.backends import util
from django.db.transaction import TransactionManagementError
from django.utils.functional import cached_property
from django.utils.importlib import import_module
+from django.utils import six
from django.utils.timezone import is_aware
@@ -808,7 +809,7 @@ class BaseDatabaseOperations(object):
"""
if value is None:
return None
- return unicode(value)
+ return six.text_type(value)
def value_to_db_datetime(self, value):
"""
@@ -817,7 +818,7 @@ class BaseDatabaseOperations(object):
"""
if value is None:
return None
- return unicode(value)
+ return six.text_type(value)
def value_to_db_time(self, value):
"""
@@ -828,7 +829,7 @@ class BaseDatabaseOperations(object):
return None
if is_aware(value):
raise ValueError("Django does not support timezone-aware times.")
- return unicode(value)
+ return six.text_type(value)
def value_to_db_decimal(self, value, max_digits, decimal_places):
"""
diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
index a7668dec49..ec65207ed8 100644
--- a/django/db/backends/mysql/base.py
+++ b/django/db/backends/mysql/base.py
@@ -297,7 +297,7 @@ class DatabaseOperations(BaseDatabaseOperations):
raise ValueError("MySQL backend does not support timezone-aware datetimes when USE_TZ is False.")
# MySQL doesn't support microseconds
- return unicode(value.replace(microsecond=0))
+ return six.text_type(value.replace(microsecond=0))
def value_to_db_time(self, value):
if value is None:
@@ -308,7 +308,7 @@ class DatabaseOperations(BaseDatabaseOperations):
raise ValueError("MySQL backend does not support timezone-aware times.")
# MySQL doesn't support microseconds
- return unicode(value.replace(microsecond=0))
+ return six.text_type(value.replace(microsecond=0))
def year_lookup_bounds(self, value):
# Again, no microseconds
@@ -399,8 +399,8 @@ class DatabaseWrapper(BaseDatabaseWrapper):
kwargs['client_flag'] = CLIENT.FOUND_ROWS
kwargs.update(settings_dict['OPTIONS'])
self.connection = Database.connect(**kwargs)
- self.connection.encoders[SafeUnicode] = self.connection.encoders[unicode]
- self.connection.encoders[SafeString] = self.connection.encoders[str]
+ self.connection.encoders[SafeUnicode] = self.connection.encoders[six.text_type]
+ self.connection.encoders[SafeString] = self.connection.encoders[bytes]
connection_created.send(sender=self.__class__, connection=self)
cursor = self.connection.cursor()
if new_connection:
diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py
index 9ac41a5741..32ae420ce0 100644
--- a/django/db/backends/oracle/base.py
+++ b/django/db/backends/oracle/base.py
@@ -356,7 +356,7 @@ WHEN (new.%(col_name)s IS NULL)
else:
raise ValueError("Oracle backend does not support timezone-aware datetimes when USE_TZ is False.")
- return unicode(value)
+ return six.text_type(value)
def value_to_db_time(self, value):
if value is None:
diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py
index e2149ca8d8..0a97449789 100644
--- a/django/db/backends/sqlite3/base.py
+++ b/django/db/backends/sqlite3/base.py
@@ -177,7 +177,7 @@ class DatabaseOperations(BaseDatabaseOperations):
else:
raise ValueError("SQLite backend does not support timezone-aware datetimes when USE_TZ is False.")
- return unicode(value)
+ return six.text_type(value)
def value_to_db_time(self, value):
if value is None:
@@ -187,7 +187,7 @@ class DatabaseOperations(BaseDatabaseOperations):
if timezone.is_aware(value):
raise ValueError("SQLite backend does not support timezone-aware times.")
- return unicode(value)
+ return six.text_type(value)
def year_lookup_bounds(self, value):
first = '%s-01-01'
diff --git a/django/db/models/base.py b/django/db/models/base.py
index 04ae4bc96d..8c448b2f39 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -375,7 +375,7 @@ class ModelWithoutMeta(object):
def __repr__(self):
try:
- u = unicode(self)
+ u = six.text_type(self)
except (UnicodeEncodeError, UnicodeDecodeError):
u = '[Bad Unicode data]'
return smart_str('<%s: %s>' % (self.__class__.__name__, u))
@@ -790,8 +790,8 @@ class ModelWithoutMeta(object):
def date_error_message(self, lookup_type, field, unique_for):
opts = self._meta
return _("%(field_name)s must be unique for %(date_field)s %(lookup)s.") % {
- 'field_name': unicode(capfirst(opts.get_field(field).verbose_name)),
- 'date_field': unicode(capfirst(opts.get_field(unique_for).verbose_name)),
+ 'field_name': six.text_type(capfirst(opts.get_field(field).verbose_name)),
+ 'date_field': six.text_type(capfirst(opts.get_field(unique_for).verbose_name)),
'lookup': lookup_type,
}
@@ -806,16 +806,16 @@ class ModelWithoutMeta(object):
field_label = capfirst(field.verbose_name)
# Insert the error into the error dict, very sneaky
return field.error_messages['unique'] % {
- 'model_name': unicode(model_name),
- 'field_label': unicode(field_label)
+ 'model_name': six.text_type(model_name),
+ 'field_label': six.text_type(field_label)
}
# unique_together
else:
field_labels = map(lambda f: capfirst(opts.get_field(f).verbose_name), unique_check)
field_labels = get_text_list(field_labels, _('and'))
return _("%(model_name)s with this %(field_label)s already exists.") % {
- 'model_name': unicode(model_name),
- 'field_label': unicode(field_labels)
+ 'model_name': six.text_type(model_name),
+ 'field_label': six.text_type(field_labels)
}
def full_clean(self, exclude=None):
diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py
index d3f1327315..b51ef1d5d6 100644
--- a/django/db/models/fields/files.py
+++ b/django/db/models/fields/files.py
@@ -265,7 +265,7 @@ class FileField(Field):
# Need to convert File objects provided via a form to unicode for database insertion
if value is None:
return None
- return unicode(value)
+ return six.text_type(value)
def pre_save(self, model_instance, add):
"Returns field's value just before saving."