diff options
Diffstat (limited to 'django/db/models')
| -rw-r--r-- | django/db/models/base.py | 16 | ||||
| -rw-r--r-- | django/db/models/expressions.py | 3 | ||||
| -rw-r--r-- | django/db/models/fields/__init__.py | 29 | ||||
| -rw-r--r-- | django/db/models/fields/files.py | 7 | ||||
| -rw-r--r-- | django/db/models/fields/related.py | 36 | ||||
| -rw-r--r-- | django/db/models/options.py | 4 | ||||
| -rw-r--r-- | django/db/models/query.py | 2 | ||||
| -rw-r--r-- | django/db/models/signals.py | 3 | ||||
| -rw-r--r-- | django/db/models/utils.py | 5 |
9 files changed, 47 insertions, 58 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py index 38d0b96217..95700edb13 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -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 diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py index 36c2b969db..960435f169 100644 --- a/django/db/models/expressions.py +++ b/django/db/models/expressions.py @@ -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 ] diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 2e21a42672..3ac04effc7 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -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 diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py index e52cc1164d..90b6515409 100644 --- a/django/db/models/fields/files.py +++ b/django/db/models/fields/files.py @@ -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." diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index 7f7a6d3ea8..65d0da41e1 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -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" % ( diff --git a/django/db/models/options.py b/django/db/models/options.py index a4593d125a..cf3e031104 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -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: diff --git a/django/db/models/query.py b/django/db/models/query.py index 2dbe3b7461..69f84d72a9 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -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 diff --git a/django/db/models/signals.py b/django/db/models/signals.py index 9f9fbccde3..a511024342 100644 --- a/django/db/models/signals.py +++ b/django/db/models/signals.py @@ -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: diff --git a/django/db/models/utils.py b/django/db/models/utils.py index cda96277a6..7d563c4ae0 100644 --- a/django/db/models/utils.py +++ b/django/db/models/utils.py @@ -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: |
