mirror of
https://github.com/django/django.git
synced 2025-10-26 15:16:09 +00:00
Refs #23919 -- Removed six.<various>_types usage
Thanks Tim Graham and Simon Charette for the reviews.
This commit is contained in:
@@ -5,7 +5,7 @@ from importlib import import_module
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.db.backends import utils
|
||||
from django.utils import six, timezone
|
||||
from django.utils import timezone
|
||||
from django.utils.dateparse import parse_duration
|
||||
from django.utils.encoding import force_text
|
||||
|
||||
@@ -201,17 +201,17 @@ class BaseDatabaseOperations(object):
|
||||
exists for database backends to provide a better implementation
|
||||
according to their own quoting schemes.
|
||||
"""
|
||||
# Convert params to contain Unicode values.
|
||||
def to_unicode(s):
|
||||
# Convert params to contain string values.
|
||||
def to_string(s):
|
||||
return force_text(s, strings_only=True, errors='replace')
|
||||
if isinstance(params, (list, tuple)):
|
||||
u_params = tuple(to_unicode(val) for val in params)
|
||||
u_params = tuple(to_string(val) for val in params)
|
||||
elif params is None:
|
||||
u_params = ()
|
||||
else:
|
||||
u_params = {to_unicode(k): to_unicode(v) for k, v in params.items()}
|
||||
u_params = {to_string(k): to_string(v) for k, v in params.items()}
|
||||
|
||||
return six.text_type("QUERY = %r - PARAMS = %r") % (sql, u_params)
|
||||
return "QUERY = %r - PARAMS = %r" % (sql, u_params)
|
||||
|
||||
def last_insert_id(self, cursor, table_name, pk_name):
|
||||
"""
|
||||
@@ -462,7 +462,7 @@ class BaseDatabaseOperations(object):
|
||||
"""
|
||||
if value is None:
|
||||
return None
|
||||
return six.text_type(value)
|
||||
return str(value)
|
||||
|
||||
def adapt_datetimefield_value(self, value):
|
||||
"""
|
||||
@@ -471,7 +471,7 @@ class BaseDatabaseOperations(object):
|
||||
"""
|
||||
if value is None:
|
||||
return None
|
||||
return six.text_type(value)
|
||||
return str(value)
|
||||
|
||||
def adapt_timefield_value(self, value):
|
||||
"""
|
||||
@@ -482,7 +482,7 @@ class BaseDatabaseOperations(object):
|
||||
return None
|
||||
if timezone.is_aware(value):
|
||||
raise ValueError("Django does not support timezone-aware times.")
|
||||
return six.text_type(value)
|
||||
return str(value)
|
||||
|
||||
def adapt_decimalfield_value(self, value, max_digits=None, decimal_places=None):
|
||||
"""
|
||||
|
||||
@@ -4,7 +4,7 @@ from datetime import datetime
|
||||
|
||||
from django.db.backends.utils import strip_quotes
|
||||
from django.db.transaction import TransactionManagementError, atomic
|
||||
from django.utils import six, timezone
|
||||
from django.utils import timezone
|
||||
from django.utils.encoding import force_bytes
|
||||
|
||||
logger = logging.getLogger('django.db.backends.schema')
|
||||
@@ -206,9 +206,9 @@ class BaseDatabaseSchemaEditor(object):
|
||||
default = field.get_default()
|
||||
elif not field.null and field.blank and field.empty_strings_allowed:
|
||||
if field.get_internal_type() == "BinaryField":
|
||||
default = six.binary_type()
|
||||
default = bytes()
|
||||
else:
|
||||
default = six.text_type()
|
||||
default = str()
|
||||
elif getattr(field, 'auto_now', False) or getattr(field, 'auto_now_add', False):
|
||||
default = datetime.now()
|
||||
internal_type = field.get_internal_type()
|
||||
|
||||
@@ -256,7 +256,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||
|
||||
def get_new_connection(self, conn_params):
|
||||
conn = Database.connect(**conn_params)
|
||||
conn.encoders[SafeText] = conn.encoders[six.text_type]
|
||||
conn.encoders[SafeText] = conn.encoders[str]
|
||||
conn.encoders[SafeBytes] = conn.encoders[bytes]
|
||||
return conn
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import uuid
|
||||
|
||||
from django.conf import settings
|
||||
from django.db.backends.base.operations import BaseDatabaseOperations
|
||||
from django.utils import six, timezone
|
||||
from django.utils import timezone
|
||||
from django.utils.encoding import force_text
|
||||
|
||||
|
||||
@@ -168,7 +168,7 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||
if not self.connection.features.supports_microsecond_precision:
|
||||
value = value.replace(microsecond=0)
|
||||
|
||||
return six.text_type(value)
|
||||
return str(value)
|
||||
|
||||
def adapt_timefield_value(self, value):
|
||||
if value is None:
|
||||
@@ -182,7 +182,7 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||
if timezone.is_aware(value):
|
||||
raise ValueError("MySQL backend does not support timezone-aware times.")
|
||||
|
||||
return six.text_type(value)
|
||||
return str(value)
|
||||
|
||||
def max_name_length(self):
|
||||
return 64
|
||||
|
||||
@@ -338,7 +338,7 @@ class OracleParam(object):
|
||||
# To transmit to the database, we need Unicode if supported
|
||||
# To get size right, we must consider bytes.
|
||||
self.force_bytes = force_text(param, cursor.charset, strings_only)
|
||||
if isinstance(self.force_bytes, six.string_types):
|
||||
if isinstance(self.force_bytes, str):
|
||||
# We could optimize by only converting up to 4000 bytes here
|
||||
string_size = len(force_bytes(param, cursor.charset, strings_only))
|
||||
if hasattr(param, 'input_size'):
|
||||
@@ -566,18 +566,5 @@ def _rowfactory(row, cursor):
|
||||
value = decimal.Decimal(value)
|
||||
else:
|
||||
value = int(value)
|
||||
elif desc[1] in (Database.STRING, Database.FIXED_CHAR,
|
||||
Database.LONG_STRING):
|
||||
value = to_unicode(value)
|
||||
casted.append(value)
|
||||
return tuple(casted)
|
||||
|
||||
|
||||
def to_unicode(s):
|
||||
"""
|
||||
Convert strings to Unicode objects (and return all other data types
|
||||
unchanged).
|
||||
"""
|
||||
if isinstance(s, six.string_types):
|
||||
return force_text(s)
|
||||
return s
|
||||
|
||||
@@ -5,7 +5,7 @@ import uuid
|
||||
from django.conf import settings
|
||||
from django.db.backends.base.operations import BaseDatabaseOperations
|
||||
from django.db.backends.utils import strip_quotes, truncate_name
|
||||
from django.utils import six, timezone
|
||||
from django.utils import timezone
|
||||
from django.utils.encoding import force_bytes, force_text
|
||||
|
||||
from .base import Database
|
||||
@@ -490,7 +490,7 @@ WHEN (new.%(col_name)s IS NULL)
|
||||
if hasattr(value, 'resolve_expression'):
|
||||
return value
|
||||
|
||||
if isinstance(value, six.string_types):
|
||||
if isinstance(value, str):
|
||||
return datetime.datetime.strptime(value, '%H:%M:%S')
|
||||
|
||||
# Oracle doesn't support tz-aware times
|
||||
|
||||
@@ -5,7 +5,6 @@ import re
|
||||
|
||||
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
||||
from django.db.utils import DatabaseError
|
||||
from django.utils import six
|
||||
from django.utils.text import force_text
|
||||
|
||||
|
||||
@@ -23,9 +22,9 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
|
||||
def quote_value(self, value):
|
||||
if isinstance(value, (datetime.date, datetime.time, datetime.datetime)):
|
||||
return "'%s'" % value
|
||||
elif isinstance(value, six.string_types):
|
||||
return "'%s'" % six.text_type(value).replace("\'", "\'\'")
|
||||
elif isinstance(value, six.buffer_types):
|
||||
elif isinstance(value, str):
|
||||
return "'%s'" % value.replace("\'", "\'\'")
|
||||
elif isinstance(value, (bytes, bytearray, memoryview)):
|
||||
return "'%s'" % force_text(binascii.hexlify(value))
|
||||
elif isinstance(value, bool):
|
||||
return "1" if value else "0"
|
||||
|
||||
@@ -14,7 +14,7 @@ from django.core.exceptions import ImproperlyConfigured
|
||||
from django.db import utils
|
||||
from django.db.backends import utils as backend_utils
|
||||
from django.db.backends.base.base import BaseDatabaseWrapper
|
||||
from django.utils import six, timezone
|
||||
from django.utils import timezone
|
||||
from django.utils.dateparse import (
|
||||
parse_date, parse_datetime, parse_duration, parse_time,
|
||||
)
|
||||
@@ -425,12 +425,12 @@ def _sqlite_format_dtdelta(conn, lhs, rhs):
|
||||
- A string representing a datetime
|
||||
"""
|
||||
try:
|
||||
if isinstance(lhs, six.integer_types):
|
||||
if isinstance(lhs, int):
|
||||
lhs = str(decimal.Decimal(lhs) / decimal.Decimal(1000000))
|
||||
real_lhs = parse_duration(lhs)
|
||||
if real_lhs is None:
|
||||
real_lhs = backend_utils.typecast_timestamp(lhs)
|
||||
if isinstance(rhs, six.integer_types):
|
||||
if isinstance(rhs, int):
|
||||
rhs = str(decimal.Decimal(rhs) / decimal.Decimal(1000000))
|
||||
real_rhs = parse_duration(rhs)
|
||||
if real_rhs is None:
|
||||
|
||||
@@ -7,7 +7,7 @@ from django.db import utils
|
||||
from django.db.backends import utils as backend_utils
|
||||
from django.db.backends.base.operations import BaseDatabaseOperations
|
||||
from django.db.models import aggregates, fields
|
||||
from django.utils import six, timezone
|
||||
from django.utils import timezone
|
||||
from django.utils.dateparse import parse_date, parse_datetime, parse_time
|
||||
from django.utils.duration import duration_string
|
||||
|
||||
@@ -178,7 +178,7 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||
else:
|
||||
raise ValueError("SQLite backend does not support timezone-aware datetimes when USE_TZ is False.")
|
||||
|
||||
return six.text_type(value)
|
||||
return str(value)
|
||||
|
||||
def adapt_timefield_value(self, value):
|
||||
if value is None:
|
||||
@@ -192,7 +192,7 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||
if timezone.is_aware(value):
|
||||
raise ValueError("SQLite backend does not support timezone-aware times.")
|
||||
|
||||
return six.text_type(value)
|
||||
return str(value)
|
||||
|
||||
def get_db_converters(self, expression):
|
||||
converters = super(DatabaseOperations, self).get_db_converters(expression)
|
||||
|
||||
@@ -5,7 +5,6 @@ from decimal import Decimal
|
||||
|
||||
from django.apps.registry import Apps
|
||||
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
||||
from django.utils import six
|
||||
|
||||
|
||||
class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
|
||||
@@ -46,15 +45,13 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
|
||||
# Manual emulation of SQLite parameter quoting
|
||||
if isinstance(value, type(True)):
|
||||
return str(int(value))
|
||||
elif isinstance(value, (Decimal, float)):
|
||||
elif isinstance(value, (Decimal, float, int)):
|
||||
return str(value)
|
||||
elif isinstance(value, six.integer_types):
|
||||
return str(value)
|
||||
elif isinstance(value, six.string_types):
|
||||
return "'%s'" % six.text_type(value).replace("\'", "\'\'")
|
||||
elif isinstance(value, str):
|
||||
return "'%s'" % value.replace("\'", "\'\'")
|
||||
elif value is None:
|
||||
return "NULL"
|
||||
elif isinstance(value, (bytes, bytearray, six.memoryview)):
|
||||
elif isinstance(value, (bytes, bytearray, memoryview)):
|
||||
# Bytes are only allowed for BLOB fields, encoded as string
|
||||
# literals containing hexadecimal data and preceded by a single "X"
|
||||
# character:
|
||||
|
||||
@@ -12,7 +12,6 @@ from django.db.migrations.questioner import MigrationQuestioner
|
||||
from django.db.migrations.utils import (
|
||||
COMPILED_REGEX_TYPE, RegexObject, get_migration_name_timestamp,
|
||||
)
|
||||
from django.utils import six
|
||||
|
||||
from .topological_sort import stable_topological_sort
|
||||
|
||||
@@ -538,7 +537,7 @@ class MigrationAutodetector(object):
|
||||
]
|
||||
# Depend on all bases
|
||||
for base in model_state.bases:
|
||||
if isinstance(base, six.string_types) and "." in base:
|
||||
if isinstance(base, str) and "." in base:
|
||||
base_app_label, base_name = base.split(".", 1)
|
||||
dependencies.append((base_app_label, base_name, None, True))
|
||||
# Depend on the other end of the primary key if it's a relation
|
||||
@@ -659,7 +658,7 @@ class MigrationAutodetector(object):
|
||||
]
|
||||
# Depend on all bases
|
||||
for base in model_state.bases:
|
||||
if isinstance(base, six.string_types) and "." in base:
|
||||
if isinstance(base, str) and "." in base:
|
||||
base_app_label, base_name = base.split(".", 1)
|
||||
dependencies.append((base_app_label, base_name, None, True))
|
||||
# Generate creation operation
|
||||
|
||||
@@ -3,7 +3,6 @@ from django.db.migrations.operations.base import Operation
|
||||
from django.db.migrations.state import ModelState
|
||||
from django.db.models.fields.related import RECURSIVE_RELATIONSHIP_CONSTANT
|
||||
from django.db.models.options import normalize_together
|
||||
from django.utils import six
|
||||
from django.utils.functional import cached_property
|
||||
|
||||
from .fields import (
|
||||
@@ -57,7 +56,7 @@ class CreateModel(ModelOperation):
|
||||
_check_for_duplicates('fields', (name for name, _ in self.fields))
|
||||
_check_for_duplicates('bases', (
|
||||
base._meta.label_lower if hasattr(base, '_meta') else
|
||||
base.lower() if isinstance(base, six.string_types) else base
|
||||
base.lower() if isinstance(base, str) else base
|
||||
for base in self.bases
|
||||
))
|
||||
_check_for_duplicates('managers', (name for name, _ in self.managers))
|
||||
@@ -110,7 +109,7 @@ class CreateModel(ModelOperation):
|
||||
# Check we didn't inherit from the model
|
||||
models_to_check = [
|
||||
base for base in self.bases
|
||||
if base is not models.Model and isinstance(base, (models.base.ModelBase, six.string_types))
|
||||
if base is not models.Model and isinstance(base, (models.base.ModelBase, str))
|
||||
]
|
||||
# Check we have no FKs/M2Ms with it
|
||||
for fname, field in self.fields:
|
||||
@@ -129,7 +128,7 @@ class CreateModel(ModelOperation):
|
||||
Take either a model class or an "app_label.ModelName" string
|
||||
and return (app_label, object_name).
|
||||
"""
|
||||
if isinstance(model, six.string_types):
|
||||
if isinstance(model, str):
|
||||
return model.split(".", 1)
|
||||
else:
|
||||
return model._meta.app_label, model._meta.object_name
|
||||
|
||||
@@ -362,11 +362,11 @@ def serializer_factory(value):
|
||||
return SettingsReferenceSerializer(value)
|
||||
if isinstance(value, float):
|
||||
return FloatSerializer(value)
|
||||
if isinstance(value, six.integer_types + (bool, type(None))):
|
||||
if isinstance(value, (bool, int, type(None))):
|
||||
return BaseSimpleSerializer(value)
|
||||
if isinstance(value, six.binary_type):
|
||||
if isinstance(value, bytes):
|
||||
return ByteTypeSerializer(value)
|
||||
if isinstance(value, six.text_type):
|
||||
if isinstance(value, str):
|
||||
return TextTypeSerializer(value)
|
||||
if isinstance(value, decimal.Decimal):
|
||||
return DecimalSerializer(value)
|
||||
|
||||
@@ -10,7 +10,6 @@ from django.db.models.fields.proxy import OrderWrt
|
||||
from django.db.models.fields.related import RECURSIVE_RELATIONSHIP_CONSTANT
|
||||
from django.db.models.options import DEFAULT_NAMES, normalize_together
|
||||
from django.db.models.utils import make_model_tuple
|
||||
from django.utils import six
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.module_loading import import_string
|
||||
@@ -20,7 +19,7 @@ from .exceptions import InvalidBasesError
|
||||
|
||||
|
||||
def _get_app_label_and_model_name(model, app_label=''):
|
||||
if isinstance(model, six.string_types):
|
||||
if isinstance(model, str):
|
||||
split = model.split('.', 1)
|
||||
return (tuple(split) if len(split) == 2 else (app_label, split[0]))
|
||||
else:
|
||||
@@ -37,7 +36,7 @@ def _get_related_models(m):
|
||||
]
|
||||
related_fields_models = set()
|
||||
for f in m._meta.get_fields(include_parents=True, include_hidden=True):
|
||||
if f.is_relation and f.related_model is not None and not isinstance(f.related_model, six.string_types):
|
||||
if f.is_relation and f.related_model is not None and not isinstance(f.related_model, str):
|
||||
related_fields_models.add(f.model)
|
||||
related_models.append(f.related_model)
|
||||
# Reverse accessors of foreign keys to proxy models are attached to their
|
||||
@@ -458,7 +457,7 @@ class ModelState(object):
|
||||
options[name] = set(normalize_together(it))
|
||||
else:
|
||||
options[name] = model._meta.original_attrs[name]
|
||||
# Force-convert all options to text_type (#23226)
|
||||
# Force-convert all options to str (#23226)
|
||||
options = cls.force_text_recursive(options)
|
||||
# If we're ignoring relationships, remove all field-listing model
|
||||
# options (that option basically just means "make a stub model")
|
||||
@@ -496,7 +495,7 @@ class ModelState(object):
|
||||
for base in flattened_bases
|
||||
)
|
||||
# Ensure at least one base inherits from models.Model
|
||||
if not any((isinstance(base, six.string_types) or issubclass(base, models.Model)) for base in bases):
|
||||
if not any((isinstance(base, str) or issubclass(base, models.Model)) for base in bases):
|
||||
bases = (models.Model,)
|
||||
|
||||
managers = []
|
||||
@@ -539,9 +538,7 @@ class ModelState(object):
|
||||
|
||||
@classmethod
|
||||
def force_text_recursive(cls, value):
|
||||
if isinstance(value, six.string_types):
|
||||
return force_text(value)
|
||||
elif isinstance(value, list):
|
||||
if isinstance(value, list):
|
||||
return [cls.force_text_recursive(x) for x in value]
|
||||
elif isinstance(value, tuple):
|
||||
return tuple(cls.force_text_recursive(x) for x in value)
|
||||
@@ -588,7 +585,7 @@ class ModelState(object):
|
||||
# Then, work out our bases
|
||||
try:
|
||||
bases = tuple(
|
||||
(apps.get_model(base) if isinstance(base, six.string_types) else base)
|
||||
(apps.get_model(base) if isinstance(base, str) else base)
|
||||
for base in self.bases
|
||||
)
|
||||
except LookupError:
|
||||
|
||||
@@ -504,7 +504,7 @@ class Model(six.with_metaclass(ModelBase)):
|
||||
|
||||
def __repr__(self):
|
||||
try:
|
||||
u = six.text_type(self)
|
||||
u = str(self)
|
||||
except (UnicodeEncodeError, UnicodeDecodeError):
|
||||
u = '[Bad Unicode data]'
|
||||
return force_str('<%s: %s>' % (self.__class__.__name__, u))
|
||||
@@ -1089,12 +1089,12 @@ class Model(six.with_metaclass(ModelBase)):
|
||||
code='unique_for_date',
|
||||
params={
|
||||
'model': self,
|
||||
'model_name': six.text_type(capfirst(opts.verbose_name)),
|
||||
'model_name': capfirst(opts.verbose_name),
|
||||
'lookup_type': lookup_type,
|
||||
'field': field_name,
|
||||
'field_label': six.text_type(capfirst(field.verbose_name)),
|
||||
'field_label': capfirst(field.verbose_name),
|
||||
'date_field': unique_for,
|
||||
'date_field_label': six.text_type(capfirst(opts.get_field(unique_for).verbose_name)),
|
||||
'date_field_label': capfirst(opts.get_field(unique_for).verbose_name),
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1104,14 +1104,14 @@ class Model(six.with_metaclass(ModelBase)):
|
||||
params = {
|
||||
'model': self,
|
||||
'model_class': model_class,
|
||||
'model_name': six.text_type(capfirst(opts.verbose_name)),
|
||||
'model_name': capfirst(opts.verbose_name),
|
||||
'unique_check': unique_check,
|
||||
}
|
||||
|
||||
# A unique field
|
||||
if len(unique_check) == 1:
|
||||
field = opts.get_field(unique_check[0])
|
||||
params['field_label'] = six.text_type(capfirst(field.verbose_name))
|
||||
params['field_label'] = capfirst(field.verbose_name)
|
||||
return ValidationError(
|
||||
message=field.error_messages['unique'],
|
||||
code='unique',
|
||||
@@ -1121,7 +1121,7 @@ class Model(six.with_metaclass(ModelBase)):
|
||||
# unique_together
|
||||
else:
|
||||
field_labels = [capfirst(opts.get_field(f).verbose_name) for f in unique_check]
|
||||
params['field_labels'] = six.text_type(get_text_list(field_labels, _('and')))
|
||||
params['field_labels'] = get_text_list(field_labels, _('and'))
|
||||
return ValidationError(
|
||||
message=_("%(model_name)s with this %(field_labels)s already exists."),
|
||||
code='unique_together',
|
||||
@@ -1647,7 +1647,7 @@ class Model(six.with_metaclass(ModelBase)):
|
||||
|
||||
for f in cls._meta.local_many_to_many:
|
||||
# Skip nonexistent models.
|
||||
if isinstance(f.remote_field.through, six.string_types):
|
||||
if isinstance(f.remote_field.through, str):
|
||||
continue
|
||||
|
||||
# Check if auto-generated name for the M2M field is too long
|
||||
|
||||
@@ -5,7 +5,6 @@ from django.core.exceptions import EmptyResultSet, FieldError
|
||||
from django.db.backends import utils as backend_utils
|
||||
from django.db.models import fields
|
||||
from django.db.models.query_utils import Q
|
||||
from django.utils import six
|
||||
from django.utils.functional import cached_property
|
||||
|
||||
|
||||
@@ -149,7 +148,7 @@ class BaseExpression(object):
|
||||
def _parse_expressions(self, *expressions):
|
||||
return [
|
||||
arg if hasattr(arg, 'resolve_expression') else (
|
||||
F(arg) if isinstance(arg, six.string_types) else Value(arg)
|
||||
F(arg) if isinstance(arg, str) else Value(arg)
|
||||
) for arg in expressions
|
||||
]
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ from django.core.exceptions import FieldDoesNotExist # NOQA
|
||||
from django.db import connection, connections, router
|
||||
from django.db.models.constants import LOOKUP_SEP
|
||||
from django.db.models.query_utils import DeferredAttribute, RegisterLookupMixin
|
||||
from django.utils import six, timezone
|
||||
from django.utils import timezone
|
||||
from django.utils.datastructures import DictWrapper
|
||||
from django.utils.dateparse import (
|
||||
parse_date, parse_datetime, parse_duration, parse_time,
|
||||
@@ -244,8 +244,7 @@ class Field(RegisterLookupMixin):
|
||||
|
||||
def _check_choices(self):
|
||||
if self.choices:
|
||||
if (isinstance(self.choices, six.string_types) or
|
||||
not is_iterable(self.choices)):
|
||||
if isinstance(self.choices, str) or not is_iterable(self.choices):
|
||||
return [
|
||||
checks.Error(
|
||||
"'choices' must be an iterable (e.g., a list or tuple).",
|
||||
@@ -253,7 +252,7 @@ class Field(RegisterLookupMixin):
|
||||
id='fields.E004',
|
||||
)
|
||||
]
|
||||
elif any(isinstance(choice, six.string_types) or
|
||||
elif any(isinstance(choice, str) or
|
||||
not is_iterable(choice) or len(choice) != 2
|
||||
for choice in self.choices):
|
||||
return [
|
||||
@@ -763,7 +762,7 @@ class Field(RegisterLookupMixin):
|
||||
|
||||
if not self.empty_strings_allowed or self.null and not connection.features.interprets_empty_strings_as_nulls:
|
||||
return return_None
|
||||
return six.text_type # returns empty string
|
||||
return str # returns empty string
|
||||
|
||||
def get_choices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH, limit_choices_to=None):
|
||||
"""Returns choices with a default blank choices included, for use
|
||||
@@ -1038,7 +1037,7 @@ class CharField(Field):
|
||||
id='fields.E120',
|
||||
)
|
||||
]
|
||||
elif not isinstance(self.max_length, six.integer_types) or self.max_length <= 0:
|
||||
elif not isinstance(self.max_length, int) or self.max_length <= 0:
|
||||
return [
|
||||
checks.Error(
|
||||
"'max_length' must be a positive integer.",
|
||||
@@ -1053,7 +1052,7 @@ class CharField(Field):
|
||||
return "CharField"
|
||||
|
||||
def to_python(self, value):
|
||||
if isinstance(value, six.string_types) or value is None:
|
||||
if isinstance(value, str) or value is None:
|
||||
return value
|
||||
return force_text(value)
|
||||
|
||||
@@ -1535,7 +1534,7 @@ class DecimalField(Field):
|
||||
)
|
||||
|
||||
def _format(self, value):
|
||||
if isinstance(value, six.string_types):
|
||||
if isinstance(value, str):
|
||||
return value
|
||||
else:
|
||||
return self.format_number(value)
|
||||
@@ -1703,7 +1702,7 @@ class FilePathField(Field):
|
||||
value = super(FilePathField, self).get_prep_value(value)
|
||||
if value is None:
|
||||
return None
|
||||
return six.text_type(value)
|
||||
return str(value)
|
||||
|
||||
def formfield(self, **kwargs):
|
||||
defaults = {
|
||||
@@ -1867,7 +1866,7 @@ class IPAddressField(Field):
|
||||
value = super(IPAddressField, self).get_prep_value(value)
|
||||
if value is None:
|
||||
return None
|
||||
return six.text_type(value)
|
||||
return str(value)
|
||||
|
||||
def get_internal_type(self):
|
||||
return "IPAddressField"
|
||||
@@ -1922,7 +1921,7 @@ class GenericIPAddressField(Field):
|
||||
def to_python(self, value):
|
||||
if value is None:
|
||||
return None
|
||||
if not isinstance(value, six.string_types):
|
||||
if not isinstance(value, str):
|
||||
value = force_text(value)
|
||||
value = value.strip()
|
||||
if ':' in value:
|
||||
@@ -1943,7 +1942,7 @@ class GenericIPAddressField(Field):
|
||||
return clean_ipv6_address(value, self.unpack_ipv4)
|
||||
except exceptions.ValidationError:
|
||||
pass
|
||||
return six.text_type(value)
|
||||
return str(value)
|
||||
|
||||
def formfield(self, **kwargs):
|
||||
defaults = {
|
||||
@@ -2094,7 +2093,7 @@ class TextField(Field):
|
||||
return "TextField"
|
||||
|
||||
def to_python(self, value):
|
||||
if isinstance(value, six.string_types) or value is None:
|
||||
if isinstance(value, str) or value is None:
|
||||
return value
|
||||
return force_text(value)
|
||||
|
||||
@@ -2310,8 +2309,8 @@ class BinaryField(Field):
|
||||
|
||||
def to_python(self, value):
|
||||
# If it's a string, it should be base64-encoded data
|
||||
if isinstance(value, six.text_type):
|
||||
return six.memoryview(b64decode(force_bytes(value)))
|
||||
if isinstance(value, str):
|
||||
return memoryview(b64decode(force_bytes(value)))
|
||||
return value
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ from django.core.files.storage import default_storage
|
||||
from django.core.validators import validate_image_file_extension
|
||||
from django.db.models import signals
|
||||
from django.db.models.fields import Field
|
||||
from django.utils import six
|
||||
from django.utils.encoding import force_str, force_text
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
@@ -181,7 +180,7 @@ class FileDescriptor(object):
|
||||
# subclasses might also want to subclass the attribute class]. This
|
||||
# object understands how to convert a path to a file, and also how to
|
||||
# handle None.
|
||||
if isinstance(file, six.string_types) or file is None:
|
||||
if isinstance(file, str) or file is None:
|
||||
attr = self.field.attr_class(instance, self.field, file)
|
||||
instance.__dict__[self.field.name] = attr
|
||||
|
||||
@@ -253,7 +252,7 @@ class FileField(Field):
|
||||
return []
|
||||
|
||||
def _check_upload_to(self):
|
||||
if isinstance(self.upload_to, six.string_types) and self.upload_to.startswith('/'):
|
||||
if isinstance(self.upload_to, str) and self.upload_to.startswith('/'):
|
||||
return [
|
||||
checks.Error(
|
||||
"%s's 'upload_to' argument must be a relative path, not an "
|
||||
@@ -284,7 +283,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 six.text_type(value)
|
||||
return str(value)
|
||||
|
||||
def pre_save(self, model_instance, add):
|
||||
"Returns field's value just before saving."
|
||||
|
||||
@@ -11,7 +11,6 @@ from django.db.models.constants import LOOKUP_SEP
|
||||
from django.db.models.deletion import CASCADE, SET_DEFAULT, SET_NULL
|
||||
from django.db.models.query_utils import PathInfo
|
||||
from django.db.models.utils import make_model_tuple
|
||||
from django.utils import six
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.functional import cached_property, curry
|
||||
from django.utils.lru_cache import lru_cache
|
||||
@@ -52,7 +51,7 @@ def resolve_relation(scope_model, relation):
|
||||
relation = scope_model
|
||||
|
||||
# Look for an "app.Model" relation
|
||||
if isinstance(relation, six.string_types):
|
||||
if isinstance(relation, str):
|
||||
if "." not in relation:
|
||||
relation = "%s.%s" % (scope_model._meta.app_label, relation)
|
||||
|
||||
@@ -160,7 +159,7 @@ class RelatedField(Field):
|
||||
|
||||
def _check_relation_model_exists(self):
|
||||
rel_is_missing = self.remote_field.model not in self.opts.apps.get_models()
|
||||
rel_is_string = isinstance(self.remote_field.model, six.string_types)
|
||||
rel_is_string = isinstance(self.remote_field.model, str)
|
||||
model_name = self.remote_field.model if rel_is_string else self.remote_field.model._meta.object_name
|
||||
if rel_is_missing and (rel_is_string or not self.remote_field.model._meta.swapped):
|
||||
return [
|
||||
@@ -175,7 +174,7 @@ class RelatedField(Field):
|
||||
|
||||
def _check_referencing_to_swapped_model(self):
|
||||
if (self.remote_field.model not in self.opts.apps.get_models() and
|
||||
not isinstance(self.remote_field.model, six.string_types) and
|
||||
not isinstance(self.remote_field.model, str) and
|
||||
self.remote_field.model._meta.swapped):
|
||||
model = "%s.%s" % (
|
||||
self.remote_field.model._meta.app_label,
|
||||
@@ -364,7 +363,7 @@ class RelatedField(Field):
|
||||
"""
|
||||
if self.swappable:
|
||||
# Work out string form of "to"
|
||||
if isinstance(self.remote_field.model, six.string_types):
|
||||
if isinstance(self.remote_field.model, str):
|
||||
to_string = self.remote_field.model
|
||||
else:
|
||||
to_string = self.remote_field.model._meta.label
|
||||
@@ -479,7 +478,7 @@ class ForeignObject(RelatedField):
|
||||
|
||||
def _check_to_fields_exist(self):
|
||||
# Skip nonexistent models.
|
||||
if isinstance(self.remote_field.model, six.string_types):
|
||||
if isinstance(self.remote_field.model, str):
|
||||
return []
|
||||
|
||||
errors = []
|
||||
@@ -500,7 +499,7 @@ class ForeignObject(RelatedField):
|
||||
return errors
|
||||
|
||||
def _check_unique_target(self):
|
||||
rel_is_string = isinstance(self.remote_field.model, six.string_types)
|
||||
rel_is_string = isinstance(self.remote_field.model, str)
|
||||
if rel_is_string or not self.requires_unique_target:
|
||||
return []
|
||||
|
||||
@@ -568,7 +567,7 @@ class ForeignObject(RelatedField):
|
||||
if self.remote_field.parent_link:
|
||||
kwargs['parent_link'] = self.remote_field.parent_link
|
||||
# Work out string form of "to"
|
||||
if isinstance(self.remote_field.model, six.string_types):
|
||||
if isinstance(self.remote_field.model, str):
|
||||
kwargs['to'] = self.remote_field.model
|
||||
else:
|
||||
kwargs['to'] = "%s.%s" % (
|
||||
@@ -598,7 +597,7 @@ class ForeignObject(RelatedField):
|
||||
def resolve_related_fields(self):
|
||||
if len(self.from_fields) < 1 or len(self.from_fields) != len(self.to_fields):
|
||||
raise ValueError('Foreign Object from and to fields must be the same non-zero length')
|
||||
if isinstance(self.remote_field.model, six.string_types):
|
||||
if isinstance(self.remote_field.model, str):
|
||||
raise ValueError('Related model %r cannot be resolved' % self.remote_field.model)
|
||||
related_fields = []
|
||||
for index in range(len(self.from_fields)):
|
||||
@@ -772,7 +771,7 @@ class ForeignKey(ForeignObject):
|
||||
try:
|
||||
to._meta.model_name
|
||||
except AttributeError:
|
||||
assert isinstance(to, six.string_types), (
|
||||
assert isinstance(to, str), (
|
||||
"%s(%r) is invalid. First parameter to ForeignKey must be "
|
||||
"either a model, a model name, or the string %r" % (
|
||||
self.__class__.__name__, to,
|
||||
@@ -926,7 +925,7 @@ class ForeignKey(ForeignObject):
|
||||
|
||||
def formfield(self, **kwargs):
|
||||
db = kwargs.pop('using', None)
|
||||
if isinstance(self.remote_field.model, six.string_types):
|
||||
if isinstance(self.remote_field.model, str):
|
||||
raise ValueError("Cannot create form field for %r yet, because "
|
||||
"its related model %r has not been loaded yet" %
|
||||
(self.name, self.remote_field.model))
|
||||
@@ -948,7 +947,7 @@ class ForeignKey(ForeignObject):
|
||||
return {"type": self.db_type(connection), "check": self.db_check(connection)}
|
||||
|
||||
def convert_empty_strings(self, value, expression, connection, context):
|
||||
if (not value) and isinstance(value, six.string_types):
|
||||
if (not value) and isinstance(value, str):
|
||||
return None
|
||||
return value
|
||||
|
||||
@@ -1082,14 +1081,11 @@ class ManyToManyField(RelatedField):
|
||||
try:
|
||||
to._meta
|
||||
except AttributeError:
|
||||
assert isinstance(to, six.string_types), (
|
||||
assert isinstance(to, str), (
|
||||
"%s(%r) is invalid. First parameter to ManyToManyField must be "
|
||||
"either a model, a model name, or the string %r" %
|
||||
(self.__class__.__name__, to, RECURSIVE_RELATIONSHIP_CONSTANT)
|
||||
)
|
||||
# Class names must be ASCII in Python 2.x, so we forcibly coerce it
|
||||
# here to break early if there's a problem.
|
||||
to = str(to)
|
||||
|
||||
if symmetrical is None:
|
||||
symmetrical = (to == RECURSIVE_RELATIONSHIP_CONSTANT)
|
||||
@@ -1197,7 +1193,7 @@ class ManyToManyField(RelatedField):
|
||||
# Set some useful local variables
|
||||
to_model = resolve_relation(from_model, self.remote_field.model)
|
||||
from_model_name = from_model._meta.object_name
|
||||
if isinstance(to_model, six.string_types):
|
||||
if isinstance(to_model, str):
|
||||
to_model_name = to_model
|
||||
else:
|
||||
to_model_name = to_model._meta.object_name
|
||||
@@ -1368,7 +1364,7 @@ class ManyToManyField(RelatedField):
|
||||
return errors
|
||||
|
||||
def _check_table_uniqueness(self, **kwargs):
|
||||
if isinstance(self.remote_field.through, six.string_types) or not self.remote_field.through._meta.managed:
|
||||
if isinstance(self.remote_field.through, str) or not self.remote_field.through._meta.managed:
|
||||
return []
|
||||
registered_tables = {
|
||||
model._meta.db_table: model
|
||||
@@ -1411,7 +1407,7 @@ class ManyToManyField(RelatedField):
|
||||
if self.remote_field.related_query_name is not None:
|
||||
kwargs['related_query_name'] = self.remote_field.related_query_name
|
||||
# Rel needs more work.
|
||||
if isinstance(self.remote_field.model, six.string_types):
|
||||
if isinstance(self.remote_field.model, str):
|
||||
kwargs['to'] = self.remote_field.model
|
||||
else:
|
||||
kwargs['to'] = "%s.%s" % (
|
||||
@@ -1419,7 +1415,7 @@ class ManyToManyField(RelatedField):
|
||||
self.remote_field.model._meta.object_name,
|
||||
)
|
||||
if getattr(self.remote_field, 'through', None) is not None:
|
||||
if isinstance(self.remote_field.through, six.string_types):
|
||||
if isinstance(self.remote_field.through, str):
|
||||
kwargs['through'] = self.remote_field.through
|
||||
elif not self.remote_field.through._meta.auto_created:
|
||||
kwargs['through'] = "%s.%s" % (
|
||||
|
||||
@@ -310,7 +310,7 @@ class Options(object):
|
||||
"""
|
||||
if self.proxy or self.swapped or not self.managed:
|
||||
return False
|
||||
if isinstance(connection, six.string_types):
|
||||
if isinstance(connection, str):
|
||||
connection = connections[connection]
|
||||
if self.required_db_vendor:
|
||||
return self.required_db_vendor == connection.vendor
|
||||
@@ -689,7 +689,7 @@ class Options(object):
|
||||
if f.is_relation and f.related_model is not None
|
||||
)
|
||||
for f in fields_with_relations:
|
||||
if not isinstance(f.remote_field.model, six.string_types):
|
||||
if not isinstance(f.remote_field.model, str):
|
||||
related_objects_graph[f.remote_field.model._meta.concrete_model._meta].append(f)
|
||||
|
||||
for model in all_models:
|
||||
|
||||
@@ -260,7 +260,7 @@ class QuerySet(object):
|
||||
"""
|
||||
Retrieves an item or slice from the set of results.
|
||||
"""
|
||||
if not isinstance(k, (slice,) + six.integer_types):
|
||||
if not isinstance(k, (int, slice)):
|
||||
raise TypeError
|
||||
assert ((not isinstance(k, slice) and (k >= 0)) or
|
||||
(isinstance(k, slice) and (k.start is None or k.start >= 0) and
|
||||
|
||||
@@ -2,7 +2,6 @@ from functools import partial
|
||||
|
||||
from django.db.models.utils import make_model_tuple
|
||||
from django.dispatch import Signal
|
||||
from django.utils import six
|
||||
|
||||
|
||||
class_prepared = Signal(providing_args=["class"])
|
||||
@@ -18,7 +17,7 @@ class ModelSignal(Signal):
|
||||
|
||||
# This partial takes a single optional argument named "sender".
|
||||
partial_method = partial(method, receiver, **kwargs)
|
||||
if isinstance(sender, six.string_types):
|
||||
if isinstance(sender, str):
|
||||
apps = apps or Options.default_apps
|
||||
apps.lazy_model_operation(partial_method, make_model_tuple(sender))
|
||||
else:
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
from django.utils import six
|
||||
|
||||
|
||||
def make_model_tuple(model):
|
||||
"""
|
||||
Takes a model or a string of the form "app_label.ModelName" and returns a
|
||||
@@ -10,7 +7,7 @@ def make_model_tuple(model):
|
||||
try:
|
||||
if isinstance(model, tuple):
|
||||
model_tuple = model
|
||||
elif isinstance(model, six.string_types):
|
||||
elif isinstance(model, str):
|
||||
app_label, model_name = model.split(".")
|
||||
model_tuple = app_label, model_name.lower()
|
||||
else:
|
||||
|
||||
@@ -247,7 +247,7 @@ class ConnectionRouter(object):
|
||||
self._routers = settings.DATABASE_ROUTERS
|
||||
routers = []
|
||||
for r in self._routers:
|
||||
if isinstance(r, six.string_types):
|
||||
if isinstance(r, str):
|
||||
router = import_string(r)()
|
||||
else:
|
||||
router = r
|
||||
|
||||
Reference in New Issue
Block a user