diff options
Diffstat (limited to 'django/db/models/fields')
| -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 |
3 files changed, 33 insertions, 39 deletions
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" % ( |
