Commits

Aymeric Augustin committed 9c40d81

Port code using basestring to Python 2 + 3.

Comments (0)

Files changed (8)

south/creator/changes.py

                     unique_together = eval(old_meta.get("unique_together", "[]"))
                     if unique_together:
                         # If it's only a single tuple, make it into the longer one
-                        if isinstance(unique_together[0], basestring):
+                        if isinstance(unique_together[0], string_types):
                             unique_together = [unique_together]
                         # For each combination, make an action for it
                         for fields in unique_together:
                     unique_together = eval(new_meta.get("unique_together", "[]"))
                     if unique_together:
                         # If it's only a single tuple, make it into the longer one
-                        if isinstance(unique_together[0], basestring):
+                        if isinstance(unique_together[0], string_types):
                             unique_together = [unique_together]
                         # For each combination, make an action for it
                         for fields in unique_together:
                 # First, normalise them into lists of sets.
                 old_unique_together = eval(old_meta.get("unique_together", "[]"))
                 new_unique_together = eval(new_meta.get("unique_together", "[]"))
-                if old_unique_together and isinstance(old_unique_together[0], basestring):
+                if old_unique_together and isinstance(old_unique_together[0], string_types):
                     old_unique_together = [old_unique_together]
-                if new_unique_together and isinstance(new_unique_together[0], basestring):
+                if new_unique_together and isinstance(new_unique_together[0], string_types):
                     new_unique_together = [new_unique_together]
                 old_unique_together = map(set, old_unique_together)
                 new_unique_together = map(set, new_unique_together)
                 unique_together = eval(meta.get("unique_together", "[]"))
                 if unique_together:
                     # If it's only a single tuple, make it into the longer one
-                    if isinstance(unique_together[0], basestring):
+                    if isinstance(unique_together[0], string_types):
                         unique_together = [unique_together]
                     # For each combination, make an action for it
                     for fields in unique_together:

south/creator/freezer.py

 from south.orm import FakeORM
 from south.utils import get_attribute, auto_through
 from south import modelsinspector
+from south.utils.py3 import string_types
 
 def freeze_apps(apps):
     """
     Takes a list of app labels, and returns a string of their frozen form.
     """
-    if isinstance(apps, basestring):
+    if isinstance(apps, string_types):
         apps = [apps]
     frozen_models = set()
     # For each app, add in all its models

south/db/firebird.py

 from django.db.utils import DatabaseError
 
 from south.db import generic
+from south.utils.py3 import string_types
 
 class DatabaseOperations(generic.DatabaseOperations):
     backend_name = 'firebird'
                         if callable(default):
                             default = default()
                         # Now do some very cheap quoting. TODO: Redesign return values to avoid this.
-                        if isinstance(default, basestring):
+                        if isinstance(default, string_types):
                             default = "'%s'" % default.replace("'", "''")
                         elif isinstance(default, (datetime.date, datetime.time, datetime.datetime)):
                             default = "'%s'" % default
                         elif isinstance(default, bool):
                             default = int(default)
                         # Escape any % signs in the output (bug #317)
-                        if isinstance(default, basestring):
+                        if isinstance(default, string_types):
                             default = default.replace("%", "%%")
                         # Add it in
                         sql += " DEFAULT %s"

south/db/generic.py

                         default = field.get_db_prep_save(default, connection=self._get_connection())
                         default = self._default_value_workaround(default)
                         # Now do some very cheap quoting. TODO: Redesign return values to avoid this.
-                        if isinstance(default, basestring):
+                        if isinstance(default, string_types):
                             default = "'%s'" % default.replace("'", "''")
                         # Escape any % signs in the output (bug #317)
-                        if isinstance(default, basestring):
+                        if isinstance(default, string_types):
                             default = default.replace("%", "%%")
                         # Add it in
                         sql += " DEFAULT %s"

south/db/sql_server/pyodbc.py

 from south.db import generic
 from south.db.generic import delete_column_constraints, invalidate_table_constraints, copy_column_constraints
 from south.exceptions import ConstraintDropped
+from south.utils.py3 import string_types
 try:
     from django.utils.encoding import smart_text                    # Django >= 1.5
 except ImportError:
         conn = self._get_connection()
         value = field.get_db_prep_save(value, connection=conn)
         # This is still a Python object -- nobody expects to need a literal.
-        if isinstance(value, basestring):
+        if isinstance(value, string_types):
             return smart_text(value)
         elif isinstance(value, (date,time,datetime)):
             return value.isoformat()

south/hacks/django_1_0.py

 from django.core.management.commands.flush import Command as FlushCommand
 from django.utils.datastructures import SortedDict
 
+from south.utils.py3 import string_types
+
 class SkipFlushCommand(FlushCommand):
     def handle_noargs(self, **options):
         # no-op to avoid calling flush
         
         # Make sure it contains strings
         if apps:
-            assert isinstance(apps[0], basestring), "The argument to set_installed_apps must be a list of strings."
+            assert isinstance(apps[0], string_types), "The argument to set_installed_apps must be a list of strings."
         
         # Monkeypatch in!
         settings.INSTALLED_APPS, settings.OLD_INSTALLED_APPS = (

south/migration/base.py

 from south.orm import FakeORM
 from south.utils import memoize, ask_for_it_by_name, datetime_utils
 from south.migration.utils import app_label_to_app_module
-
+from south.utils.py3 import string_types
 
 def all_migrations(applications=None):
     """
 
 def application_to_app_label(application):
     "Works out the app label from either the app label, the app name, or the module"
-    if isinstance(application, basestring):
+    if isinstance(application, string_types):
         app_label = application.split('.')[-1]
     else:
         app_label = application.__name__.split('.')[-1]
         return self._cache[name]
 
     def __getitem__(self, value):
-        if isinstance(value, basestring):
+        if isinstance(value, string_types):
             return self.migration(value)
         return super(Migrations, self).__getitem__(value)
 
                 key = key.lower()
                 if key not in self.models:
                     raise ORMBaseNotIncluded("Cannot find ORM base %s" % key)
-                elif isinstance(self.models[key], basestring):
+                elif isinstance(self.models[key], string_types):
                     # Then the other model hasn't been unfrozen yet.
                     # We postpone ourselves; the situation will eventually resolve.
                     raise UnfreezeMeLater()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.