diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2020-04-10 17:52:47 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@bbpush.zzzcomputing.com> | 2020-04-10 17:52:47 +0000 |
commit | 1ff644d2f16a7517df7f175e1291ddaa501646dd (patch) | |
tree | a8f6e624e1500f3b77e43a22eaeb0e7b8ff20100 /lib/sqlalchemy/dialects | |
parent | fe591913030a244a9ccfdd47b371609f1f1b44af (diff) | |
parent | a9b068ae564e5e775e312373088545b75aeaa1b0 (diff) | |
download | sqlalchemy-1ff644d2f16a7517df7f175e1291ddaa501646dd.tar.gz |
Merge "Remove code deprecated before version 1.1"
Diffstat (limited to 'lib/sqlalchemy/dialects')
-rw-r--r-- | lib/sqlalchemy/dialects/__init__.py | 10 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/mssql/base.py | 6 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/mysql/__init__.py | 1 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/mysql/base.py | 8 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/mysql/enumerated.py | 111 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/mysql/gaerdbms.py | 102 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/mysql/reflection.py | 17 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/oracle/cx_oracle.py | 4 |
8 files changed, 47 insertions, 212 deletions
diff --git a/lib/sqlalchemy/dialects/__init__.py b/lib/sqlalchemy/dialects/__init__.py index 4407ab62d..9b46a4d0c 100644 --- a/lib/sqlalchemy/dialects/__init__.py +++ b/lib/sqlalchemy/dialects/__init__.py @@ -18,9 +18,6 @@ __all__ = ( from .. import util -_translates = {"postgres": "postgresql"} - - def _auto_fn(name): """default dialect importer. @@ -34,13 +31,6 @@ def _auto_fn(name): dialect = name driver = "base" - if dialect in _translates: - translated = _translates[dialect] - util.warn_deprecated( - "The '%s' dialect name has been " - "renamed to '%s'" % (dialect, translated) - ) - dialect = translated try: module = __import__("sqlalchemy.dialects.%s" % (dialect,)).dialects except ImportError: diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index 69e6834d2..a7086259b 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -2061,7 +2061,8 @@ class MSDDLCompiler(compiler.DDLCompiler): "will correspond to an actual SQL Server " "CREATE SEQUENCE in " "a future release. Please use the mssql_identity_start " - "and mssql_identity_increment parameters." + "and mssql_identity_increment parameters.", + version="1.3", ) if column.default.start == 0: start = 0 @@ -2225,7 +2226,8 @@ class MSIdentifierPreparer(compiler.IdentifierPreparer): "deprecated and will be removed in a future release. This " "flag has no effect on the behavior of the " "IdentifierPreparer.quote method; please refer to " - "quoted_name()." + "quoted_name().", + version="1.3", ) dbname, owner = _schema_elements(schema) diff --git a/lib/sqlalchemy/dialects/mysql/__init__.py b/lib/sqlalchemy/dialects/mysql/__init__.py index f1f1cce37..683d43877 100644 --- a/lib/sqlalchemy/dialects/mysql/__init__.py +++ b/lib/sqlalchemy/dialects/mysql/__init__.py @@ -7,7 +7,6 @@ from . import base # noqa from . import cymysql # noqa -from . import gaerdbms # noqa from . import mysqlconnector # noqa from . import mysqldb # noqa from . import oursql # noqa diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index 54a13b550..a075b4d6b 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -2141,14 +2141,10 @@ class MySQLTypeCompiler(compiler.GenericTypeCompiler): ) def visit_ENUM(self, type_, **kw): - return self._visit_enumerated_values( - "ENUM", type_, type_._enumerated_values - ) + return self._visit_enumerated_values("ENUM", type_, type_.enums) def visit_SET(self, type_, **kw): - return self._visit_enumerated_values( - "SET", type_, type_._enumerated_values - ) + return self._visit_enumerated_values("SET", type_, type_.values) def visit_BOOLEAN(self, type_, **kw): return "BOOL" diff --git a/lib/sqlalchemy/dialects/mysql/enumerated.py b/lib/sqlalchemy/dialects/mysql/enumerated.py index 536d03876..2bc25585e 100644 --- a/lib/sqlalchemy/dialects/mysql/enumerated.py +++ b/lib/sqlalchemy/dialects/mysql/enumerated.py @@ -12,53 +12,10 @@ from ... import exc from ... import sql from ... import util from ...sql import sqltypes +from ...sql.base import NO_ARG -class _EnumeratedValues(_StringType): - def _init_values(self, values, kw): - self.quoting = kw.pop("quoting", "auto") - - if self.quoting == "auto" and len(values): - # What quoting character are we using? - q = None - for e in values: - if len(e) == 0: - self.quoting = "unquoted" - break - elif q is None: - q = e[0] - - if len(e) == 1 or e[0] != q or e[-1] != q: - self.quoting = "unquoted" - break - else: - self.quoting = "quoted" - - if self.quoting == "quoted": - util.warn_deprecated( - "Manually quoting %s value literals is deprecated. Supply " - "unquoted values and use the quoting= option in cases of " - "ambiguity." % self.__class__.__name__ - ) - - values = self._strip_values(values) - - self._enumerated_values = values - length = max([len(v) for v in values] + [0]) - return values, length - - @classmethod - def _strip_values(cls, values): - strip_values = [] - for a in values: - if a[0:1] == '"' or a[0:1] == "'": - # strip enclosing quotes and unquote interior - a = a[1:-1].replace(a[0] * 2, a[0]) - strip_values.append(a) - return strip_values - - -class ENUM(sqltypes.NativeForEmulated, sqltypes.Enum, _EnumeratedValues): +class ENUM(sqltypes.NativeForEmulated, sqltypes.Enum, _StringType): """MySQL ENUM type.""" __visit_name__ = "ENUM" @@ -72,10 +29,10 @@ class ENUM(sqltypes.NativeForEmulated, sqltypes.Enum, _EnumeratedValues): Column('myenum', ENUM("foo", "bar", "baz")) - :param enums: The range of valid values for this ENUM. Values will be - quoted when generating the schema according to the quoting flag (see - below). This object may also be a PEP-435-compliant enumerated - type. + :param enums: The range of valid values for this ENUM. Values in + enums are not quoted, they will be escaped and surrounded by single + quotes when generating the schema. This object may also be a + PEP-435-compliant enumerated type. .. versionadded: 1.1 added support for PEP-435-compliant enumerated types. @@ -102,22 +59,15 @@ class ENUM(sqltypes.NativeForEmulated, sqltypes.Enum, _EnumeratedValues): BINARY in schema. This does not affect the type of data stored, only the collation of character data. - :param quoting: Defaults to 'auto': automatically determine enum value - quoting. If all enum values are surrounded by the same quoting - character, then use 'quoted' mode. Otherwise, use 'unquoted' mode. - - 'quoted': values in enums are already quoted, they will be used - directly when generating the schema - this usage is deprecated. - - 'unquoted': values in enums are not quoted, they will be escaped and - surrounded by single quotes when generating the schema. - - Previous versions of this type always required manually quoted - values to be supplied; future versions will always quote the string - literals for you. This is a transitional option. + :param quoting: Not used. A warning will be raised if provided. """ - + if kw.pop("quoting", NO_ARG) is not NO_ARG: + util.warn_deprecated_20( + "The 'quoting' parameter to :class:`.mysql.ENUM` is deprecated" + " and will be removed in a future release. " + "This parameter now has no effect." + ) kw.pop("strict", None) self._enum_init(enums, kw) _StringType.__init__(self, length=self.length, **kw) @@ -132,10 +82,6 @@ class ENUM(sqltypes.NativeForEmulated, sqltypes.Enum, _EnumeratedValues): kw.setdefault("values_callable", impl.values_callable) return cls(**kw) - def _setup_for_values(self, values, objects, kw): - values, length = self._init_values(values, kw) - return super(ENUM, self)._setup_for_values(values, objects, kw) - def _object_value_for_elem(self, elem): # mysql sends back a blank string for any value that # was persisted that was not in the enums; that is, it does no @@ -152,7 +98,7 @@ class ENUM(sqltypes.NativeForEmulated, sqltypes.Enum, _EnumeratedValues): ) -class SET(_EnumeratedValues): +class SET(_StringType): """MySQL SET type.""" __visit_name__ = "SET" @@ -169,7 +115,9 @@ class SET(_EnumeratedValues): set will be used to generate DDL for a table, or if the :paramref:`.SET.retrieve_as_bitwise` flag is set to True. - :param values: The range of valid values for this SET. + :param values: The range of valid values for this SET. The values + are not quoted, they will be escaped and surrounded by single + quotes when generating the schema. :param convert_unicode: Same flag as that of :paramref:`.String.convert_unicode`. @@ -184,22 +132,6 @@ class SET(_EnumeratedValues): :param binary: same as that of :paramref:`.VARCHAR.binary`. - :param quoting: Defaults to 'auto': automatically determine set value - quoting. If all values are surrounded by the same quoting - character, then use 'quoted' mode. Otherwise, use 'unquoted' mode. - - 'quoted': values in enums are already quoted, they will be used - directly when generating the schema - this usage is deprecated. - - 'unquoted': values in enums are not quoted, they will be escaped and - surrounded by single quotes when generating the schema. - - Previous versions of this type always required manually quoted - values to be supplied; future versions will always quote the string - literals for you. This is a transitional option. - - .. versionadded:: 0.9.0 - :param retrieve_as_bitwise: if True, the data for the set type will be persisted and selected using an integer value, where a set is coerced into a bitwise mask for persistence. MySQL allows this mode which @@ -218,10 +150,16 @@ class SET(_EnumeratedValues): .. versionadded:: 1.0.0 + :param quoting: Not used. A warning will be raised if passed. """ + if kw.pop("quoting", NO_ARG) is not NO_ARG: + util.warn_deprecated_20( + "The 'quoting' parameter to :class:`.mysql.SET` is deprecated" + " and will be removed in a future release. " + "This parameter now has no effect." + ) self.retrieve_as_bitwise = kw.pop("retrieve_as_bitwise", False) - values, length = self._init_values(values, kw) self.values = tuple(values) if not self.retrieve_as_bitwise and "" in values: raise exc.ArgumentError( @@ -235,6 +173,7 @@ class SET(_EnumeratedValues): self._bitmap.update( (2 ** idx, value) for idx, value in enumerate(self.values) ) + length = max([len(v) for v in values] + [0]) kw.setdefault("length", length) super(SET, self).__init__(**kw) diff --git a/lib/sqlalchemy/dialects/mysql/gaerdbms.py b/lib/sqlalchemy/dialects/mysql/gaerdbms.py deleted file mode 100644 index 0ba819d2d..000000000 --- a/lib/sqlalchemy/dialects/mysql/gaerdbms.py +++ /dev/null @@ -1,102 +0,0 @@ -# mysql/gaerdbms.py -# Copyright (C) 2005-2020 the SQLAlchemy authors and contributors -# <see AUTHORS file> -# -# This module is part of SQLAlchemy and is released under -# the MIT License: http://www.opensource.org/licenses/mit-license.php -r""" -.. dialect:: mysql+gaerdbms - :name: Google Cloud SQL - :dbapi: rdbms - :connectstring: mysql+gaerdbms:///<dbname>?instance=<instancename> - :url: https://developers.google.com/appengine/docs/python/cloud-sql/developers-guide - - This dialect is based primarily on the :mod:`.mysql.mysqldb` dialect with - minimal changes. - - .. deprecated:: 1.0 This dialect is **no longer necessary** for - Google Cloud SQL; the MySQLdb dialect can be used directly. - Cloud SQL now recommends creating connections via the - mysql dialect using the URL format - - ``mysql+mysqldb://root@/<dbname>?unix_socket=/cloudsql/<projectid>:<instancename>`` - - -Pooling -------- - -Google App Engine connections appear to be randomly recycled, -so the dialect does not pool connections. The :class:`.NullPool` -implementation is installed within the :class:`.Engine` by -default. - -""" # noqa - -import os -import re - -from sqlalchemy.util import warn_deprecated -from .mysqldb import MySQLDialect_mysqldb -from ...pool import NullPool - - -def _is_dev_environment(): - return os.environ.get("SERVER_SOFTWARE", "").startswith("Development/") - - -class MySQLDialect_gaerdbms(MySQLDialect_mysqldb): - @classmethod - def dbapi(cls): - - warn_deprecated( - "Google Cloud SQL now recommends creating connections via the " - "MySQLdb dialect directly, using the URL format " - "mysql+mysqldb://root@/<dbname>?unix_socket=/cloudsql/" - "<projectid>:<instancename>" - ) - - # from django: - # http://code.google.com/p/googleappengine/source/ - # browse/trunk/python/google/storage/speckle/ - # python/django/backend/base.py#118 - # see also [ticket:2649] - # see also http://stackoverflow.com/q/14224679/34549 - from google.appengine.api import apiproxy_stub_map - - if _is_dev_environment(): - from google.appengine.api import rdbms_mysqldb - - return rdbms_mysqldb - elif apiproxy_stub_map.apiproxy.GetStub("rdbms"): - from google.storage.speckle.python.api import rdbms_apiproxy - - return rdbms_apiproxy - else: - from google.storage.speckle.python.api import rdbms_googleapi - - return rdbms_googleapi - - @classmethod - def get_pool_class(cls, url): - # Cloud SQL connections die at any moment - return NullPool - - def create_connect_args(self, url): - opts = url.translate_connect_args() - if not _is_dev_environment(): - # 'dsn' and 'instance' are because we are skipping - # the traditional google.api.rdbms wrapper - opts["dsn"] = "" - opts["instance"] = url.query["instance"] - return [], opts - - def _extract_error_code(self, exception): - match = re.compile(r"^(\d+)L?:|^\((\d+)L?,").match(str(exception)) - # The rdbms api will wrap then re-raise some types of errors - # making this regex return no matches. - code = match.group(1) or match.group(2) if match else None - if code: - return int(code) - - -dialect = MySQLDialect_gaerdbms diff --git a/lib/sqlalchemy/dialects/mysql/reflection.py b/lib/sqlalchemy/dialects/mysql/reflection.py index 8aeb1dc96..5be6a010e 100644 --- a/lib/sqlalchemy/dialects/mysql/reflection.py +++ b/lib/sqlalchemy/dialects/mysql/reflection.py @@ -7,7 +7,7 @@ import re -from .enumerated import _EnumeratedValues +from .enumerated import ENUM from .enumerated import SET from .types import DATETIME from .types import TIME @@ -215,8 +215,8 @@ class MySQLTableDefinitionParser(object): for kw in ("charset", "collate"): if spec.get(kw, False): type_kw[kw] = spec[kw] - if issubclass(col_type, _EnumeratedValues): - type_args = _EnumeratedValues._strip_values(type_args) + if issubclass(col_type, (ENUM, SET)): + type_args = _strip_values(type_args) if issubclass(col_type, SET) and "" in type_args: type_kw["retrieve_as_bitwise"] = True @@ -545,3 +545,14 @@ def _re_compile(regex): """Compile a string to regex, I and UNICODE.""" return re.compile(regex, re.I | re.UNICODE) + + +def _strip_values(values): + "Strip reflected values quotes" + strip_values = [] + for a in values: + if a[0:1] == '"' or a[0:1] == "'": + # strip enclosing quotes and unquote interior + a = a[1:-1].replace(a[0] * 2, a[0]) + strip_values.append(a) + return strip_values diff --git a/lib/sqlalchemy/dialects/oracle/cx_oracle.py b/lib/sqlalchemy/dialects/oracle/cx_oracle.py index 3a3bbad25..2ac5510d1 100644 --- a/lib/sqlalchemy/dialects/oracle/cx_oracle.py +++ b/lib/sqlalchemy/dialects/oracle/cx_oracle.py @@ -1003,12 +1003,12 @@ class OracleDialect_cx_oracle(OracleDialect): def create_connect_args(self, url): opts = dict(url.query) - # deprecated in 1.3 for opt in ("use_ansi", "auto_convert_lobs"): if opt in opts: util.warn_deprecated( "cx_oracle dialect option %r should only be passed to " - "create_engine directly, not within the URL string" % opt + "create_engine directly, not within the URL string" % opt, + version="1.3", ) util.coerce_kw_type(opts, opt, bool) setattr(self, opt, opts.pop(opt)) |