Permalink
Browse files

[py3] Replaced basestring by six.string_types.

  • Loading branch information...
1 parent cacd845 commit 3cb2457f46b3e40ff6b6acffcb3fd44cbea091e5 @aaugustin aaugustin committed Jul 20, 2012
Showing with 230 additions and 150 deletions.
  1. +3 −2 django/conf/__init__.py
  2. +3 −2 django/conf/urls/__init__.py
  3. +2 −1 django/contrib/admin/helpers.py
  4. +1 −1 django/contrib/admin/util.py
  5. +2 −1 django/contrib/formtools/utils.py
  6. +3 −2 django/contrib/gis/admin/widgets.py
  7. +1 −1 django/contrib/gis/db/backends/oracle/operations.py
  8. +1 −1 django/contrib/gis/db/backends/postgis/operations.py
  9. +2 −1 django/contrib/gis/db/backends/spatialite/introspection.py
  10. +1 −1 django/contrib/gis/db/backends/spatialite/operations.py
  11. +3 −1 django/contrib/gis/db/backends/util.py
  12. +2 −1 django/contrib/gis/db/models/fields.py
  13. +2 −1 django/contrib/gis/db/models/proxy.py
  14. +3 −1 django/contrib/gis/db/models/query.py
  15. +6 −4 django/contrib/gis/gdal/datasource.py
  16. +6 −4 django/contrib/gis/gdal/driver.py
  17. +9 −7 django/contrib/gis/gdal/feature.py
  18. +4 −4 django/contrib/gis/gdal/geometries.py
  19. +5 −3 django/contrib/gis/gdal/geomtype.py
  20. +2 −2 django/contrib/gis/gdal/srs.py
  21. +4 −2 django/contrib/gis/geoip/base.py
  22. +3 −1 django/contrib/gis/geoip/tests.py
  23. +3 −1 django/contrib/gis/geos/factory.py
  24. +5 −3 django/contrib/gis/geos/geometry.py
  25. +5 −3 django/contrib/gis/geos/prototypes/io.py
  26. +3 −2 django/contrib/gis/geos/tests/test_geos.py
  27. +5 −4 django/contrib/gis/geos/tests/test_io.py
  28. +6 −5 django/contrib/gis/maps/google/overlays.py
  29. +1 −1 django/contrib/gis/measure.py
  30. +5 −4 django/contrib/gis/utils/layermapping.py
  31. +2 −1 django/contrib/gis/utils/ogrinspect.py
  32. +5 −3 django/contrib/gis/utils/wkt.py
  33. +3 −1 django/core/cache/backends/memcached.py
  34. +2 −1 django/core/mail/backends/filebased.py
  35. +5 −4 django/core/mail/message.py
  36. +4 −3 django/core/management/validation.py
  37. +2 −1 django/core/serializers/base.py
  38. +2 −1 django/core/serializers/json.py
  39. +2 −1 django/core/serializers/pyyaml.py
  40. +4 −3 django/core/urlresolvers.py
  41. +2 −1 django/core/validators.py
  42. +4 −3 django/db/backends/oracle/base.py
  43. +4 −3 django/db/models/fields/__init__.py
  44. +2 −1 django/db/models/fields/files.py
  45. +11 −10 django/db/models/fields/related.py
  46. +3 −2 django/db/models/options.py
  47. +2 −1 django/db/utils.py
  48. +2 −1 django/forms/extras/widgets.py
  49. +3 −2 django/forms/fields.py
  50. +2 −1 django/forms/widgets.py
  51. +2 −1 django/template/base.py
  52. +2 −1 django/template/loader.py
  53. +2 −1 django/template/response.py
  54. +2 −1 django/templatetags/i18n.py
  55. +2 −1 django/templatetags/tz.py
  56. +5 −5 django/test/_doctest.py
  57. +1 −1 django/test/client.py
  58. +10 −9 django/test/html.py
  59. +2 −1 django/test/utils.py
  60. +3 −1 django/utils/archive.py
  61. +3 −1 django/utils/checksums.py
  62. +3 −1 django/utils/dictconfig.py
  63. +2 −2 django/utils/encoding.py
  64. +1 −1 django/utils/formats.py
  65. +3 −1 django/utils/regex_helper.py
  66. +3 −2 django/utils/timezone.py
  67. +2 −1 django/views/debug.py
  68. +4 −3 django/views/i18n.py
  69. +2 −1 tests/modeltests/field_subclassing/fields.py
  70. +2 −1 tests/modeltests/serializers/tests.py
  71. +2 −1 tests/regressiontests/forms/tests/fields.py
  72. +3 −1 tests/regressiontests/i18n/commands/tests.py
  73. +2 −1 tests/regressiontests/staticfiles_tests/tests.py
@@ -15,6 +15,7 @@
from django.core.exceptions import ImproperlyConfigured
from django.utils.functional import LazyObject, empty
from django.utils import importlib
+from django.utils import six
ENVIRONMENT_VARIABLE = "DJANGO_SETTINGS_MODULE"
@@ -73,7 +74,7 @@ def __setattr__(self, name, value):
elif name == "ADMIN_MEDIA_PREFIX":
warnings.warn("The ADMIN_MEDIA_PREFIX setting has been removed; "
"use STATIC_URL instead.", DeprecationWarning)
- elif name == "ALLOWED_INCLUDE_ROOTS" and isinstance(value, basestring):
+ elif name == "ALLOWED_INCLUDE_ROOTS" and isinstance(value, six.string_types):
raise ValueError("The ALLOWED_INCLUDE_ROOTS setting must be set "
"to a tuple, not a string.")
object.__setattr__(self, name, value)
@@ -102,7 +103,7 @@ def __init__(self, settings_module):
if setting == setting.upper():
setting_value = getattr(mod, setting)
if setting in tuple_settings and \
- isinstance(setting_value, basestring):
+ isinstance(setting_value, six.string_types):
warnings.warn("The %s setting must be a tuple. Please fix your "
"settings, as auto-correction is now deprecated." % setting,
PendingDeprecationWarning)
@@ -2,6 +2,7 @@
RegexURLResolver, LocaleRegexURLResolver)
from django.core.exceptions import ImproperlyConfigured
from django.utils.importlib import import_module
+from django.utils import six
__all__ = ['handler403', 'handler404', 'handler500', 'include', 'patterns', 'url']
@@ -20,7 +21,7 @@ def include(arg, namespace=None, app_name=None):
# No namespace hint - use manually provided namespace
urlconf_module = arg
- if isinstance(urlconf_module, basestring):
+ if isinstance(urlconf_module, six.string_types):
urlconf_module = import_module(urlconf_module)
patterns = getattr(urlconf_module, 'urlpatterns', urlconf_module)
@@ -52,7 +53,7 @@ def url(regex, view, kwargs=None, name=None, prefix=''):
urlconf_module, app_name, namespace = view
return RegexURLResolver(regex, urlconf_module, kwargs, app_name=app_name, namespace=namespace)
else:
- if isinstance(view, basestring):
+ if isinstance(view, six.string_types):
if not view:
raise ImproperlyConfigured('Empty URL pattern view name not permitted (for pattern %r)' % regex)
if prefix:
@@ -12,6 +12,7 @@
from django.utils.encoding import force_unicode, smart_unicode
from django.utils.html import conditional_escape, format_html
from django.utils.safestring import mark_safe
+from django.utils import six
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
@@ -49,7 +50,7 @@ def first_field(self):
try:
fieldset_name, fieldset_options = self.fieldsets[0]
field_name = fieldset_options['fields'][0]
- if not isinstance(field_name, basestring):
+ if not isinstance(field_name, six.string_types):
field_name = field_name[0]
return self.form[field_name]
except (KeyError, IndexError):
@@ -52,7 +52,7 @@ def quote(s):
quoting is slightly different so that it doesn't get automatically
unquoted by the Web browser.
"""
- if not isinstance(s, basestring):
+ if not isinstance(s, six.string_types):
return s
res = list(s)
for i in range(len(res)):
@@ -2,6 +2,7 @@
import pickle
from django.utils.crypto import salted_hmac
+from django.utils import six
def form_hmac(form):
@@ -16,7 +17,7 @@ def form_hmac(form):
value = bf.data or ''
else:
value = bf.field.clean(bf.data) or ''
- if isinstance(value, basestring):
+ if isinstance(value, six.string_types):
value = value.strip()
data.append((bf.name, value))
@@ -1,6 +1,7 @@
from django.forms.widgets import Textarea
from django.template import loader, Context
from django.templatetags.static import static
+from django.utils import six
from django.utils import translation
from django.contrib.gis.gdal import OGRException
@@ -25,7 +26,7 @@ def render(self, name, value, attrs=None):
# If a string reaches here (via a validation error on another
# field) then just reconstruct the Geometry.
- if isinstance(value, basestring):
+ if isinstance(value, six.string_types):
try:
value = GEOSGeometry(value)
except (GEOSException, ValueError):
@@ -109,7 +110,7 @@ def _has_changed(self, initial, data):
""" Compare geographic value of data with its initial value. """
# Ensure we are dealing with a geographic object
- if isinstance(initial, basestring):
+ if isinstance(initial, six.string_types):
try:
initial = GEOSGeometry(initial)
except (GEOSException, ValueError):
@@ -121,7 +121,7 @@ class OracleOperations(DatabaseOperations, BaseSpatialOperations):
'exact' : SDOOperation('SDO_EQUAL'),
'overlaps' : SDOOperation('SDO_OVERLAPS'),
'same_as' : SDOOperation('SDO_EQUAL'),
- 'relate' : (SDORelate, basestring), # Oracle uses a different syntax, e.g., 'mask=inside+touch'
+ 'relate' : (SDORelate, six.string_types), # Oracle uses a different syntax, e.g., 'mask=inside+touch'
'touches' : SDOOperation('SDO_TOUCH'),
'within' : SDOOperation('SDO_INSIDE'),
}
@@ -162,7 +162,7 @@ def __init__(self, connection):
'overlaps' : PostGISFunction(prefix, 'Overlaps'),
'contains' : PostGISFunction(prefix, 'Contains'),
'intersects' : PostGISFunction(prefix, 'Intersects'),
- 'relate' : (PostGISRelate, basestring),
+ 'relate' : (PostGISRelate, six.string_types),
}
# Valid distance types and substitutions
@@ -1,5 +1,6 @@
from django.contrib.gis.gdal import OGRGeomType
from django.db.backends.sqlite3.introspection import DatabaseIntrospection, FlexibleFieldLookupDict
+from django.utils import six
class GeoFlexibleFieldLookupDict(FlexibleFieldLookupDict):
"""
@@ -43,7 +44,7 @@ def get_geometry_type(self, table_name, geo_col):
field_params = {}
if srid != 4326:
field_params['srid'] = srid
- if isinstance(dim, basestring) and 'Z' in dim:
+ if isinstance(dim, six.string_types) and 'Z' in dim:
field_params['dim'] = 3
finally:
cursor.close()
@@ -90,7 +90,7 @@ class SpatiaLiteOperations(DatabaseOperations, BaseSpatialOperations):
'overlaps' : SpatiaLiteFunction('Overlaps'),
'contains' : SpatiaLiteFunction('Contains'),
'intersects' : SpatiaLiteFunction('Intersects'),
- 'relate' : (SpatiaLiteRelate, basestring),
+ 'relate' : (SpatiaLiteRelate, six.string_types),
# Returns true if B's bounding box completely contains A's bounding box.
'contained' : SpatiaLiteFunction('MbrWithin'),
# Returns true if A's bounding box completely contains B's bounding box.
@@ -3,13 +3,15 @@
backends.
"""
+from django.utils import six
+
def gqn(val):
"""
The geographic quote name function; used for quoting tables and
geometries (they use single rather than the double quotes of the
backend quotename function).
"""
- if isinstance(val, basestring):
+ if isinstance(val, six.string_types):
if isinstance(val, unicode): val = val.encode('ascii')
return "'%s'" % val
else:
@@ -4,6 +4,7 @@
from django.contrib.gis import forms
from django.contrib.gis.db.models.proxy import GeometryProxy
from django.contrib.gis.geometry.backend import Geometry, GeometryException
+from django.utils import six
# Local cache of the spatial_ref_sys table, which holds SRID data for each
# spatial database alias. This cache exists so that the database isn't queried
@@ -159,7 +160,7 @@ def get_prep_value(self, value):
# from the given string input.
if isinstance(geom, Geometry):
pass
- elif isinstance(geom, basestring) or hasattr(geom, '__geo_interface__'):
+ elif isinstance(geom, six.string_types) or hasattr(geom, '__geo_interface__'):
try:
geom = Geometry(geom)
except GeometryException:
@@ -5,6 +5,7 @@
Thanks to Robert Coup for providing this functionality (see #4322).
"""
+from django.utils import six
class GeometryProxy(object):
def __init__(self, klass, field):
@@ -53,7 +54,7 @@ def __set__(self, obj, value):
if isinstance(value, self._klass) and (str(value.geom_type).upper() == gtype or gtype == 'GEOMETRY'):
# Assigning the SRID to the geometry.
if value.srid is None: value.srid = self._field.srid
- elif value is None or isinstance(value, (basestring, buffer)):
+ elif value is None or isinstance(value, six.string_types + (buffer,)):
# Set with None, WKT, HEX, or WKB
pass
else:
@@ -8,6 +8,8 @@
from django.contrib.gis.measure import Area, Distance
from django.utils import six
+from django.utils import six
+
class GeoQuerySet(QuerySet):
"The Geographic QuerySet."
@@ -534,7 +536,7 @@ def _spatial_attribute(self, att, settings, field_name=None, model_att=None):
geo_field = settings['geo_field']
# The attribute to attach to the model.
- if not isinstance(model_att, basestring): model_att = att
+ if not isinstance(model_att, six.string_types): model_att = att
# Special handling for any argument that is a geometry.
for name in settings['geom_args']:
@@ -45,6 +45,8 @@
# Getting the ctypes prototypes for the DataSource.
from django.contrib.gis.gdal.prototypes import ds as capi
+from django.utils import six
+
# For more information, see the OGR C API source code:
# http://www.gdal.org/ogr/ogr__api_8h.html
#
@@ -65,7 +67,7 @@ def __init__(self, ds_input, ds_driver=False, write=False):
if not capi.get_driver_count():
capi.register_all()
- if isinstance(ds_input, basestring):
+ if isinstance(ds_input, six.string_types):
# The data source driver is a void pointer.
ds_driver = Driver.ptr_type()
try:
@@ -84,7 +86,7 @@ def __init__(self, ds_input, ds_driver=False, write=False):
self.ptr = ds
self.driver = Driver(ds_driver)
else:
- # Raise an exception if the returned pointer is NULL
+ # Raise an exception if the returned pointer is NULL
raise OGRException('Invalid data source file "%s"' % ds_input)
def __del__(self):
@@ -98,7 +100,7 @@ def __iter__(self):
def __getitem__(self, index):
"Allows use of the index [] operator to get a layer at the index."
- if isinstance(index, basestring):
+ if isinstance(index, six.string_types):
l = capi.get_layer_by_name(self.ptr, index)
if not l: raise OGRIndexError('invalid OGR Layer name given: "%s"' % index)
elif isinstance(index, int):
@@ -108,7 +110,7 @@ def __getitem__(self, index):
else:
raise TypeError('Invalid index type: %s' % type(index))
return Layer(l, self)
-
+
def __len__(self):
"Returns the number of layers within the data source."
return self.layer_count
@@ -1,9 +1,11 @@
-# prerequisites imports
+# prerequisites imports
from ctypes import c_void_p
from django.contrib.gis.gdal.base import GDALBase
from django.contrib.gis.gdal.error import OGRException
from django.contrib.gis.gdal.prototypes import ds as capi
+from django.utils import six
+
# For more information, see the OGR C API source code:
# http://www.gdal.org/ogr/ogr__api_8h.html
#
@@ -18,11 +20,11 @@ class Driver(GDALBase):
'tiger' : 'TIGER',
'tiger/line' : 'TIGER',
}
-
+
def __init__(self, dr_input):
"Initializes an OGR driver on either a string or integer input."
- if isinstance(dr_input, basestring):
+ if isinstance(dr_input, six.string_types):
# If a string name of the driver was passed in
self._register()
@@ -57,7 +59,7 @@ def _register(self):
# Only register all if the driver count is 0 (or else all drivers
# will be registered over and over again)
if not self.driver_count: capi.register_all()
-
+
# Driver properties
@property
def driver_count(self):
@@ -7,6 +7,8 @@
# ctypes function prototypes
from django.contrib.gis.gdal.prototypes import ds as capi, geom as geom_api
+from django.utils import six
+
# For more information, see the OGR C API source code:
# http://www.gdal.org/ogr/ogr__api_8h.html
#
@@ -30,17 +32,17 @@ def __getitem__(self, index):
"""
Gets the Field object at the specified index, which may be either
an integer or the Field's string label. Note that the Field object
- is not the field's _value_ -- use the `get` method instead to
+ is not the field's _value_ -- use the `get` method instead to
retrieve the value (e.g. an integer) instead of a Field instance.
"""
- if isinstance(index, basestring):
+ if isinstance(index, six.string_types):
i = self.index(index)
else:
if index < 0 or index > self.num_fields:
raise OGRIndexError('index out of range')
i = index
return Field(self.ptr, i)
-
+
def __iter__(self):
"Iterates over each field in the Feature."
for i in xrange(self.num_fields):
@@ -49,7 +51,7 @@ def __iter__(self):
def __len__(self):
"Returns the count of fields in this feature."
return self.num_fields
-
+
def __str__(self):
"The string name of the feature."
return 'Feature FID %d in Layer<%s>' % (self.fid, self.layer_name)
@@ -63,7 +65,7 @@ def __eq__(self, other):
def fid(self):
"Returns the feature identifier."
return capi.get_fid(self.ptr)
-
+
@property
def layer_name(self):
"Returns the name of the layer for the feature."
@@ -77,7 +79,7 @@ def num_fields(self):
@property
def fields(self):
"Returns a list of fields in the Feature."
- return [capi.get_field_name(capi.get_field_defn(self._fdefn, i))
+ return [capi.get_field_name(capi.get_field_defn(self._fdefn, i))
for i in xrange(self.num_fields)]
@property
@@ -91,7 +93,7 @@ def geom(self):
def geom_type(self):
"Returns the OGR Geometry Type for this Feture."
return OGRGeomType(capi.get_fd_geom_type(self._fdefn))
-
+
#### Feature Methods ####
def get(self, field):
"""
Oops, something went wrong.

0 comments on commit 3cb2457

Please sign in to comment.