o
    ‹åg¬  ã                   @  sø   U d dl mZ d dlZd dlZd dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 d dlm
Z
 d dlmZ d d	lmZ d
dlmZ d
dlmZ dZi Zded< d.dd„Zd/dd„Zd0d d!„Zd1d$d%„Zed&ƒ	'd2d3d*d&„ƒZed+ƒd2d3d,d-„ƒZdS )4é    )ÚannotationsN)ÚAny)ÚCallable)ÚDict)ÚList)ÚMapping)ÚOptional)ÚUnioné   )Úutil)ÚcompatÚREVISION_SCRIPT_FILENAMEÚdictÚ	_registryÚnameÚstrÚreturnr   c                   s   ‡ fdd„}|S )z¿A function decorator that will register that function as a write hook.

    See the documentation linked below for an example.

    .. seealso::

        :ref:`post_write_hooks_custom`


    c                   s   | t ˆ < | S )N)r   )Úfn©r   © úV/var/www/html/flaskapp/venv/lib/python3.10/site-packages/alembic/script/write_hooks.pyÚdecorate&   s   zregister.<locals>.decorater   )r   r   r   r   r   Úregister   s   r   ÚrevisionÚoptionsúMapping[str, Union[str, int]]r   c              
   C  sD   zt |  }W n ty } z
t d| › d�¡|‚d}~ww |||ƒS )a7  Invokes the formatter registered for the given name.

    :param name: The name of a formatter in the registry
    :param revision: A :class:`.MigrationRevision` instance
    :param options: A dict containing kwargs passed to the
        specified formatter.
    :raises: :class:`alembic.util.CommandError`
    zNo formatter with name 'z' registeredN)r   ÚKeyErrorr   ÚCommandError)r   r   r   ÚhookÚker   r   r   Ú_invoke-   s   
ÿþ€ÿ
r    ÚpathÚhook_configúMapping[str, str]ÚNonec                   sÌ   ddl m} | ˆ  dd¡¡}|D ]R‰ˆsq‡ ‡fdd„ˆ D ƒ}ˆ|d< z|d }W n tyB } zt d	ˆ› d
ˆ›�¡|‚d}~ww tjdˆ›�dd�� t|| |ƒ W d  ƒ n1 s^w   Y  qdS )z&Invoke hooks for a generated revision.é   )Ú_split_on_space_commaÚhooksÚ c                   s4   i | ]}|  ˆd  ¡r|tˆƒd d… ˆ | “qS )Ú.r%   N)Ú
startswithÚlen)Ú.0Úkey©r"   r   r   r   Ú
<dictcomp>L   s    ýÿz_run_hooks.<locals>.<dictcomp>Ú
_hook_nameÚtypeúKey z&.type is required for post write hook NzRunning post write hook T)Únewline)	Úbaser&   ÚsplitÚgetr   r   r   Ústatusr    )r!   r"   r&   ÚnamesÚoptsÚtype_r   r   r.   r   Ú
_run_hooksB   s4   þÿþ€ÿ
ÿý€ðr;   Úcmdline_options_strú	List[str]c                   s:   t | vr
t d |  } tj| tjd�}‡ fdd„|D ƒ}|S )züParse options from a string into a list.

    Also substitutes the revision script token with the actual filename of
    the revision script.

    If the revision script token doesn't occur in the options string, it is
    automatically prepended.
    ú )Úposixc                   s   g | ]}|  tˆ ¡‘qS r   )ÚreplaceÚREVISION_SCRIPT_TOKEN)r,   Úoption©r!   r   r   Ú
<listcomp>m   s    
ÿÿz*_parse_cmdline_options.<locals>.<listcomp>)rA   Úshlexr5   r   Úis_posix)r<   r!   Úcmdline_options_listr   rC   r   Ú_parse_cmdline_options_   s   	ÿ
þrH   Úconsole_scriptsFÚignore_outputÚboolc              
   C  sô   z|d }W n t y" } zt d|d › d|d ›�¡|‚d }~ww t d¡D ]}|j|kr3|} n	q(t d|› �¡‚| dd ¡}| dd	¡}t|| ƒ}	i }
|rZtj	 |
d
< |
d< tj
tjdd|j› d|j› d|j› d�g|	 fd|i|
¤Ž d S )NÚ
entrypointr2   r0   z,.entrypoint is required for post write hook rI   z*Could not find entrypoint console_scripts.Úcwdr   r(   ÚstdoutÚstderrz-czimport z; r)   z())r   r   r   r   Úimportlib_metadata_getr   r6   rH   Ú
subprocessÚDEVNULLÚrunÚsysÚ
executableÚmoduleÚattr)r!   r   rJ   Úentrypoint_namer   ÚentryÚimplrM   r<   rG   Úkwr   r   r   rI   t   sL   ÿÿý€ÿ
þÿ
ýûÿù
øÚexecc           	   
   C  s¢   z|d }W n t y" } zt d|d › d|d ›�¡|‚d }~ww | dd ¡}| dd¡}t|| ƒ}i }|rAtj |d< |d	< tj|g|¢fd|i|¤Ž d S )
NrU   r2   r0   z,.executable is required for post write hook rM   r   r(   rN   rO   )r   r   r   r6   rH   rQ   rR   rS   )	r!   r   rJ   rU   r   rM   r<   rG   r[   r   r   r   Úexec_›   s8   ÿÿý€ÿ
ÿþÿû
úr]   )r   r   r   r   )r   r   r   r   r   r   r   r   )r!   r   r"   r#   r   r$   )r<   r   r!   r   r   r=   )F)r!   r   r   r   rJ   rK   r   r$   )Ú
__future__r   rE   rQ   rT   Útypingr   r   r   r   r   r   r	   r(   r   r   rA   r   Ú__annotations__r   r    r;   rH   rI   r]   r   r   r   r   Ú<module>   s0   



ÿ&