Commits

Michael Manfre committed e8bfd2f

Starting toward Python 2/3 support

Comments (0)

Files changed (16)

sqlserver_ado/__init__.py

-from __future__ import absolute_import
+from __future__ import absolute_import, unicode_literals
 # following PEP 386
 __version__ = "1.5a"
 

sqlserver_ado/ado_consts.py

+from __future__ import unicode_literals
+
 # ADO enumerated constants documented on MSDN:
 # http://msdn.microsoft.com/en-us/library/ms678353(VS.85).aspx
 

sqlserver_ado/base.py

 """Microsoft SQL Server database backend for Django."""
-from __future__ import absolute_import
+from __future__ import absolute_import, unicode_literals
 
 from django.core.exceptions import ImproperlyConfigured, ValidationError
 from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseValidation, BaseDatabaseClient
 
     # If no user is specified, use integrated security.
     if settings.USER != '':
-        auth_string = u'UID={0};PWD={1}'.format(settings.USER, settings.PASSWORD)
+        auth_string = 'UID={0};PWD={1}'.format(settings.USER, settings.PASSWORD)
     else:
         auth_string = 'Integrated Security=SSPI'
 
     parts = [
-        u'DATA SOURCE={0};Initial Catalog={1}'.format(db_host, db_name),
+        'DATA SOURCE={0};Initial Catalog={1}'.format(db_host, db_name),
         auth_string
     ]
 

sqlserver_ado/compiler.py

-from __future__ import absolute_import
+from __future__ import absolute_import, unicode_literals
 
 try:
     from itertools import zip_longest

sqlserver_ado/creation.py

-from __future__ import absolute_import
+from __future__ import absolute_import, unicode_literals
 
 from django.conf import settings
 from django.db.backends.creation import BaseDatabaseCreation, TEST_DATABASE_PREFIX

sqlserver_ado/dbapi.py

 
 DB-API 2.0 specification: http://www.python.org/dev/peps/pep-0249/
 """
+from __future__ import unicode_literals
 
 import sys
 import time
         p.Type = adBSTR
         if timezone.is_aware(value):
             value = timezone.make_naive(value, timezone.utc)
-        s = value.isoformat(' ')
+        s = value.isoformat(b' ')
         p.Value = s
         p.Size = len(s)
 
             for i, p in enumerate(tuple(self.cmd.Parameters)[1:]):
                 _configure_parameter(p, parameters[i])
         except:
-            _message = u'Converting Parameter %s: %s, %s\n' %\
+            _message = 'Converting Parameter %s: %s, %s\n' %\
                 (p.Name, ado_type_name(p.Type), repr(parameters[i]))
 
             self._raiseCursorError(DataError, _message)
             try:
                 p = self.cmd.CreateParameter('p%i' % i, _ado_type(value))
             except KeyError:
-                _message = u'Failed to map python type "%s" to an ADO type' % (value.__class__.__name__,)
+                _message = 'Failed to map python type "%s" to an ADO type' % (value.__class__.__name__,)
                 self._raiseCursorError(DataError, _message)
             except:
-                _message = u'Creating Parameter p%i, %s' % (i, _ado_type(value))
+                _message = 'Creating Parameter p%i, %s' % (i, _ado_type(value))
                 self._raiseCursorError(DataError, _message)
 
             try:
                 _configure_parameter(p, value)
                 self.cmd.Parameters.Append(p)
             except Exception as e:
-                _message = u'Converting Parameter %s: %s, %s\n' %\
+                _message = 'Converting Parameter %s: %s, %s\n' %\
                     (p.Name, ado_type_name(p.Type), repr(value))
 
                 self._raiseCursorError(DataError, _message)

sqlserver_ado/fields.py

 """This module provides SQL Server specific fields for Django models."""
+from __future__ import unicode_literals
 import datetime
 from django.db import models
 from django.forms import ValidationError
-from django.utils import timezone
+from django.utils import six, timezone
 from django.utils.translation import ugettext_lazy as _
 
 
 BigIntegerField = models.BigIntegerField
 
 def convert_microsoft_date_to_isoformat(value):
-    if isinstance(value, basestring):
+    if isinstance(value, six.string_types):
         value = value.replace(' +', '+').replace(' -', '-')
     return value
 
             value = self.get_prep_value(value)
         if value is None:
             return None
-        return value.isoformat(' ')
+        return value.isoformat(b' ')
 
 class TimeField(models.TimeField):
     """

sqlserver_ado/introspection.py

-from __future__ import absolute_import
+from __future__ import absolute_import, unicode_literals
 
 from django.db.backends import BaseDatabaseIntrospection
 from . import ado_consts

sqlserver_ado/models/__init__.py

+from __future__ import unicode_literals
 from sqlserver_ado.models.manager import RawStoredProcedureManager
 from sqlserver_ado.models.query import RawStoredProcedureQuerySet

sqlserver_ado/models/manager.py

+from __future__ import unicode_literals
 from django.db.models import Manager
 from sqlserver_ado.models.query import RawStoredProcedureQuerySet
 

sqlserver_ado/models/query.py

+from __future__ import unicode_literals
 from django.db import connections, router
 from django.db.models import sql
 from django.db.models.query import RawQuerySet

sqlserver_ado/operations.py

-from __future__ import absolute_import
+from __future__ import absolute_import, unicode_literals
 
 import datetime
 import django
 except:
     from django.utils.encoding import smart_unicode as smart_text
 
-from django.utils import timezone
+from django.utils import six, timezone
 
 from . import fields as mssql_fields
 
             seconds = ((timedelta.days * 86400) + timedelta.seconds) * sign
             out = sql
             if seconds:
-                out = u'DATEADD(SECOND, {0}, {1})'.format(seconds, sql)
+                out = 'DATEADD(SECOND, {0}, {1})'.format(seconds, sql)
             if timedelta.microseconds:
                 # DATEADD with datetime doesn't support ms, must cast up
-                out = u'DATEADD(MICROSECOND, {ms}, CAST({sql} as datetime2))'.format(
+                out = 'DATEADD(MICROSECOND, {ms}, CAST({sql} as datetime2))'.format(
                     ms=timedelta.microseconds * sign,
                     sql=out,
                 )
         else:
             # Only days in the delta, assume underlying datatype can DATEADD with days
-            out = u'DATEADD(DAY, {0}, {1})'.format(timedelta.days * sign, sql)
+            out = 'DATEADD(DAY, {0}, {1})'.format(timedelta.days * sign, sql)
         return out
 
     def date_trunc_sql(self, lookup_type, field_name):
         return "ON %s" % self.quote_name(tablespace)
 
     def _legacy_value_to_db_datetime(self, value):
-        if value is None or isinstance(value, basestring):
+        if value is None or isinstance(value, six.string_types):
             return value
 
         if timezone.is_aware(value):# and not self.connection.features.supports_timezones:
         # SQL Server 2005 doesn't support microseconds
         if self.connection.is_sql2005():
            value = value.replace(microsecond=0)
-        val = value.isoformat(' ')
+        val = value.isoformat(b' ')
         if value.microsecond:
             # truncate microsecond to millisecond
             idx = val.rindex('.')
         return val
         
     def _new_value_to_db_datetime(self, value):
-        if value is None or isinstance(value, basestring):
+        if value is None or isinstance(value, six.string_types):
             return value
             
         if timezone.is_aware(value):# and not self.connection.features.supports_timezones:
                 value = value.astimezone(timezone.utc).replace(tzinfo=None)
             else:
                 raise ValueError("SQL Server backend does not support timezone-aware datetimes.")
-        return value.isoformat(' ')
+        return value.isoformat(b' ')
     
     def _legacy_value_to_db_time(self, value):
-        if value is None or isinstance(value, basestring):
+        if value is None or isinstance(value, six.string_types):
             return value
 
         if timezone.is_aware(value):
         return val
 
     def _new_value_to_db_time(self, value):
-        if value is None or isinstance(value, basestring):
+        if value is None or isinstance(value, six.string_types):
             return value
 
         if timezone.is_aware(value):

sqlserver_ado/patches.py

+from __future__ import unicode_literals
 import sys
 
 if sys.version_info >= (2,7):

sqlserver_ado/south_adapter.py

+from __future__ import unicode_literals
+
 from django.db import connection
 from django.db.models.fields import *
 from south.db import generic

sqlserver_ado/sql_app/management/commands/dbgui.py

+from __future__ import unicode_literals
 from django.core.management.base import NoArgsCommand
 
 class Command(NoArgsCommand):

sqlserver_ado/sql_app/management/commands/install_regex_clr.py

+from __future__ import unicode_literals
 from django.core.management.base import BaseCommand
 from django.db import connection
 
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.