diff options
author | Federico Caselli <cfederico87@gmail.com> | 2020-04-08 20:26:21 +0200 |
---|---|---|
committer | Federico Caselli <cfederico87@gmail.com> | 2020-04-09 00:33:22 +0200 |
commit | a9b068ae564e5e775e312373088545b75aeaa1b0 (patch) | |
tree | 3a20c79acfefe49b62ee4bca360bb11001f9eec9 /lib/sqlalchemy/dialects/mysql/enumerated.py | |
parent | ecca4fe3f8aebc5b42c2acda2e5d28d6a90a821e (diff) | |
download | sqlalchemy-a9b068ae564e5e775e312373088545b75aeaa1b0.tar.gz |
Remove code deprecated before version 1.1
- Remove deprecated method ``get_primary_keys` in the :class:`.Dialect` and
:class:`.Inspector` classes.
- Remove deprecated event ``dbapi_error`` and the method ``ConnectionEvents.dbapi_error`.
- Remove support for deprecated engine URLs of the form ``postgres://``.
- Remove deprecated dialect ``mysql+gaerdbms``.
- Remove deprecated parameter ``quoting`` from :class:`.mysql.ENUM`
and :class:`.mysql.SET` in the ``mysql`` dialect.
- Remove deprecated function ``comparable_property``. and function
``comparable_using`` in the declarative extension.
- Remove deprecated function ``compile_mappers``.
- Remove deprecated method ``collection.linker``.
- Remove deprecated method ``Session.prune`` and parameter ``Session.weak_identity_map``.
This change also removes the class ``StrongInstanceDict``.
- Remove deprecated parameter ``mapper.order_by``.
- Remove deprecated parameter ``Session._enable_transaction_accounting`.
- Remove deprecated parameter ``Session.is_modified.passive``.
- Remove deprecated class ``Binary``. Please use :class:`.LargeBinary`.
- Remove deprecated methods ``Compiled.compile``, ``ClauseElement.__and__`` and
``ClauseElement.__or__`` and attribute ``Over.func``.
- Remove deprecated ``FromClause.count`` method.
- Remove deprecated parameter ``Table.useexisting``.
- Remove deprecated parameters ``text.bindparams`` and ``text.typemap``.
- Remove boolean support for the ``passive`` parameter in ``get_history``.
- Remove deprecated ``adapt_operator`` in ``UserDefinedType.Comparator``.
Fixes: #4643
Change-Id: Idcd390c77bf7b0e9957907716993bdaa3f1a1763
Diffstat (limited to 'lib/sqlalchemy/dialects/mysql/enumerated.py')
-rw-r--r-- | lib/sqlalchemy/dialects/mysql/enumerated.py | 111 |
1 files changed, 25 insertions, 86 deletions
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) |