관리-도구
편집 파일: enumerated.cpython-38.pyc
U -?�f ! � @ sp d dl Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ G d d � d ejej e�Z G dd� de�ZdS ) � N� )�_StringType� )�exc)�sql)�util)�sqltypesc sD e Zd ZdZd ZdZdd� Zedd� �Z� fdd�Z d d � Z � ZS )�ENUMzMySQL ENUM type.Tc O s4 |� dd� | �||� tj| fd| ji|�� dS )a� Construct 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. �strictN�length)�popZ _enum_initr �__init__r )�self�enums�kw� r �T/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/dialects/mysql/enumerated.pyr s &z ENUM.__init__c K s4 |� d|j� |� d|j� |� d|j� | f |�S )zXProduce a MySQL native :class:`.mysql.ENUM` from plain :class:`.Enum`. �validate_strings�values_callableZomit_aliases)� setdefaultr r Z _omit_aliases)�cls�implr r r r �adapt_emulated_to_nativeD s zENUM.adapt_emulated_to_nativec s |dkr|S t � �|�S d S )N� )�super�_object_value_for_elem)r �elem�� __class__r r r O s zENUM._object_value_for_elemc C s t j| tttjgd�S )N)� to_inspect)r �generic_reprr r r �Enum�r r r r �__repr__Y s �z ENUM.__repr__)�__name__� __module__�__qualname__�__doc__�__visit_name__Znative_enumr �classmethodr r r# � __classcell__r r r r r s * r c sT e Zd ZdZd Z� fdd�Zdd� Z� fdd�Z� fdd �Zd d� Z dd � Z � ZS )�SETzMySQL SET type.c s� |� dd�| _t|�| _| js0d|kr0t�d��| jrhdd� t| j�D �| _| j�dd� t| j�D �� t d d � |D �dg �}|� d|� t� jf |� d S )a Construct 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. �retrieve_as_bitwiseFr zNCan't use the blank value '' in a SET without setting retrieve_as_bitwise=Truec S s i | ]\}}|d | �qS )� r ��.0�idx�valuer r r � <dictcomp>� s z SET.__init__.<locals>.<dictcomp>c s s | ]\}}d | |fV qdS )r- Nr r. r r r � <genexpr>� s zSET.__init__.<locals>.<genexpr>c S s g | ]}t |��qS r )�len)r/ �vr r r � <listcomp>� s z SET.__init__.<locals>.<listcomp>r r N) r r, �tuple�valuesr � ArgumentError� enumerate�_bitmap�update�maxr r r )r r8 r r r r r r d s . ���zSET.__init__c C s( | j r t�t�|tj�d | �S |S d S �Nr )r, r Ztype_coercer �Integer)r Zcolexprr r r �column_expression� s �zSET.column_expressionc s2 � j r� fdd�}nt� �||���fdd�}|S )Nc s, | d k r$t | �} tt�� jj| ��S d S d S )N)�int�setr Zmap_bitsr; �__getitem__�r1 r"