Permalink
Browse files

[py3] Replaced unicode/str by six.text_type/bytes.

  • Loading branch information...
1 parent 3cb2457 commit bdca5ea345c548a82a80d198906818c9ccbef896 @aaugustin aaugustin committed Jul 20, 2012
Showing with 376 additions and 294 deletions.
  1. +1 −1 django/contrib/admin/helpers.py
  2. +2 −2 django/contrib/admin/util.py
  3. +2 −1 django/contrib/admin/widgets.py
  4. +5 −4 django/contrib/auth/models.py
  5. +3 −2 django/contrib/auth/tokens.py
  6. +2 −1 django/contrib/contenttypes/tests.py
  7. +3 −2 django/contrib/formtools/wizard/views.py
  8. +4 −3 django/contrib/gis/db/backends/base.py
  9. +1 −1 django/contrib/gis/db/backends/util.py
  10. +1 −1 django/contrib/gis/gdal/geometries.py
  11. +1 −1 django/contrib/gis/gdal/srs.py
  12. +1 −1 django/contrib/gis/geos/geometry.py
  13. +1 −1 django/contrib/gis/geos/tests/test_io.py
  14. +2 −1 django/contrib/gis/tests/geoapp/tests.py
  15. +1 −1 django/contrib/gis/utils/layermapping.py
  16. +3 −2 django/contrib/localflavor/mx/forms.py
  17. +3 −2 django/contrib/localflavor/se/utils.py
  18. +2 −1 django/core/management/commands/inspectdb.py
  19. +2 −2 django/core/management/validation.py
  20. +1 −1 django/core/urlresolvers.py
  21. +4 −3 django/db/backends/__init__.py
  22. +4 −4 django/db/backends/mysql/base.py
  23. +1 −1 django/db/backends/oracle/base.py
  24. +2 −2 django/db/backends/sqlite3/base.py
  25. +7 −7 django/db/models/base.py
  26. +1 −1 django/db/models/fields/files.py
  27. +2 −2 django/forms/fields.py
  28. +2 −2 django/forms/forms.py
  29. +4 −3 django/forms/formsets.py
  30. +2 −2 django/forms/models.py
  31. +8 −8 django/http/__init__.py
  32. +2 −1 django/http/multipartparser.py
  33. +1 −1 django/template/base.py
  34. +5 −4 django/template/defaultfilters.py
  35. +1 −1 django/test/_doctest.py
  36. +3 −3 django/test/html.py
  37. +3 −2 django/test/testcases.py
  38. +3 −2 django/utils/dateformat.py
  39. +25 −12 django/utils/encoding.py
  40. +2 −2 django/utils/formats.py
  41. +6 −5 django/utils/functional.py
  42. +9 −8 django/utils/html.py
  43. +5 −4 django/utils/http.py
  44. +3 −2 django/utils/numberformat.py
  45. +17 −16 django/utils/safestring.py
  46. +13 −12 django/utils/text.py
  47. +8 −7 django/utils/translation/__init__.py
  48. +1 −1 django/views/debug.py
  49. +5 −4 tests/modeltests/custom_columns/tests.py
  50. +2 −1 tests/modeltests/custom_managers/tests.py
  51. +3 −2 tests/modeltests/custom_pk/fields.py
  52. +8 −7 tests/modeltests/custom_pk/tests.py
  53. +2 −1 tests/modeltests/expressions/tests.py
  54. +2 −2 tests/modeltests/field_subclassing/fields.py
  55. +2 −1 tests/modeltests/lookup/models.py
  56. +2 −1 tests/modeltests/m2m_and_m2o/models.py
  57. +3 −2 tests/modeltests/m2m_intermediary/tests.py
  58. +2 −1 tests/modeltests/many_to_one/tests.py
  59. +2 −1 tests/modeltests/model_forms/models.py
  60. +17 −16 tests/modeltests/model_forms/tests.py
  61. +2 −1 tests/modeltests/model_formsets/models.py
  62. +11 −10 tests/modeltests/model_formsets/tests.py
  63. +3 −2 tests/modeltests/model_inheritance/tests.py
  64. +2 −1 tests/modeltests/order_with_respect_to/models.py
  65. +4 −3 tests/modeltests/pagination/tests.py
  66. +20 −19 tests/modeltests/prefetch_related/tests.py
  67. +2 −1 tests/modeltests/save_delete_hooks/tests.py
  68. +2 −1 tests/modeltests/serializers/models.py
  69. +1 −1 tests/modeltests/serializers/tests.py
  70. +2 −1 tests/modeltests/signals/tests.py
  71. +3 −2 tests/modeltests/update/models.py
  72. +5 −4 tests/regressiontests/admin_changelist/tests.py
  73. +2 −1 tests/regressiontests/admin_util/models.py
  74. +4 −3 tests/regressiontests/admin_util/tests.py
  75. +4 −3 tests/regressiontests/admin_views/tests.py
  76. +3 −2 tests/regressiontests/backends/tests.py
  77. +2 −1 tests/regressiontests/datatypes/tests.py
  78. +4 −3 tests/regressiontests/defaultfilters/tests.py
  79. +2 −1 tests/regressiontests/file_uploads/views.py
  80. +2 −1 tests/regressiontests/fixtures_regress/models.py
  81. +2 −1 tests/regressiontests/forms/tests/models.py
  82. +2 −1 tests/regressiontests/forms/tests/util.py
  83. +4 −3 tests/regressiontests/forms/tests/widgets.py
  84. +4 −3 tests/regressiontests/i18n/contenttypes/tests.py
  85. +5 −4 tests/regressiontests/i18n/tests.py
  86. +3 −2 tests/regressiontests/inline_formsets/tests.py
  87. +5 −4 tests/regressiontests/model_forms_regress/tests.py
  88. +6 −5 tests/regressiontests/model_formsets_regress/tests.py
  89. +3 −2 tests/regressiontests/model_regress/tests.py
  90. +2 −1 tests/regressiontests/queries/models.py
  91. +3 −2 tests/regressiontests/select_related_regress/tests.py
  92. +12 −11 tests/regressiontests/templates/templatetags/custom.py
  93. +2 −1 tests/regressiontests/templates/unicode.py
  94. +4 −3 tests/regressiontests/utils/simplelazyobject.py
  95. +2 −1 tests/regressiontests/wsgi/tests.py
  96. +2 −1 tests/runtests.py
@@ -189,7 +189,7 @@ def contents(self):
if value is None:
result_repr = EMPTY_CHANGELIST_VALUE
elif isinstance(f.rel, ManyToManyRel):
- result_repr = ", ".join(map(unicode, value.all()))
+ result_repr = ", ".join(map(six.text_type, value.all()))
else:
result_repr = display_for_field(value, f)
return conditional_escape(result_repr)
@@ -275,10 +275,10 @@ def label_for_field(name, model, model_admin=None, return_attr=False):
except models.FieldDoesNotExist:
if name == "__unicode__":
label = force_unicode(model._meta.verbose_name)
- attr = unicode
+ attr = six.text_type
elif name == "__str__":
label = smart_str(model._meta.verbose_name)
- attr = str
+ attr = bytes
else:
if callable(name):
attr = name
@@ -15,6 +15,7 @@
from django.utils.translation import ugettext as _
from django.utils.safestring import mark_safe
from django.utils.encoding import force_unicode
+from django.utils import six
class FilteredSelectMultiple(forms.SelectMultiple):
@@ -121,7 +122,7 @@ def url_params_from_lookup_dict(lookups):
# See django.db.fields.BooleanField.get_prep_lookup
v = ('0', '1')[v]
else:
- v = unicode(v)
+ v = six.text_type(v)
items.append((k, v))
params.update(dict(items))
return params
@@ -8,6 +8,7 @@
from django.db.models.manager import EmptyManager
from django.utils.crypto import get_random_string
from django.utils.encoding import smart_str
+from django.utils import six
from django.utils.translation import ugettext_lazy as _
from django.utils import timezone
@@ -79,9 +80,9 @@ class Meta:
def __unicode__(self):
return "%s | %s | %s" % (
- unicode(self.content_type.app_label),
- unicode(self.content_type),
- unicode(self.name))
+ six.text_type(self.content_type.app_label),
+ six.text_type(self.content_type),
+ six.text_type(self.name))
def natural_key(self):
return (self.codename,) + self.content_type.natural_key()
@@ -421,7 +422,7 @@ def __unicode__(self):
return 'AnonymousUser'
def __str__(self):
- return unicode(self).encode('utf-8')
+ return six.text_type(self).encode('utf-8')
def __eq__(self, other):
return isinstance(other, self.__class__)
@@ -2,6 +2,7 @@
from django.conf import settings
from django.utils.http import int_to_base36, base36_to_int
from django.utils.crypto import constant_time_compare, salted_hmac
+from django.utils import six
class PasswordResetTokenGenerator(object):
"""
@@ -56,8 +57,8 @@ def _make_token_with_timestamp(self, user, timestamp):
# Ensure results are consistent across DB backends
login_timestamp = user.last_login.replace(microsecond=0, tzinfo=None)
- value = (unicode(user.id) + user.password +
- unicode(login_timestamp) + unicode(timestamp))
+ value = (six.text_type(user.id) + user.password +
+ six.text_type(login_timestamp) + six.text_type(timestamp))
hash = salted_hmac(key_salt, value).hexdigest()[::2]
return "%s-%s" % (ts_b36, hash)
@@ -9,6 +9,7 @@
from django.http import HttpRequest, Http404
from django.test import TestCase
from django.utils.encoding import smart_str
+from django.utils import six
class ConcreteModel(models.Model):
@@ -271,4 +272,4 @@ def test_missing_model(self):
app_label = 'contenttypes',
model = 'OldModel',
)
- self.assertEqual(unicode(ct), 'Old model')
+ self.assertEqual(six.text_type(ct), 'Old model')
@@ -7,6 +7,7 @@
from django.views.generic import TemplateView
from django.utils.datastructures import SortedDict
from django.utils.decorators import classonlymethod
+from django.utils import six
from django.contrib.formtools.wizard.storage import get_storage
from django.contrib.formtools.wizard.storage.exceptions import NoFileStorageConfigured
@@ -157,10 +158,10 @@ def get_initkwargs(cls, form_list, initial_dict=None,
if isinstance(form, (list, tuple)):
# if the element is a tuple, add the tuple to the new created
# sorted dictionary.
- init_form_list[unicode(form[0])] = form[1]
+ init_form_list[six.text_type(form[0])] = form[1]
else:
# if not, add the form with a zero based counter as unicode
- init_form_list[unicode(i)] = form
+ init_form_list[six.text_type(i)] = form
# walk through the new created list of forms
for form in init_form_list.itervalues():
@@ -4,6 +4,7 @@
"""
import re
from django.contrib.gis import gdal
+from django.utils import six
class BaseSpatialOperations(object):
"""
@@ -88,7 +89,7 @@ def convert_geom(self, geom_val, geom_field):
# For quoting column values, rather than columns.
def geo_quote_name(self, name):
- if isinstance(name, unicode):
+ if isinstance(name, six.text_type):
name = name.encode('ascii')
return "'%s'" % name
@@ -330,6 +331,6 @@ def __unicode__(self):
it will be 'pretty' OGC WKT.
"""
try:
- return unicode(self.srs)
+ return six.text_type(self.srs)
except:
- return unicode(self.wkt)
+ return six.text_type(self.wkt)
@@ -12,7 +12,7 @@ def gqn(val):
backend quotename function).
"""
if isinstance(val, six.string_types):
- if isinstance(val, unicode): val = val.encode('ascii')
+ if isinstance(val, six.text_type): val = val.encode('ascii')
return "'%s'" % val
else:
return str(val)
@@ -81,7 +81,7 @@ def __init__(self, geom_input, srs=None):
# Constructing the geometry,
if str_instance:
# Checking if unicode
- if isinstance(geom_input, unicode):
+ if isinstance(geom_input, six.text_type):
# Encoding to ASCII, WKT or HEX doesn't need any more.
geom_input = geom_input.encode('ascii')
@@ -56,7 +56,7 @@ def __init__(self, srs_input=''):
if isinstance(srs_input, six.string_types):
# Encoding to ASCII if unicode passed in.
- if isinstance(srs_input, unicode):
+ if isinstance(srs_input, six.text_type):
srs_input = srs_input.encode('ascii')
try:
# If SRID is a string, e.g., '4326', then make acceptable
@@ -55,7 +55,7 @@ def __init__(self, geo_input, srid=None):
(SRID) number for this Geometry. If not set, the SRID will be None.
"""
if isinstance(geo_input, six.string_types):
- if isinstance(geo_input, unicode):
+ if isinstance(geo_input, six.text_type):
# Encoding to ASCII, WKT or HEXEWKB doesn't need any more.
geo_input = geo_input.encode('ascii')
@@ -13,7 +13,7 @@ def test01_wktreader(self):
# read() should return a GEOSGeometry
ref = GEOSGeometry(wkt)
g1 = wkt_r.read(wkt)
- g2 = wkt_r.read(unicode(wkt))
+ g2 = wkt_r.read(six.text_type(wkt))
for geom in (g1, g2):
self.assertEqual(ref, geom)
@@ -11,6 +11,7 @@
no_mysql, no_oracle, no_spatialite,
mysql, oracle, postgis, spatialite)
from django.test import TestCase
+from django.utils import six
from .models import Country, City, PennsylvaniaCity, State, Track
@@ -663,7 +664,7 @@ def test27_snap_to_grid(self):
# Let's try and break snap_to_grid() with bad combinations of arguments.
for bad_args in ((), range(3), range(5)):
self.assertRaises(ValueError, Country.objects.snap_to_grid, *bad_args)
- for bad_args in (('1.0',), (1.0, None), tuple(map(unicode, range(4)))):
+ for bad_args in (('1.0',), (1.0, None), tuple(map(six.text_type, range(4)))):
self.assertRaises(TypeError, Country.objects.snap_to_grid, *bad_args)
# Boundary for San Marino, courtesy of Bjorn Sandvik of thematicmapping.org
@@ -330,7 +330,7 @@ def verify_ogr_field(self, ogr_field, model_field):
if self.encoding:
# The encoding for OGR data sources may be specified here
# (e.g., 'cp437' for Census Bureau boundary files).
- val = unicode(ogr_field.value, self.encoding)
+ val = six.text_type(ogr_field.value, self.encoding)
else:
val = ogr_field.value
if model_field.max_length and len(val) > model_field.max_length:
@@ -7,6 +7,7 @@
from django.forms import ValidationError
from django.forms.fields import Select, RegexField
+from django.utils import six
from django.utils.translation import ugettext_lazy as _
from django.core.validators import EMPTY_VALUES
from django.contrib.localflavor.mx.mx_states import STATE_CHOICES
@@ -155,7 +156,7 @@ def _checksum(self, rfc):
elif checksum == 11:
return '0'
- return unicode(checksum)
+ return six.text_type(checksum)
def _has_inconvenient_word(self, rfc):
first_four = rfc[:4]
@@ -219,7 +220,7 @@ def _checksum(self, value):
if checksum == 10:
return '0'
- return unicode(checksum)
+ return six.text_type(checksum)
def _has_inconvenient_word(self, curp):
first_four = curp[:4]
@@ -1,4 +1,5 @@
import datetime
+from django.utils import six
def id_number_checksum(gd):
"""
@@ -65,15 +66,15 @@ def validate_id_birthday(gd, fix_coordination_number_day=True):
def format_personal_id_number(birth_day, gd):
# birth_day.strftime cannot be used, since it does not support dates < 1900
- return unicode(str(birth_day.year) + gd['month'] + gd['day'] + gd['serial'] + gd['checksum'])
+ return six.text_type(str(birth_day.year) + gd['month'] + gd['day'] + gd['serial'] + gd['checksum'])
def format_organisation_number(gd):
if gd['century'] is None:
century = ''
else:
century = gd['century']
- return unicode(century + gd['year'] + gd['month'] + gd['day'] + gd['serial'] + gd['checksum'])
+ return six.text_type(century + gd['year'] + gd['month'] + gd['day'] + gd['serial'] + gd['checksum'])
def valid_organisation(gd):
return gd['century'] in (None, 16) and \
@@ -3,6 +3,7 @@
from django.core.management.base import NoArgsCommand, CommandError
from django.db import connections, DEFAULT_DB_ALIAS
+from django.utils import six
class Command(NoArgsCommand):
help = "Introspects the database tables in the given database and outputs a Django model module."
@@ -115,7 +116,7 @@ def handle_inspection(self, options):
if att_name[0].isdigit():
att_name = 'number_%s' % att_name
- extra_params['db_column'] = unicode(column_name)
+ extra_params['db_column'] = six.text_type(column_name)
comment_notes.append("Field renamed because it wasn't a "
"valid Python identifier.")
@@ -120,7 +120,7 @@ def get_validation_errors(outfile, app=None):
e.add(opts, "'%s' has a relation with model %s, which has either not been installed or is abstract." % (f.name, f.rel.to))
# it is a string and we could not find the model it refers to
# so skip the next section
- if isinstance(f.rel.to, (str, unicode)):
+ if isinstance(f.rel.to, six.string_types):
continue
# Make sure the related field specified by a ForeignKey is unique
@@ -162,7 +162,7 @@ def get_validation_errors(outfile, app=None):
e.add(opts, "'%s' has an m2m relation with model %s, which has either not been installed or is abstract." % (f.name, f.rel.to))
# it is a string and we could not find the model it refers to
# so skip the next section
- if isinstance(f.rel.to, (str, unicode)):
+ if isinstance(f.rel.to, six.string_types):
continue
# Check that the field is not set to unique. ManyToManyFields do not support unique.
@@ -169,7 +169,7 @@ def regex(self):
except re.error as e:
raise ImproperlyConfigured(
'"%s" is not a valid regular expression: %s' %
- (regex, unicode(e)))
+ (regex, six.text_type(e)))
self._regex_dict[language_code] = compiled_regex
return self._regex_dict[language_code]
@@ -12,6 +12,7 @@
from django.db.transaction import TransactionManagementError
from django.utils.functional import cached_property
from django.utils.importlib import import_module
+from django.utils import six
from django.utils.timezone import is_aware
@@ -808,7 +809,7 @@ def value_to_db_date(self, value):
"""
if value is None:
return None
- return unicode(value)
+ return six.text_type(value)
def value_to_db_datetime(self, value):
"""
@@ -817,7 +818,7 @@ def value_to_db_datetime(self, value):
"""
if value is None:
return None
- return unicode(value)
+ return six.text_type(value)
def value_to_db_time(self, value):
"""
@@ -828,7 +829,7 @@ def value_to_db_time(self, value):
return None
if is_aware(value):
raise ValueError("Django does not support timezone-aware times.")
- return unicode(value)
+ return six.text_type(value)
def value_to_db_decimal(self, value, max_digits, decimal_places):
"""
@@ -297,7 +297,7 @@ def value_to_db_datetime(self, value):
raise ValueError("MySQL backend does not support timezone-aware datetimes when USE_TZ is False.")
# MySQL doesn't support microseconds
- return unicode(value.replace(microsecond=0))
+ return six.text_type(value.replace(microsecond=0))
def value_to_db_time(self, value):
if value is None:
@@ -308,7 +308,7 @@ def value_to_db_time(self, value):
raise ValueError("MySQL backend does not support timezone-aware times.")
# MySQL doesn't support microseconds
- return unicode(value.replace(microsecond=0))
+ return six.text_type(value.replace(microsecond=0))
def year_lookup_bounds(self, value):
# Again, no microseconds
@@ -399,8 +399,8 @@ def _cursor(self):
kwargs['client_flag'] = CLIENT.FOUND_ROWS
kwargs.update(settings_dict['OPTIONS'])
self.connection = Database.connect(**kwargs)
- self.connection.encoders[SafeUnicode] = self.connection.encoders[unicode]
- self.connection.encoders[SafeString] = self.connection.encoders[str]
+ self.connection.encoders[SafeUnicode] = self.connection.encoders[six.text_type]
+ self.connection.encoders[SafeString] = self.connection.encoders[bytes]
connection_created.send(sender=self.__class__, connection=self)
cursor = self.connection.cursor()
if new_connection:
@@ -356,7 +356,7 @@ def value_to_db_datetime(self, value):
else:
raise ValueError("Oracle backend does not support timezone-aware datetimes when USE_TZ is False.")
- return unicode(value)
+ return six.text_type(value)
def value_to_db_time(self, value):
if value is None:
Oops, something went wrong.

0 comments on commit bdca5ea

Please sign in to comment.