]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
work through dialects
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 28 Apr 2013 00:02:24 +0000 (20:02 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 28 Apr 2013 00:02:24 +0000 (20:02 -0400)
lib/sqlalchemy/connectors/pyodbc.py
lib/sqlalchemy/dialects/informix/base.py
lib/sqlalchemy/dialects/mssql/adodbapi.py
lib/sqlalchemy/dialects/mssql/base.py
lib/sqlalchemy/util/__init__.py
lib/sqlalchemy/util/compat.py

index 504414b0f64cb7d444e4335ea4b953daae3180f8..784344b824e56109ee2f8993268ef7e74c858866 100644 (file)
@@ -5,11 +5,11 @@
 # the MIT License: http://www.opensource.org/licenses/mit-license.php
 
 from . import Connector
-from ..util import asbool
+from .. import util
+
 
 import sys
 import re
-import urllib.request, urllib.parse, urllib.error
 
 
 class PyODBCConnector(Connector):
@@ -56,10 +56,10 @@ class PyODBCConnector(Connector):
         connect_args = {}
         for param in ('ansi', 'unicode_results', 'autocommit'):
             if param in keys:
-                connect_args[param] = asbool(keys.pop(param))
+                connect_args[param] = util.asbool(keys.pop(param))
 
         if 'odbc_connect' in keys:
-            connectors = [urllib.parse.unquote_plus(keys.pop('odbc_connect'))]
+            connectors = [util.unquote_plus(keys.pop('odbc_connect'))]
         else:
             dsn_connection = 'dsn' in keys or \
                             ('host' in keys and 'database' not in keys)
@@ -121,18 +121,15 @@ class PyODBCConnector(Connector):
             self.freetds_driver_version = dbapi_con.getinfo(
                 pyodbc.SQL_DRIVER_VER)
 
-        # the "Py2K only" part here is theoretical.
-        # have not tried pyodbc + python3.1 yet.
-# start Py2K
-#        self.supports_unicode_statements = (
-#            not self.freetds and not self.easysoft)
-#        if self._user_supports_unicode_binds is not None:
-#            self.supports_unicode_binds = self._user_supports_unicode_binds
-#        else:
-#            self.supports_unicode_binds = (
-#                not self.freetds or self.freetds_driver_version >= '0.91'
-#            ) and not self.easysoft
-# end Py2K
+        if not util.py3k:
+            self.supports_unicode_statements = (
+                not self.freetds and not self.easysoft)
+            if self._user_supports_unicode_binds is not None:
+                self.supports_unicode_binds = self._user_supports_unicode_binds
+            else:
+                self.supports_unicode_binds = (
+                    not self.freetds or self.freetds_driver_version >= '0.91'
+                ) and not self.easysoft
 
         # run other initialization which asks for user name, etc.
         super(PyODBCConnector, self).initialize(connection)
index 691400e058217568ff04248022a6f8eff2577e41..a5a6917af4054cb28abe664a4c53796c3b69bf1b 100644 (file)
@@ -299,7 +299,7 @@ class InfoDDLCompiler(compiler.DDLCompiler):
 
     def get_column_default_string(self, column):
         if (isinstance(column.server_default, schema.DefaultClause) and
-            isinstance(column.server_default.arg, str)):
+            isinstance(column.server_default.arg, util.string_type)):
                 if isinstance(column.type, (sqltypes.Integer, sqltypes.Numeric)):
                     return self.sql_compiler.process(text(column.server_default.arg))
 
@@ -323,10 +323,10 @@ class InfoDDLCompiler(compiler.DDLCompiler):
         remote_table = list(constraint._elements.values())[0].column.table
         text = "FOREIGN KEY (%s) REFERENCES %s (%s)" % (
             ', '.join(preparer.quote(f.parent.name, f.parent.quote)
-                      for f in list(constraint._elements.values())),
+                      for f in constraint._elements.values()),
             preparer.format_table(remote_table),
             ', '.join(preparer.quote(f.column.name, f.column.quote)
-                      for f in list(constraint._elements.values()))
+                      for f in constraint._elements.values())
         )
         text += self.define_constraint_cascades(constraint)
         text += self.define_constraint_deferrability(constraint)
index 080382d556302635a26389009498a1748a0fa389..167b4e807e06487a6984f061df3634dba60293d3 100644 (file)
@@ -44,7 +44,7 @@ class MSDialect_adodbapi(MSDialect):
 
     @classmethod
     def import_dbapi(cls):
-        from . import adodbapi as module
+        import adodbapi as module
         return module
 
     colspecs = util.update_copy(
index 827cf01867d0d25811387a5076345a7e64ecdbf4..c5b86b887af3fcfc009f3e030b559d5252fa9d27 100644 (file)
@@ -295,7 +295,7 @@ class _MSDate(sqltypes.Date):
         def process(value):
             if isinstance(value, datetime.datetime):
                 return value.date()
-            elif isinstance(value, str):
+            elif isinstance(value, util.string_type):
                 return datetime.date(*[
                         int(x or 0)
                         for x in self._reg.match(value).groups()
@@ -328,7 +328,7 @@ class TIME(sqltypes.TIME):
         def process(value):
             if isinstance(value, datetime.datetime):
                 return value.time()
-            elif isinstance(value, str):
+            elif isinstance(value, util.string_type):
                 return datetime.time(*[
                         int(x or 0)
                         for x in self._reg.match(value).groups()])
@@ -1002,7 +1002,7 @@ class MSDDLCompiler(compiler.DDLCompiler):
         # handle other included columns
         if index.kwargs.get("mssql_include"):
             inclusions = [index.table.c[col]
-                            if isinstance(col, str) else col
+                            if isinstance(col, util.string_type) else col
                           for col in index.kwargs["mssql_include"]]
 
             text += " INCLUDE (%s)" \
@@ -1150,7 +1150,7 @@ class MSDialect(default.DefaultDialect):
             try:
                 default_schema_name = connection.scalar(query, name=user_name)
                 if default_schema_name is not None:
-                    return str(default_schema_name)
+                    return util.text_type(default_schema_name)
             except:
                 pass
         return self.schema_name
index 3fa06c79325b96c11b4f4c4481eb4e7b303856e6..2fcfabefd5818fdfa6cf775b2c0c04b7f41c0def 100644 (file)
@@ -7,7 +7,7 @@
 from .compat import callable, cmp, reduce,  \
     threading, py3k, py3k_warning, jython, pypy, cpython, win32, set_types, \
     pickle, dottedgetter, parse_qsl, namedtuple, next, WeakSet, reraise, \
-    raise_from_cause
+    raise_from_cause, text_type, string_type, binary_type, quote_plus
 
 from ._collections import KeyedTuple, ImmutableContainer, immutabledict, \
     Properties, OrderedProperties, ImmutableProperties, OrderedDict, \
index 4eb915469523ed8d5686400d89dc2767ccd31416..d00e3ab232f7af9fc3acdd567ea01600b795b610 100644 (file)
@@ -21,11 +21,8 @@ pypy = hasattr(sys, 'pypy_version_info')
 win32 = sys.platform.startswith('win')
 cpython = not pypy and not jython  # TODO: something better for this ?
 
-if py3k_warning:
+if py3k:
     set_types = set
-elif sys.version_info < (2, 6):
-    import sets
-    set_types = set, sets.Set
 else:
     # 2.6 deprecates sets.Set, but we still need to be able to detect them
     # in user code and as return values from DB-APIs
@@ -46,7 +43,7 @@ if sys.version_info < (2, 6):
         return iter.__next__()
 else:
     next = next
-if py3k_warning:
+if py3k:
     import pickle
 else:
     try:
@@ -54,19 +51,21 @@ else:
     except ImportError:
         import pickle
 
-if sys.version_info < (2, 6):
-    # emits a nasty deprecation warning
-    # in newer pythons
-    from cgi import parse_qsl
+from urllib.parse import parse_qsl
+
+
+if py3k:
+    from inspect import getfullargspec as inspect_getfullargspec
+    from urllib.parse import quote_plus, unquote_plus
+    string_types = str,
+    binary_type = bytes
+    text_type = str
 else:
-    from urllib.parse import parse_qsl
-
-# start Py3K
-from inspect import getfullargspec as inspect_getfullargspec
-# end Py3K
-# start Py2K
-#from inspect import getargspec as inspect_getfullargspec
-# end Py2K
+    from inspect import getargspec as inspect_getfullargspec
+    from urllib import quote_plus, unquote_plus
+    string_types = basestring,
+    binary_type = str
+    text_type = unicode
 
 if py3k_warning:
     # they're bringing it back in 3.2.  brilliant !