U a$@s|ddlZddlmZddlmZddlmZddlmZddlmZdd lm Z Gd d d ej ej eZ Gd d d eZ dS)N) _StringType)exc)sql)util)sqltypes)NO_ARGcsDeZdZdZdZdZddZeddZfddZ d d Z Z S) ENUMzMySQL ENUM type.TcOsN|dttk rtd|dd|||tj|fd|ji|dS)aConstruct an ENUM. E.g.:: Column('myenum', ENUM("foo", "bar", "baz")) :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. :param strict: This flag has no effect. .. versionchanged:: The MySQL ENUM type as well as the base Enum type now validates all Python data values. :param charset: Optional, a column-level character set for this string value. Takes precedence to 'ascii' or 'unicode' short-hand. :param collation: Optional, a column-level collation for this string value. Takes precedence to 'binary' short-hand. :param ascii: Defaults to False: short-hand for the ``latin1`` character set, generates ASCII in schema. :param unicode: Defaults to False: short-hand for the ``ucs2`` character set, generates UNICODE in schema. :param binary: Defaults to False: short-hand, pick the binary collation type that matches the column's character set. Generates BINARY in schema. This does not affect the type of data stored, only the collation of character data. :param quoting: Not used. A warning will be raised if provided. quotingzThe 'quoting' parameter to :class:`.mysql.ENUM` is deprecated and will be removed in a future release. This parameter now has no effect.strictNlength)popr rwarn_deprecated_20Z _enum_initr__init__r )selfenumskwreC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-nyjtotrf\sqlalchemy\dialects\mysql\enumerated.pyrs(  z ENUM.__init__cKs4|d|j|d|j|d|j|f|S)zXProduce a MySQL native :class:`.mysql.ENUM` from plain :class:`.Enum`. validate_stringsvalues_callableZ omit_aliases) setdefaultrrZ _omit_aliases)clsimplrrrradapt_emulated_to_nativeKszENUM.adapt_emulated_to_nativecs |dkr |Stt||SdS)N)superr _object_value_for_elem)relem __class__rrrVszENUM._object_value_for_elemcCstj|tttjgdS)N)Z to_inspect)rZ generic_reprr rrEnumrrrr__repr__`s z ENUM.__repr__) __name__ __module__ __qualname____doc____visit_name__Z native_enumr classmethodrrr$ __classcell__rrr rr s2 r csLeZdZdZdZfddZddZfddZfdd Zd d Z Z S) SETzMySQL SET type.cs|dttk rtd|dd|_t||_|jsJd|krJtd|jrt ddt |jD|_ |j d dt |jDt d d |Dd g}|d |tt|jf|dS)aConstruct a SET. E.g.:: Column('myset', SET("foo", "bar", "baz")) The list of potential values is required in the case that this 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. 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`. :param collation: same as that of :paramref:`.String.collation` :param charset: same as that of :paramref:`.VARCHAR.charset`. :param ascii: same as that of :paramref:`.VARCHAR.ascii`. :param unicode: same as that of :paramref:`.VARCHAR.unicode`. :param binary: same as that of :paramref:`.VARCHAR.binary`. :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 has the advantage of being able to store values unambiguously, such as the blank string ``''``. The datatype will appear as the expression ``col + 0`` in a SELECT statement, so that the value is coerced into an integer value in result sets. This flag is required if one wishes to persist a set that can store the blank string ``''`` as a value. .. warning:: When using :paramref:`.mysql.SET.retrieve_as_bitwise`, it is essential that the list of set values is expressed in the **exact same order** as exists on the MySQL database. .. versionadded:: 1.0.0 :param quoting: Not used. A warning will be raised if passed. r zThe 'quoting' parameter to :class:`.mysql.SET` is deprecated and will be removed in a future release. This parameter now has no effect.retrieve_as_bitwiseFrzNCan't use the blank value '' in a SET without setting retrieve_as_bitwise=Truecss|]\}}|d|fVqdSNr.0idxvaluerrr szSET.__init__..css|]\}}d||fVqdSr.rr0rrrr4scSsg|] }t|qSr)len)r1vrrr sz SET.__init__..rr N)rr rrr-tuplevaluesr ArgumentErrordict enumerate_bitmapupdatemaxrrr,r)rr9rr r rrrks(2    z SET.__init__cCs(|jr tt|tjd|S|SdSNr)r-rZ type_coercerZInteger)rZcolexprrrrcolumn_expressions zSET.column_expressioncs6jrfdd}ntt||fdd}|S)Ncs,|dk r$t|}ttjj|SdSdS)N)intsetrZmap_bitsr= __getitem__r3r#rrprocesssz%SET.result_processor..processcsBt|tjr(r|}ttd|S|dk r:|d|SdS)Nz[^,]+r) isinstancer string_typesrCrefindalldiscardrE super_convertrrrFs  )r-rr,result_processor)rdialectZcoltyperFr rrMrrNs   zSET.result_processorcs6tt|jr&fdd}n fdd}|S)NcsT|dkr dSt|tjtjr0r*|S|Sn d}|D]}|j|O}q8|SdSr@)rGr int_typesrHr=)r3Z int_valuer6rPrrrFsz#SET.bind_processor..processcs8|dk r$t|tjtjs$d|}r0|S|SdS)N,)rGrrQrHjoinrErLrrrFs   )rr,bind_processorr-)rrOrFr rPrrTs  zSET.bind_processorcKs |j|d<tj||f|j|S)Nr-)r-rZconstructor_copyr9)rZimpltyperrrradapts z SET.adapt) r%r&r'r(r)rrArNrTrUr+rrr rr,fs J  "r,)rItypesrrrrrrZsql.baser ZNativeForEmulatedr"r r,rrrrs      T