
    ZeIip                    \   U d dl mZ d dlZd dl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 erdd
lmZ dZi Zded<   d-dZd.dZd/dZd0d Zd1d!Zd2d%Z ed&          	 d3d4d(            Z ed)          d3d4d*            Z ed+          d3d4d,            ZdS )5    )annotationsN)Any)Callable)TYPE_CHECKING   )util)compat)_preserving_path_as_str)PostWriteHookConfigREVISION_SCRIPT_FILENAMEdict	_registrynamestrreturnr   c                      fd}|S )zA 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                    | t           <   | S )N)r   )fnr   s    _/var/www/html/MCyber-Diagnostic/venv/lib/python3.11/site-packages/alembic/script/write_hooks.pydecoratezregister.<locals>.decorate'   s    	$	     )r   r   s   ` r   registerr      s#         Or   revision_pathstr | os.PathLike[str]optionsr   r   c                    t          |          }	 t          |          } |||          S # t          $ r}t          j        d|  d          |d}~ww xY w)a1  Invokes the formatter registered for the given name.

    :param name: The name of a formatter in the registry
    :param revision: string path to the revision file
    :param options: A dict containing kwargs passed to the
        specified formatter.
    :raises: :class:`alembic.util.CommandError`
    zNo formatter with name 'z' registeredN)r
   r   KeyErrorr   CommandError)r   r   r   hookkes        r   _invoker"   .   sz     ,M::M, tM7+++    9t999
 
	s   * 
AAApathhookslist[PostWriteHookConfig]Nonec                   |D ]}|d         }	 |d         }t          j        d|d          5  t          || |           ddd           n# 1 swxY w Y   V# t          $ r }t          j        d| d|          |d}~ww xY wdS )	z&Invoke hooks for a generated revision.
_hook_nametypezRunning post write hook T)newlineNzKey 'z;.type' (or 'type' in toml) is required for post write hook )r   statusr"   r   r   )r#   r$   r    r   type_r!   s         r   
_run_hooksr-   F   s   
  + +L!	+LE 3433T   + + tT***+ + + + + + + + + + + + + + +  	 	 	#0 0 0'+0 0  		+ +s(   AAA	A	
B#A>>Bcmdline_options_str	list[str]c                    t           | vrt           dz   | z   } t          j        | t          j                  }fd|D             }|S )zParse 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                F    g | ]}|                     t                    S r   )replaceREVISION_SCRIPT_TOKEN).0optionr#   s     r   
<listcomp>z*_parse_cmdline_options.<locals>.<listcomp>i   s8        	,d33  r   )r5   shlexsplitr	   is_posix)r.   r#   cmdline_options_lists    ` r   _parse_cmdline_optionsr=   [   sq     $7773c9<OO ;6?     *    r   c           
         	 | |         S # t           $ r/}t          j        d| d          d| d| d                   |d }~ww xY w)NzKey r(   .z! is required for post write hook )r   r   r   )r   r   r!   s      r   _get_required_optionr@   p   s~    t}   47<( 4 44 4 4!,/4 4
 
 	s   
 
A*>Aignore_outputboolcommandc                    |                     dd           }|                     dd          }t          ||           }i }|rt          j        x|d<   |d<   t          j        g ||fd|i| d S )Ncwdr    stdoutstderr)getr=   
subprocessDEVNULLrun)r#   r   rA   rC   rE   r.   r<   kws           r   	_run_hookrN   z   s     kk%..C!++i4412EtLLB 9&0&888r(|N4W434DD#DDDDDDr   console_scriptsFc           	        t          |d          }t          j        d          D ]}|j        |k    r|} nt	          j        d|           t          j        dd|j         d|j         d|j	         dg}t          | |||           d S )	N
entrypointrO   z*Could not find entrypoint console_scripts.z-czimport z; r?   z())r@   r	   importlib_metadata_getr   r   r   sys
executablemoduleattrrN   )r#   r   rA   entrypoint_nameentryimplrC   s          r   rO   rO      s     +7LAAO./@AA 
 
:((DE ) JJJ
 
 	

 	<$+<<<<ty<<<G
 dG]G44444r   execc                N    t          |d          }t          | |||g           d S )NrT   )rC   )r@   rN   )r#   r   rA   rT   s       r   exec_r\      s0    %g|<<JdG]ZLAAAAAAr   rU   c                    t          |d          }t          j                            |          t          j        d|           t
          j        d|g}t          | |||           d S )NrU   zCould not find module z-m)r@   	importlibr   	find_specr   rS   rT   rN   )r#   r   rA   module_namerC   s        r   rU   rU      si    &w99K~,,4 F F FGGG~t[1GdG]G44444r   )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   r   r   r   r   r   )
r#   r   r   r   rA   rB   rC   r/   r   r&   )F)r#   r   r   r   rA   rB   r   r&   )
__future__r   importlib.utilr^   osr9   rJ   rS   typingr   r   r   rF   r   r	   util.pyfilesr
   configr   r5   r   __annotations__r   r"   r-   r=   r@   rN   rO   r\   rU   r   r   r   <module>rh      s   # " " " " " "     				      



                                     2 2 2 2 2 2 -,,,,,,2 	       &, , , ,0+ + + +*       *   E E E E 

495 5 5 5 5* 
&B B B B B
 
(5 5 5 5 5 5 5r   