1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

[py3] Replaced basestring by six.string_types.

This commit is contained in:
Aymeric Augustin
2012-07-20 14:22:00 +02:00
parent cacd845996
commit 3cb2457f46
73 changed files with 230 additions and 150 deletions

View File

@@ -5,10 +5,12 @@ from threading import local
from django.core.cache.backends.base import BaseCache, InvalidCacheBackendError
from django.utils import six
class BaseMemcachedCache(BaseCache):
def __init__(self, server, params, library, value_not_found_exception):
super(BaseMemcachedCache, self).__init__(params)
if isinstance(server, basestring):
if isinstance(server, six.string_types):
self._servers = server.split(';')
else:
self._servers = server

View File

@@ -6,6 +6,7 @@ import os
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.core.mail.backends.console import EmailBackend as ConsoleEmailBackend
from django.utils import six
class EmailBackend(ConsoleEmailBackend):
def __init__(self, *args, **kwargs):
@@ -15,7 +16,7 @@ class EmailBackend(ConsoleEmailBackend):
else:
self.file_path = getattr(settings, 'EMAIL_FILE_PATH',None)
# Make sure self.file_path is a string.
if not isinstance(self.file_path, basestring):
if not isinstance(self.file_path, six.string_types):
raise ImproperlyConfigured('Path for saving emails is invalid: %r' % self.file_path)
self.file_path = os.path.abspath(self.file_path)
# Make sure that self.file_path is an directory if it exists.

View File

@@ -16,6 +16,7 @@ from io import BytesIO
from django.conf import settings
from django.core.mail.utils import DNS_NAME
from django.utils.encoding import smart_str, force_unicode
from django.utils import six
# Don't BASE64-encode UTF-8 messages so that we avoid unwanted attention from
@@ -96,7 +97,7 @@ def forbid_multi_line_headers(name, val, encoding):
def sanitize_address(addr, encoding):
if isinstance(addr, basestring):
if isinstance(addr, six.string_types):
addr = parseaddr(force_unicode(addr))
nm, addr = addr
nm = str(Header(nm, encoding))
@@ -180,17 +181,17 @@ class EmailMessage(object):
necessary encoding conversions.
"""
if to:
assert not isinstance(to, basestring), '"to" argument must be a list or tuple'
assert not isinstance(to, six.string_types), '"to" argument must be a list or tuple'
self.to = list(to)
else:
self.to = []
if cc:
assert not isinstance(cc, basestring), '"cc" argument must be a list or tuple'
assert not isinstance(cc, six.string_types), '"cc" argument must be a list or tuple'
self.cc = list(cc)
else:
self.cc = []
if bcc:
assert not isinstance(bcc, basestring), '"bcc" argument must be a list or tuple'
assert not isinstance(bcc, six.string_types), '"bcc" argument must be a list or tuple'
self.bcc = list(bcc)
else:
self.bcc = []

View File

@@ -3,6 +3,7 @@ import sys
from django.core.management.color import color_style
from django.utils.encoding import smart_str
from django.utils.itercompat import is_iterable
from django.utils import six
class ModelErrorCollection:
def __init__(self, outfile=sys.stdout):
@@ -93,7 +94,7 @@ def get_validation_errors(outfile, app=None):
if isinstance(f, models.FilePathField) and not (f.allow_files or f.allow_folders):
e.add(opts, '"%s": FilePathFields must have either allow_files or allow_folders set to True.' % f.name)
if f.choices:
if isinstance(f.choices, basestring) or not is_iterable(f.choices):
if isinstance(f.choices, six.string_types) or not is_iterable(f.choices):
e.add(opts, '"%s": "choices" should be iterable (e.g., a tuple or list).' % f.name)
else:
for c in f.choices:
@@ -168,7 +169,7 @@ def get_validation_errors(outfile, app=None):
if f.unique:
e.add(opts, "ManyToManyFields cannot be unique. Remove the unique argument on '%s'." % f.name)
if f.rel.through is not None and not isinstance(f.rel.through, basestring):
if f.rel.through is not None and not isinstance(f.rel.through, six.string_types):
from_model, to_model = cls, f.rel.to
if from_model == to_model and f.rel.symmetrical and not f.rel.through._meta.auto_created:
e.add(opts, "Many-to-many fields with intermediate tables cannot be symmetrical.")
@@ -239,7 +240,7 @@ def get_validation_errors(outfile, app=None):
"to %s and %s" % (f.name, f.rel.through._meta.object_name,
f.rel.to._meta.object_name, cls._meta.object_name)
)
elif isinstance(f.rel.through, basestring):
elif isinstance(f.rel.through, six.string_types):
e.add(opts, "'%s' specifies an m2m relation through model %s, "
"which has not been installed" % (f.name, f.rel.through)
)

View File

@@ -6,6 +6,7 @@ from io import BytesIO
from django.db import models
from django.utils.encoding import smart_unicode
from django.utils import six
class SerializerDoesNotExist(KeyError):
"""The requested serializer was not found."""
@@ -123,7 +124,7 @@ class Deserializer(object):
Init this serializer given a stream or a string
"""
self.options = options
if isinstance(stream_or_string, basestring):
if isinstance(stream_or_string, six.string_types):
self.stream = BytesIO(stream_or_string)
else:
self.stream = stream_or_string

View File

@@ -13,6 +13,7 @@ from django.core.serializers.base import DeserializationError
from django.core.serializers.python import Serializer as PythonSerializer
from django.core.serializers.python import Deserializer as PythonDeserializer
from django.utils.encoding import smart_str
from django.utils import six
from django.utils.timezone import is_aware
class Serializer(PythonSerializer):
@@ -63,7 +64,7 @@ def Deserializer(stream_or_string, **options):
if isinstance(stream_or_string, bytes):
stream_or_string = stream_or_string.decode('utf-8')
try:
if isinstance(stream_or_string, basestring):
if isinstance(stream_or_string, six.string_types):
objects = json.loads(stream_or_string)
else:
objects = json.load(stream_or_string)

View File

@@ -13,6 +13,7 @@ from django.core.serializers.base import DeserializationError
from django.core.serializers.python import Serializer as PythonSerializer
from django.core.serializers.python import Deserializer as PythonDeserializer
from django.utils.encoding import smart_str
from django.utils import six
class DjangoSafeDumper(yaml.SafeDumper):
@@ -53,7 +54,7 @@ def Deserializer(stream_or_string, **options):
"""
if isinstance(stream_or_string, bytes):
stream_or_string = stream_or_string.decode('utf-8')
if isinstance(stream_or_string, basestring):
if isinstance(stream_or_string, six.string_types):
stream = StringIO(stream_or_string)
else:
stream = stream_or_string

View File

@@ -19,6 +19,7 @@ from django.utils.functional import memoize, lazy
from django.utils.importlib import import_module
from django.utils.module_loading import module_has_submodule
from django.utils.regex_helper import normalize
from django.utils import six
from django.utils.translation import get_language
@@ -159,7 +160,7 @@ class LocaleRegexProvider(object):
"""
language_code = get_language()
if language_code not in self._regex_dict:
if isinstance(self._regex, basestring):
if isinstance(self._regex, six.string_types):
regex = self._regex
else:
regex = force_unicode(self._regex)
@@ -228,7 +229,7 @@ class RegexURLResolver(LocaleRegexProvider):
LocaleRegexProvider.__init__(self, regex)
# urlconf_name is a string representing the module containing URLconfs.
self.urlconf_name = urlconf_name
if not isinstance(urlconf_name, basestring):
if not isinstance(urlconf_name, six.string_types):
self._urlconf_module = self.urlconf_name
self.callback = None
self.default_kwargs = default_kwargs or {}
@@ -434,7 +435,7 @@ def reverse(viewname, urlconf=None, args=None, kwargs=None, prefix=None, current
if prefix is None:
prefix = get_script_prefix()
if not isinstance(viewname, basestring):
if not isinstance(viewname, six.string_types):
view = viewname
else:
parts = viewname.split(':')

View File

@@ -7,6 +7,7 @@ from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import smart_unicode
from django.utils.ipv6 import is_valid_ipv6_address
from django.utils import six
# These values, if given to validate(), will trigger the self.required check.
EMPTY_VALUES = (None, '', [], (), {})
@@ -25,7 +26,7 @@ class RegexValidator(object):
self.code = code
# Compile the regex if it was not passed pre-compiled.
if isinstance(self.regex, basestring):
if isinstance(self.regex, six.string_types):
self.regex = re.compile(self.regex)
def __call__(self, value):