Hacked By AnonymousFox

Current Path : /opt/cloudlinux/venv/lib64/python3.11/site-packages/alembic/autogenerate/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/alembic/autogenerate/__pycache__/rewriter.cpython-311.pyc

�

�܋f���ddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm	Z	dd	lm
Z
dd
lmZddl
mZe	r6ddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZGd�d��ZdS)�)�annotations)�Any)�Callable)�Iterator)�List)�Optional)�Type)�
TYPE_CHECKING)�Union)�util)�ops)�AddColumnOp)�
AlterColumnOp)�
CreateTableOp)�MigrateOperation)�MigrationScript)�ModifyTableOps)�OpContainer)�MigrationContext)�Revisionc�X�eZdZUdZej��ZdZded<d"d�Z	d#d	�Z
d$d
�Zd%d�Zd&d�Z
e�ej��d'd���Ze�ej��d(d���Ze�ej��d)d���Zd*d�Zd+d �Zd&d!�ZdS),�Rewritera5A helper object that allows easy 'rewriting' of ops streams.

    The :class:`.Rewriter` object is intended to be passed along
    to the
    :paramref:`.EnvironmentContext.configure.process_revision_directives`
    parameter in an ``env.py`` script.    Once constructed, any number
    of "rewrites" functions can be associated with it, which will be given
    the opportunity to modify the structure without having to have explicit
    knowledge of the overall structure.

    The function is passed the :class:`.MigrationContext` object and
    ``revision`` tuple that are passed to the  :paramref:`.Environment
    Context.configure.process_revision_directives` function normally,
    and the third argument is an individual directive of the type
    noted in the decorator.  The function has the choice of  returning
    a single op directive, which normally can be the directive that
    was actually passed, or a new directive to replace it, or a list
    of zero or more directives to replace it.

    .. seealso::

        :ref:`autogen_rewriter` - usage example

    NzOptional[Rewriter]�_chained�return�Nonec�6�tj��|_dS�N)r�
Dispatcher�dispatch)�selfs �T/opt/cloudlinux/venv/lib64/python3.11/site-packages/alembic/autogenerate/rewriter.py�__init__zRewriter.__init__9s����)�)��
�
�
��otherc��|j�|j��}|j�|j��||_|S)a�Produce a "chain" of this :class:`.Rewriter` to another.

        This allows two rewriters to operate serially on a stream,
        e.g.::

            writer1 = autogenerate.Rewriter()
            writer2 = autogenerate.Rewriter()


            @writer1.rewrites(ops.AddColumnOp)
            def add_column_nullable(context, revision, op):
                op.column.nullable = True
                return op


            @writer2.rewrites(ops.AddColumnOp)
            def add_column_idx(context, revision, op):
                idx_op = ops.CreateIndexOp(
                    "ixc", op.table_name, [op.column.name]
                )
                return [op, idx_op]

            writer = writer1.chain(writer2)

        :param other: a :class:`.Rewriter` instance
        :return: a new :class:`.Rewriter` that will run the operations
         of this writer, then the "other" writer, in succession.

        )�	__class__�__new__�__dict__�updater)r r$�wrs   r!�chainzRewriter.chain<s?��<�^�
#�
#�D�N�
3�
3��
����4�=�)�)�)�����	r#�operator�pUnion[Type[AddColumnOp], Type[MigrateOperation], Type[AlterColumnOp], Type[CreateTableOp], Type[ModifyTableOps]]rc�6�|j�|��S)a�Register a function as rewriter for a given type.

        The function should receive three arguments, which are
        the :class:`.MigrationContext`, a ``revision`` tuple, and
        an op directive of the type indicated.  E.g.::

            @writer1.rewrites(ops.AddColumnOp)
            def add_column_nullable(context, revision, op):
                op.column.nullable = True
                return op

        )r�dispatch_for)r r,s  r!�rewriteszRewriter.rewrites_s��,�}�)�)�(�3�3�3r#�contextr�revisionr�	directiver�Iterator[MigrateOperation]c#�K�	|j�|��}||jvr|V�dStj||||��g��D]&}|j�|g��|_|V��'dS#t
$r
d}|V�YdSwxYwr)r�
_mutationsr�to_list�union�
ValueError)r r1r2r3�	_rewriter�r_directives      r!�_rewritezRewriter._rewritews�����	&��
�.�.�y�9�9�I�
�y�+�+�+�������#'�<��I�g�x��;�;�R�$�$�&�&�K�.9�-C�-I�-I���.�.�K�*�&�%�%�%�%�
&�&���	�	�	��I��O�O�O�O�O�O�	���s�A6�6B
�	B
�
directives�List[MigrationScript]c�t�|�|||��|jr|�|||��dSdSr)�process_revision_directivesr�r r1r2r=s    r!�__call__zRewriter.__call__�sL��	
�(�(��(�J�G�G�G��=�	9��M�M�'�8�Z�8�8�8�8�8�	9�	9r#rc��g}|jD]V}|�|||��}t|��dkrtd���|�|d���W||_g}|jD]V}|�|||��}t|��dkrtd���|�|d���W||_dS)N�z5Can only return single object for UpgradeOps traverserz7Can only return single object for DowngradeOps traverse)�upgrade_ops_list�
_traverse_for�lenr9�append�upgrade_ops�downgrade_ops_list�
downgrade_ops)	r r1r2r3rErI�retrJrKs	         r!�_traverse_scriptzRewriter._traverse_script�s�����$�5�	,�	,�K��$�$�W�h��D�D�C��3�x�x�1�}�}� �K����
�#�#�C��F�+�+�+�+� 0�	����&�9�	.�	.�M��$�$�W�h�
�F�F�C��3�x�x�1�}�}� �M����
�%�%�c�!�f�-�-�-�-�"4�	���r#rc�>�|�|||j��dSr)�_traverse_listr
�r r1r2r3s    r!�_traverse_op_containerzRewriter._traverse_op_container�s$��	
���G�X�y�}�=�=�=�=�=r#c��dSr�rPs    r!�_traverse_any_directivez Rewriter._traverse_any_directive�s	��	
�r#rc��t|�|||����}|D]*}|j�|��}|||||���+|Sr)�listr<�	_traverser)r r1r2r3r=�	traversers      r!rFzRewriter._traverse_for�sd���$�-�-���9�E�E�F�F�
�#�	:�	:�I���/�/�	�:�:�I��I�d�G�X�y�9�9�9�9��r#c�v�g}|D],}|�|�|||�����-||dd�<dSr)�extendrF)r r1r2r=�destr3s      r!rOzRewriter._traverse_list�sR����#�	J�	J�I��K�K��*�*�7�H�i�H�H�I�I�I�I��
�1�1�1�
�
�
r#c�4�|�|||��dSr)rOrAs    r!r@z$Rewriter.process_revision_directives�s"��	
���G�X�z�:�:�:�:�:r#)rr)r$rrr)r,r-rr)r1rr2rr3rrr4)r1rr2rr=r>rr)r1rr2rr3rrr)r1rr2rr3rrr)r1rr2rr3rrr)r1rr2rr3rrr)r1rr2rr=rrr)�__name__�
__module__�__qualname__�__doc__rrrWr�__annotations__r"r+r0r<rBr/r
rrMrrQrrTrFrOr@rSr#r!rrsx���������2 ���!�!�I�#'�H�'�'�'�'�*�*�*�*�!�!�!�!�F4�4�4�4�0&�&�&�&�.9�9�9�9����C�/�0�0�5�5�5�1�0�5�4���C�O�,�,�>�>�>�-�,�>����C�0�1�1�
�
�
�2�1�
�
�
�
�
�
�
�
�
�;�;�;�;�;�;r#rN)�
__future__r�typingrrrrrr	r
r�alembicr�alembic.operationsr
�alembic.operations.opsrrrrrrr�alembic.runtime.migrationr�alembic.script.revisionrrrSr#r!�<module>ris���"�"�"�"�"�"������������������������������������� � � � � � �������������"�"�"�"�"�"��	1�2�2�2�2�2�2�4�4�4�4�4�4�4�4�4�4�4�4�7�7�7�7�7�7�6�6�6�6�6�6�5�5�5�5�5�5�2�2�2�2�2�2�:�:�:�:�:�:�0�0�0�0�0�0�H;�H;�H;�H;�H;�H;�H;�H;�H;�H;r#

Hacked By AnonymousFox1.0, Coded By AnonymousFox