diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-01-06 01:14:26 -0500 |
|---|---|---|
| committer | mike bayer <mike_mp@zzzcomputing.com> | 2019-01-06 17:34:50 +0000 |
| commit | 1e1a38e7801f410f244e4bbb44ec795ae152e04e (patch) | |
| tree | 28e725c5c8188bd0cfd133d1e268dbca9b524978 /lib/sqlalchemy/connectors | |
| parent | 404e69426b05a82d905cbb3ad33adafccddb00dd (diff) | |
| download | sqlalchemy-1e1a38e7801f410f244e4bbb44ec795ae152e04e.tar.gz | |
Run black -l 79 against all source files
This is a straight reformat run using black as is, with no edits
applied at all.
The black run will format code consistently, however in
some cases that are prevalent in SQLAlchemy code it produces
too-long lines. The too-long lines will be resolved in the
following commit that will resolve all remaining flake8 issues
including shadowed builtins, long lines, import order, unused
imports, duplicate imports, and docstring issues.
Change-Id: I7eda77fed3d8e73df84b3651fd6cfcfe858d4dc9
Diffstat (limited to 'lib/sqlalchemy/connectors')
| -rw-r--r-- | lib/sqlalchemy/connectors/mxodbc.py | 39 | ||||
| -rw-r--r-- | lib/sqlalchemy/connectors/pyodbc.py | 77 | ||||
| -rw-r--r-- | lib/sqlalchemy/connectors/zxJDBC.py | 31 |
3 files changed, 79 insertions, 68 deletions
diff --git a/lib/sqlalchemy/connectors/mxodbc.py b/lib/sqlalchemy/connectors/mxodbc.py index 65be4c7d5..209877e4a 100644 --- a/lib/sqlalchemy/connectors/mxodbc.py +++ b/lib/sqlalchemy/connectors/mxodbc.py @@ -27,7 +27,7 @@ from . import Connector class MxODBCConnector(Connector): - driver = 'mxodbc' + driver = "mxodbc" supports_sane_multi_rowcount = False supports_unicode_statements = True @@ -41,12 +41,12 @@ class MxODBCConnector(Connector): # attribute of the same name, so this is normally only called once. cls._load_mx_exceptions() platform = sys.platform - if platform == 'win32': + if platform == "win32": from mx.ODBC import Windows as Module # this can be the string "linux2", and possibly others - elif 'linux' in platform: + elif "linux" in platform: from mx.ODBC import unixODBC as Module - elif platform == 'darwin': + elif platform == "darwin": from mx.ODBC import iODBC as Module else: raise ImportError("Unrecognized platform for mxODBC import") @@ -68,6 +68,7 @@ class MxODBCConnector(Connector): conn.datetimeformat = self.dbapi.PYDATETIME_DATETIMEFORMAT conn.decimalformat = self.dbapi.DECIMAL_DECIMALFORMAT conn.errorhandler = self._error_handler() + return connect def _error_handler(self): @@ -79,11 +80,12 @@ class MxODBCConnector(Connector): def error_handler(connection, cursor, errorclass, errorvalue): if issubclass(errorclass, MxOdbcWarning): errorclass.__bases__ = (Warning,) - warnings.warn(message=str(errorvalue), - category=errorclass, - stacklevel=2) + warnings.warn( + message=str(errorvalue), category=errorclass, stacklevel=2 + ) else: raise errorclass(errorvalue) + return error_handler def create_connect_args(self, url): @@ -101,11 +103,11 @@ class MxODBCConnector(Connector): not be populated. """ - opts = url.translate_connect_args(username='user') + opts = url.translate_connect_args(username="user") opts.update(url.query) - args = opts.pop('host') - opts.pop('port', None) - opts.pop('database', None) + args = opts.pop("host") + opts.pop("port", None) + opts.pop("database", None) return (args,), opts def is_disconnect(self, e, connection, cursor): @@ -114,7 +116,7 @@ class MxODBCConnector(Connector): if isinstance(e, self.dbapi.ProgrammingError): return "connection already closed" in str(e) elif isinstance(e, self.dbapi.Error): - return '[08S01]' in str(e) + return "[08S01]" in str(e) else: return False @@ -123,7 +125,7 @@ class MxODBCConnector(Connector): # of what we're doing here dbapi_con = connection.connection version = [] - r = re.compile(r'[.\-]') + r = re.compile(r"[.\-]") # 18 == pyodbc.SQL_DBMS_VER for n in r.split(dbapi_con.getinfo(18)[1]): try: @@ -134,8 +136,9 @@ class MxODBCConnector(Connector): def _get_direct(self, context): if context: - native_odbc_execute = context.execution_options.\ - get('native_odbc_execute', 'auto') + native_odbc_execute = context.execution_options.get( + "native_odbc_execute", "auto" + ) # default to direct=True in all cases, is more generally # compatible especially with SQL Server return False if native_odbc_execute is True else True @@ -144,8 +147,8 @@ class MxODBCConnector(Connector): def do_executemany(self, cursor, statement, parameters, context=None): cursor.executemany( - statement, parameters, direct=self._get_direct(context)) + statement, parameters, direct=self._get_direct(context) + ) def do_execute(self, cursor, statement, parameters, context=None): - cursor.execute(statement, parameters, - direct=self._get_direct(context)) + cursor.execute(statement, parameters, direct=self._get_direct(context)) diff --git a/lib/sqlalchemy/connectors/pyodbc.py b/lib/sqlalchemy/connectors/pyodbc.py index 41ba89de6..8f5eea89b 100644 --- a/lib/sqlalchemy/connectors/pyodbc.py +++ b/lib/sqlalchemy/connectors/pyodbc.py @@ -13,7 +13,7 @@ import re class PyODBCConnector(Connector): - driver = 'pyodbc' + driver = "pyodbc" supports_sane_rowcount_returning = False supports_sane_multi_rowcount = False @@ -22,7 +22,7 @@ class PyODBCConnector(Connector): supports_unicode_binds = True supports_native_decimal = True - default_paramstyle = 'named' + default_paramstyle = "named" # for non-DSN connections, this *may* be used to # hold the desired driver name @@ -35,10 +35,10 @@ class PyODBCConnector(Connector): @classmethod def dbapi(cls): - return __import__('pyodbc') + return __import__("pyodbc") def create_connect_args(self, url): - opts = url.translate_connect_args(username='user') + opts = url.translate_connect_args(username="user") opts.update(url.query) keys = opts @@ -46,52 +46,55 @@ class PyODBCConnector(Connector): query = url.query connect_args = {} - for param in ('ansi', 'unicode_results', 'autocommit'): + for param in ("ansi", "unicode_results", "autocommit"): if param in keys: connect_args[param] = util.asbool(keys.pop(param)) - if 'odbc_connect' in keys: - connectors = [util.unquote_plus(keys.pop('odbc_connect'))] + if "odbc_connect" in keys: + connectors = [util.unquote_plus(keys.pop("odbc_connect"))] else: + def check_quote(token): if ";" in str(token): token = "'%s'" % token return token - keys = dict( - (k, check_quote(v)) for k, v in keys.items() - ) + keys = dict((k, check_quote(v)) for k, v in keys.items()) - dsn_connection = 'dsn' in keys or \ - ('host' in keys and 'database' not in keys) + dsn_connection = "dsn" in keys or ( + "host" in keys and "database" not in keys + ) if dsn_connection: - connectors = ['dsn=%s' % (keys.pop('host', '') or - keys.pop('dsn', ''))] + connectors = [ + "dsn=%s" % (keys.pop("host", "") or keys.pop("dsn", "")) + ] else: - port = '' - if 'port' in keys and 'port' not in query: - port = ',%d' % int(keys.pop('port')) + port = "" + if "port" in keys and "port" not in query: + port = ",%d" % int(keys.pop("port")) connectors = [] - driver = keys.pop('driver', self.pyodbc_driver_name) + driver = keys.pop("driver", self.pyodbc_driver_name) if driver is None: util.warn( "No driver name specified; " "this is expected by PyODBC when using " - "DSN-less connections") + "DSN-less connections" + ) else: connectors.append("DRIVER={%s}" % driver) connectors.extend( [ - 'Server=%s%s' % (keys.pop('host', ''), port), - 'Database=%s' % keys.pop('database', '') - ]) + "Server=%s%s" % (keys.pop("host", ""), port), + "Database=%s" % keys.pop("database", ""), + ] + ) user = keys.pop("user", None) if user: connectors.append("UID=%s" % user) - connectors.append("PWD=%s" % keys.pop('password', '')) + connectors.append("PWD=%s" % keys.pop("password", "")) else: connectors.append("Trusted_Connection=Yes") @@ -99,18 +102,20 @@ class PyODBCConnector(Connector): # convert textual data from your database encoding to your # client encoding. This should obviously be set to 'No' if # you query a cp1253 encoded database from a latin1 client... - if 'odbc_autotranslate' in keys: - connectors.append("AutoTranslate=%s" % - keys.pop("odbc_autotranslate")) + if "odbc_autotranslate" in keys: + connectors.append( + "AutoTranslate=%s" % keys.pop("odbc_autotranslate") + ) - connectors.extend(['%s=%s' % (k, v) for k, v in keys.items()]) + connectors.extend(["%s=%s" % (k, v) for k, v in keys.items()]) return [[";".join(connectors)], connect_args] def is_disconnect(self, e, connection, cursor): if isinstance(e, self.dbapi.ProgrammingError): - return "The cursor's connection has been closed." in str(e) or \ - 'Attempt to use a closed connection.' in str(e) + return "The cursor's connection has been closed." in str( + e + ) or "Attempt to use a closed connection." in str(e) else: return False @@ -123,10 +128,7 @@ class PyODBCConnector(Connector): return self._parse_dbapi_version(self.dbapi.version) def _parse_dbapi_version(self, vers): - m = re.match( - r'(?:py.*-)?([\d\.]+)(?:-(\w+))?', - vers - ) + m = re.match(r"(?:py.*-)?([\d\.]+)(?:-(\w+))?", vers) if not m: return () vers = tuple([int(x) for x in m.group(1).split(".")]) @@ -140,7 +142,7 @@ class PyODBCConnector(Connector): # queries. dbapi_con = connection.connection version = [] - r = re.compile(r'[.\-]') + r = re.compile(r"[.\-]") for n in r.split(dbapi_con.getinfo(self.dbapi.SQL_DBMS_VER)): try: version.append(int(n)) @@ -153,12 +155,11 @@ class PyODBCConnector(Connector): # adjust for ConnectionFairy being present # allows attribute set e.g. "connection.autocommit = True" # to work properly - if hasattr(connection, 'connection'): + if hasattr(connection, "connection"): connection = connection.connection - if level == 'AUTOCOMMIT': + if level == "AUTOCOMMIT": connection.autocommit = True else: connection.autocommit = False - super(PyODBCConnector, self).set_isolation_level(connection, - level) + super(PyODBCConnector, self).set_isolation_level(connection, level) diff --git a/lib/sqlalchemy/connectors/zxJDBC.py b/lib/sqlalchemy/connectors/zxJDBC.py index 71decd9ab..003ecbed1 100644 --- a/lib/sqlalchemy/connectors/zxJDBC.py +++ b/lib/sqlalchemy/connectors/zxJDBC.py @@ -10,15 +10,15 @@ from . import Connector class ZxJDBCConnector(Connector): - driver = 'zxjdbc' + driver = "zxjdbc" supports_sane_rowcount = False supports_sane_multi_rowcount = False supports_unicode_binds = True - supports_unicode_statements = sys.version > '2.5.0+' + supports_unicode_statements = sys.version > "2.5.0+" description_encoding = None - default_paramstyle = 'qmark' + default_paramstyle = "qmark" jdbc_db_name = None jdbc_driver_name = None @@ -26,6 +26,7 @@ class ZxJDBCConnector(Connector): @classmethod def dbapi(cls): from com.ziclix.python.sql import zxJDBC + return zxJDBC def _driver_kwargs(self): @@ -34,25 +35,31 @@ class ZxJDBCConnector(Connector): def _create_jdbc_url(self, url): """Create a JDBC url from a :class:`~sqlalchemy.engine.url.URL`""" - return 'jdbc:%s://%s%s/%s' % (self.jdbc_db_name, url.host, - url.port is not None - and ':%s' % url.port or '', - url.database) + return "jdbc:%s://%s%s/%s" % ( + self.jdbc_db_name, + url.host, + url.port is not None and ":%s" % url.port or "", + url.database, + ) def create_connect_args(self, url): opts = self._driver_kwargs() opts.update(url.query) return [ - [self._create_jdbc_url(url), - url.username, url.password, - self.jdbc_driver_name], - opts] + [ + self._create_jdbc_url(url), + url.username, + url.password, + self.jdbc_driver_name, + ], + opts, + ] def is_disconnect(self, e, connection, cursor): if not isinstance(e, self.dbapi.ProgrammingError): return False e = str(e) - return 'connection is closed' in e or 'cursor is closed' in e + return "connection is closed" in e or "cursor is closed" in e def _get_server_version_info(self, connection): # use connection.connection.dbversion, and parse appropriately |
