# 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):
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)
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)
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))
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)
@classmethod
def import_dbapi(cls):
- from . import adodbapi as module
+ import adodbapi as module
return module
colspecs = util.update_copy(
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()
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()])
# 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)" \
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
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, \
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
return iter.__next__()
else:
next = next
-if py3k_warning:
+if py3k:
import pickle
else:
try:
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 !