diff options
| author | Tom Christie | 2014-10-01 13:09:14 +0100 |
|---|---|---|
| committer | Tom Christie | 2014-10-01 13:09:14 +0100 |
| commit | 381771731f48c75e7d5951e353049cceec386512 (patch) | |
| tree | bc426b11d4ba33cbbb2063e3393f8855c7841fd8 /rest_framework/fields.py | |
| parent | bb2222963f527638ed2bc9a817415102312e12e0 (diff) | |
| download | django-rest-framework-381771731f48c75e7d5951e353049cceec386512.tar.bz2 | |
Use six.text_type instead of str everywhere
Diffstat (limited to 'rest_framework/fields.py')
| -rw-r--r-- | rest_framework/fields.py | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/rest_framework/fields.py b/rest_framework/fields.py index f7ea3b0c..f3ff2233 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -2,7 +2,7 @@ from django import forms from django.conf import settings from django.core import validators from django.core.exceptions import ValidationError -from django.utils import timezone +from django.utils import six, timezone from django.utils.datastructures import SortedDict from django.utils.dateparse import parse_date, parse_datetime, parse_time from django.utils.encoding import is_protected_type @@ -431,10 +431,10 @@ class CharField(Field): return super(CharField, self).run_validation(data) def to_internal_value(self, data): - return str(data) + return six.text_type(data) def to_representation(self, value): - return str(value) + return six.text_type(value) class EmailField(CharField): @@ -448,10 +448,10 @@ class EmailField(CharField): self.validators.append(validator) def to_internal_value(self, data): - return str(data).strip() + return six.text_type(data).strip() def to_representation(self, value): - return str(value).strip() + return six.text_type(value).strip() class RegexField(CharField): @@ -510,7 +510,7 @@ class IntegerField(Field): def to_internal_value(self, data): try: - data = int(str(data)) + data = int(six.text_type(data)) except (ValueError, TypeError): self.fail('invalid') return data @@ -616,7 +616,7 @@ class DecimalField(Field): def to_representation(self, value): if not isinstance(value, decimal.Decimal): - value = decimal.Decimal(str(value).strip()) + value = decimal.Decimal(six.text_type(value).strip()) context = decimal.getcontext().copy() context.prec = self.max_digits @@ -832,19 +832,19 @@ class ChoiceField(Field): # Allows us to deal with eg. integer choices while supporting either # integer or string input, but still get the correct datatype out. self.choice_strings_to_values = dict([ - (str(key), key) for key in self.choices.keys() + (six.text_type(key), key) for key in self.choices.keys() ]) super(ChoiceField, self).__init__(**kwargs) def to_internal_value(self, data): try: - return self.choice_strings_to_values[str(data)] + return self.choice_strings_to_values[six.text_type(data)] except KeyError: self.fail('invalid_choice', input=data) def to_representation(self, value): - return self.choice_strings_to_values[str(value)] + return self.choice_strings_to_values[six.text_type(value)] class MultipleChoiceField(ChoiceField): @@ -864,7 +864,7 @@ class MultipleChoiceField(ChoiceField): def to_representation(self, value): return set([ - self.choice_strings_to_values[str(item)] for item in value + self.choice_strings_to_values[six.text_type(item)] for item in value ]) |
