mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Refs #23919 -- Removed six.<various>_types usage
Thanks Tim Graham and Simon Charette for the reviews.
This commit is contained in:
@@ -3,7 +3,6 @@ import warnings
|
||||
|
||||
from django.forms.utils import flatatt, pretty_name
|
||||
from django.forms.widgets import Textarea, TextInput
|
||||
from django.utils import six
|
||||
from django.utils.deprecation import RemovedInDjango21Warning
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.functional import cached_property
|
||||
@@ -63,7 +62,7 @@ class BoundField(object):
|
||||
def __getitem__(self, idx):
|
||||
# Prevent unnecessary reevaluation when accessing BoundField's attrs
|
||||
# from templates.
|
||||
if not isinstance(idx, six.integer_types + (slice,)):
|
||||
if not isinstance(idx, (int, slice)):
|
||||
raise TypeError
|
||||
return self.subwidgets[idx]
|
||||
|
||||
|
||||
@@ -393,10 +393,10 @@ class BaseTemporalField(Field):
|
||||
def to_python(self, value):
|
||||
# Try to coerce the value to unicode.
|
||||
unicode_value = force_text(value, strings_only=True)
|
||||
if isinstance(unicode_value, six.text_type):
|
||||
if isinstance(unicode_value, str):
|
||||
value = unicode_value.strip()
|
||||
# If unicode, try to strptime against each input format.
|
||||
if isinstance(value, six.text_type):
|
||||
if isinstance(value, str):
|
||||
for format in self.input_formats:
|
||||
try:
|
||||
return self.strptime(value, format)
|
||||
@@ -521,7 +521,7 @@ class RegexField(CharField):
|
||||
return self._regex
|
||||
|
||||
def _set_regex(self, regex):
|
||||
if isinstance(regex, six.string_types):
|
||||
if isinstance(regex, str):
|
||||
regex = re.compile(regex, re.UNICODE)
|
||||
self._regex = regex
|
||||
if hasattr(self, '_regex_validator') and self._regex_validator in self.validators:
|
||||
@@ -712,7 +712,7 @@ class BooleanField(Field):
|
||||
# will submit for False. Also check for '0', since this is what
|
||||
# RadioSelect will provide. Because bool("True") == bool('1') == True,
|
||||
# we don't need to handle that explicitly.
|
||||
if isinstance(value, six.string_types) and value.lower() in ('false', '0'):
|
||||
if isinstance(value, str) and value.lower() in ('false', '0'):
|
||||
value = False
|
||||
else:
|
||||
value = bool(value)
|
||||
|
||||
@@ -209,7 +209,7 @@ class BaseForm(object):
|
||||
top_errors.extend(
|
||||
[_('(Hidden field %(name)s) %(error)s') % {'name': name, 'error': force_text(e)}
|
||||
for e in bf_errors])
|
||||
hidden_fields.append(six.text_type(bf))
|
||||
hidden_fields.append(str(bf))
|
||||
else:
|
||||
# Create a 'class="..."' attribute if the row should have any
|
||||
# CSS classes applied.
|
||||
@@ -234,7 +234,7 @@ class BaseForm(object):
|
||||
output.append(normal_row % {
|
||||
'errors': force_text(bf_errors),
|
||||
'label': force_text(label),
|
||||
'field': six.text_type(bf),
|
||||
'field': str(bf),
|
||||
'help_text': help_text,
|
||||
'html_class_attr': html_class_attr,
|
||||
'css_classes': css_classes,
|
||||
|
||||
@@ -3,7 +3,6 @@ from django.forms import Form
|
||||
from django.forms.fields import BooleanField, IntegerField
|
||||
from django.forms.utils import ErrorList
|
||||
from django.forms.widgets import HiddenInput
|
||||
from django.utils import six
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.html import html_safe
|
||||
from django.utils.safestring import mark_safe
|
||||
@@ -416,17 +415,17 @@ class BaseFormSet(object):
|
||||
# probably should be. It might make sense to render each form as a
|
||||
# table row with each field as a td.
|
||||
forms = ' '.join(form.as_table() for form in self)
|
||||
return mark_safe('\n'.join([six.text_type(self.management_form), forms]))
|
||||
return mark_safe('\n'.join([str(self.management_form), forms]))
|
||||
|
||||
def as_p(self):
|
||||
"Returns this formset rendered as HTML <p>s."
|
||||
forms = ' '.join(form.as_p() for form in self)
|
||||
return mark_safe('\n'.join([six.text_type(self.management_form), forms]))
|
||||
return mark_safe('\n'.join([str(self.management_form), forms]))
|
||||
|
||||
def as_ul(self):
|
||||
"Returns this formset rendered as HTML <li>s."
|
||||
forms = ' '.join(form.as_ul() for form in self)
|
||||
return mark_safe('\n'.join([six.text_type(self.management_form), forms]))
|
||||
return mark_safe('\n'.join([str(self.management_form), forms]))
|
||||
|
||||
|
||||
def formset_factory(form, formset=BaseFormSet, extra=1, can_order=False,
|
||||
|
||||
@@ -220,7 +220,7 @@ class ModelFormMetaclass(DeclarativeFieldsMetaclass):
|
||||
# of ('foo',)
|
||||
for opt in ['fields', 'exclude', 'localized_fields']:
|
||||
value = getattr(opts, opt)
|
||||
if isinstance(value, six.string_types) and value != ALL_FIELDS:
|
||||
if isinstance(value, str) and value != ALL_FIELDS:
|
||||
msg = ("%(model)s.Meta.%(opt)s cannot be a string. "
|
||||
"Did you mean to type: ('%(value)s',)?" % {
|
||||
'model': new_class.__name__,
|
||||
@@ -727,7 +727,7 @@ class BaseModelFormSet(BaseFormSet):
|
||||
}
|
||||
else:
|
||||
return ugettext("Please correct the duplicate data for %(field)s, which must be unique.") % {
|
||||
"field": get_text_list(unique_check, six.text_type(_("and"))),
|
||||
"field": get_text_list(unique_check, _("and")),
|
||||
}
|
||||
|
||||
def get_date_error_message(self, date_check):
|
||||
@@ -737,7 +737,7 @@ class BaseModelFormSet(BaseFormSet):
|
||||
) % {
|
||||
'field_name': date_check[2],
|
||||
'date_field': date_check[3],
|
||||
'lookup': six.text_type(date_check[1]),
|
||||
'lookup': str(date_check[1]),
|
||||
}
|
||||
|
||||
def get_form_error(self):
|
||||
@@ -1305,7 +1305,7 @@ class ModelMultipleChoiceField(ModelChoiceField):
|
||||
|
||||
def prepare_value(self, value):
|
||||
if (hasattr(value, '__iter__') and
|
||||
not isinstance(value, six.text_type) and
|
||||
not isinstance(value, str) and
|
||||
not hasattr(value, '_meta')):
|
||||
return [super(ModelMultipleChoiceField, self).prepare_value(v) for v in value]
|
||||
return super(ModelMultipleChoiceField, self).prepare_value(value)
|
||||
|
||||
@@ -498,7 +498,7 @@ class CheckboxInput(Input):
|
||||
value = data.get(name)
|
||||
# Translate true and false strings to boolean values.
|
||||
values = {'true': True, 'false': False}
|
||||
if isinstance(value, six.string_types):
|
||||
if isinstance(value, str):
|
||||
value = values.get(value.lower(), value)
|
||||
return bool(value)
|
||||
|
||||
@@ -671,10 +671,7 @@ class Select(ChoiceWidget):
|
||||
def _choice_has_empty_value(choice):
|
||||
"""Return True if the choice's value is empty string or None."""
|
||||
value, _ = choice
|
||||
return (
|
||||
(isinstance(value, six.string_types) and not bool(value)) or
|
||||
value is None
|
||||
)
|
||||
return (isinstance(value, str) and not bool(value)) or value is None
|
||||
|
||||
def use_required_attribute(self, initial):
|
||||
"""
|
||||
@@ -986,7 +983,7 @@ class SelectDateWidget(Widget):
|
||||
year, month, day = None, None, None
|
||||
if isinstance(value, (datetime.date, datetime.datetime)):
|
||||
year, month, day = value.year, value.month, value.day
|
||||
elif isinstance(value, six.string_types):
|
||||
elif isinstance(value, str):
|
||||
if settings.USE_L10N:
|
||||
try:
|
||||
input_format = get_format('DATE_INPUT_FORMATS')[0]
|
||||
|
||||
Reference in New Issue
Block a user