
    ZeIi                       d dl mZ d dlmZ d dlmZ d dlmZ d dlZd dlZd dl	m
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 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   G d d          Z!ee"e"f         Z# G d ded          Z$ G d de          Z% G d  d!          Z&	 	 d,d-d*Z'e(d+k    r e'             dS dS ).    )annotations)ArgumentParser)	Namespace)ConfigParserN)Path)Any)cast)Dict)Mapping)Optional)overload)Protocol)Sequence)TextIO)Union)	TypedDict   )__version__)command)util)compat)_preserving_path_as_strc                     e Zd ZU dZddddej        d ej                    dfdOdZdZ	de
d<   	 dZde
d<   	 dZde
d<   	 edPd            ZedPd            ZdZde
d<   	 ej        dQd            ZdRd"Zej        dSd$            Zej        dTd%            ZdUd&ZdVd(Ze	 dWdXd-            ZedYd/            ZedZd2            Z	 d[d\d4Zd]d6Zd^d7Zd_d9Z	 d[d`d:Zedad;            Ze	 d[dbd<            Z	 d[dbd=Zedad>            Ze	 d[dbd?            Z	 d[dcdAZdddCZ 	 d[dedEZ!ej        dfdG            Z"dgdIZ#dhdKZ$dhdLZ%didNZ&dS )jConfiga;  Represent an Alembic configuration.

    Within an ``env.py`` script, this is available
    via the :attr:`.EnvironmentContext.config` attribute,
    which in turn is available at ``alembic.context``::

        from alembic import context

        some_param = context.config.get_main_option("my option")

    When invoking Alembic programmatically, a new
    :class:`.Config` can be created by passing
    the name of an .ini file to the constructor::

        from alembic.config import Config
        alembic_cfg = Config("/path/to/yourapp/alembic.ini")

    With a :class:`.Config` object, you can then
    run Alembic commands programmatically using the directives
    in :mod:`alembic.command`.

    The :class:`.Config` object can also be constructed without
    a filename.   Values can be set programmatically, and
    new sections will be created as needed::

        from alembic.config import Config
        alembic_cfg = Config()
        alembic_cfg.set_main_option("script_location", "myapp:migrations")
        alembic_cfg.set_main_option("sqlalchemy.url", "postgresql://foo/bar")
        alembic_cfg.set_section_option("mysection", "foo", "bar")

    .. warning::

       When using programmatic configuration, make sure the
       ``env.py`` file in use is compatible with the target configuration;
       including that the call to Python ``logging.fileConfig()`` is
       omitted if the programmatic configuration doesn't actually include
       logging directives.

    For passing non-string values to environments, such as connections and
    engines, use the :attr:`.Config.attributes` dictionary::

        with engine.begin() as connection:
            alembic_cfg.attributes['connection'] = connection
            command.upgrade(alembic_cfg, "head")

    :param file\_: name of the .ini file to open if an ``alembic.ini`` is
     to be used.    This should refer to the ``alembic.ini`` file, either as
     a filename or a full path to the file.  This filename if passed must refer
     to an **ini file in ConfigParser format** only.

    :param toml\_file: name of the pyproject.toml file to open if a
     ``pyproject.toml`` file is to be used.  This should refer to the
     ``pyproject.toml`` file, either as a filename or a full path to the file.
     This file must be in toml format. Both :paramref:`.Config.file\_` and
     :paramref:`.Config.toml\_file` may be passed simultaneously, or
     exclusively.

     .. versionadded:: 1.16.0

    :param ini_section: name of the main Alembic section within the
     .ini file
    :param output_buffer: optional file-like input buffer which
     will be passed to the :class:`.MigrationContext` - used to redirect
     the output of "offline generation" when using Alembic programmatically.
    :param stdout: buffer where the "print" output of commands will be sent.
     Defaults to ``sys.stdout``.

    :param config_args: A dictionary of keys and values that will be used
     for substitution in the alembic config file, as well as the pyproject.toml
     file, depending on which / both are used.  The dictionary as given is
     **copied** to two new, independent dictionaries, stored locally under the
     attributes ``.config_args`` and ``.toml_args``.   Both of these
     dictionaries will also be populated with the replacement variable
     ``%(here)s``, which refers to the location of the .ini and/or .toml file
     as appropriate.

    :param attributes: optional dictionary of arbitrary Python keys/values,
     which will be populated into the :attr:`.Config.attributes` dictionary.

     .. seealso::

        :ref:`connection_sharing`

    Nalembicfile_"Union[str, os.PathLike[str], None]	toml_fileini_sectionstroutput_bufferOptional[TextIO]stdoutr   cmd_optsOptional[Namespace]config_argsMapping[str, Any]
attributesOptional[Dict[str, Any]]returnNonec	                *   |rt          |          nd| _        |rt          |          nd| _        || _        || _        || _        || _        t          |          | _        t          |          | _	        |r| j
                            |           dS dS )z Construct a new :class:`.Config`N)r   config_file_nametoml_file_nameconfig_ini_sectionr!   r#   r$   dictr&   	toml_argsr(   update)	selfr   r   r   r!   r#   r$   r&   r(   s	            S/var/www/html/MCyber-Diagnostic/venv/lib/python3.11/site-packages/alembic/config.py__init__zConfig.__init__v   s     /4=#E*** 	 3<E#I... 	 #.* ,,k** 	/O"":.....	/ 	/    Optional[str]r-   r.   Optional[Path]c                <    | j         d S t          | j                   S N)r-   r   r3   s    r4   _config_file_pathzConfig._config_file_path   s!     (4D)***r6   c                <    | j         d S t          | j                   S r:   )r.   r   r;   s    r4   _toml_file_pathzConfig._toml_file_path   s!    &4D'(((r6   r/   Dict[str, Any]c                    i S )a  A Python dictionary for storage of additional state.


        This is a utility dictionary which can include not just strings but
        engines, connections, schema objects, or anything else.
        Use this to pass objects into an env.py script, such as passing
        a :class:`sqlalchemy.engine.base.Connection` when calling
        commands from :mod:`alembic.command` programmatically.

        .. seealso::

            :ref:`connection_sharing`

            :paramref:`.Config.attributes`

         r;   s    r4   r(   zConfig.attributes   s	    $ 	r6   textargr   c                    |rt          |          |z  }nt          |          }t          j        | j        |dfi | j         dS )a  Render a message to standard out.

        When :meth:`.Config.print_stdout` is called with additional args
        those arguments will formatted against the provided text,
        otherwise we simply output the provided text verbatim.

        This is a no-op when the``quiet`` messaging option is enabled.

        e.g.::

            >>> config.print_stdout('Some text %s', 'arg')
            Some Text arg

        
N)r    r   write_outstreamr#   messaging_opts)r3   rB   rC   outputs       r4   print_stdoutzConfig.print_stdout   sP       	YY_FFYYFT[&$NN$:MNNNNNr6   r   c                H   | j         r| j                                         j        }nt                      }|                                | j        d<   t          | j                  }| j         rt          j        || j         g           n|	                    | j
                   |S )a  Return the underlying ``ConfigParser`` object.

        Dir*-ect access to the .ini file is available here,
        though the :meth:`.Config.get_section` and
        :meth:`.Config.get_main_option`
        methods provide a possibly simpler interface.

        here)r<   absoluteparentr   as_posixr&   r   r   read_config_parseradd_sectionr/   )r3   rK   file_configs      r4   rQ   zConfig.file_config   s     ! 	)2244;DD66D#'==?? "4#344! 	=%kD4J3KLLLL##D$;<<<r6   c                    | j         r| j                                         r| j                                         j        }|                                | j        d<   t          | j         d          5 }t          j        	                    |          }|
                    di           
                    di           }t          |t                    st          j        d          |cddd           S # 1 swxY w Y   dS i S )zMReturn a dictionary of the [tool.alembic] section from
        pyproject.tomlrK   rbtoolr   zIncorrect TOML formatN)r>   existsrL   rM   rN   r1   openr   tomllibloadget
isinstancer0   r   CommandError)r3   rK   f	toml_datadatas        r4   toml_alembic_configzConfig.toml_alembic_config   s+   
  	D$8$?$?$A$A 	'00229D%)]]__DN6"d*D11 Q"N//22	 }}VR0044YCC!$-- E+,CDDD                  Is   0A4C11C58C5c                    ddl }t          |j                                                  j        }t          |dz            S )zReturn the directory where Alembic setup templates are found.

        This method is used by the alembic ``init`` and ``list_templates``
        commands.

        r   N	templates)r   r   __file__rL   rM   r    )r3   r   package_dirs      r4   get_template_directoryzConfig.get_template_directory  s?     	7+,,5577>;,---r6   r   c                D    t          |                                           S )zReturn the directory where Alembic setup templates are found.

        This method is used by the alembic ``init`` and ``list_templates``
        commands.

        .. versionadded:: 1.16.0

        )r   rd   r;   s    r4   _get_template_pathzConfig._get_template_path  s     D//11222r6   .namedefaultOptional[Dict[str, str]]c                    d S r:   rA   r3   rg   rh   s      r4   get_sectionzConfig.get_section(  s	     $'3r6   Dict[str, str]c                    d S r:   rA   rk   s      r4   rl   zConfig.get_section0  s	     r6   Mapping[str, str](Union[Dict[str, str], Mapping[str, str]]c                    d S r:   rA   rk   s      r4   rl   zConfig.get_section5  s	     473r6   Optional[Mapping[str, str]]c                    | j                             |          s|S t          | j                             |                    S )zReturn all the configuration options from a given .ini file section
        as a dictionary.

        If the given section does not exist, the value of ``default``
        is returned, which is expected to be a dictionary or other mapping.

        )rQ   has_sectionr0   itemsrk   s      r4   rl   zConfig.get_section:  sA     ++D11 	ND$**400111r6   valuec                >    |                      | j        ||           dS )a:  Set an option programmatically within the 'main' section.

        This overrides whatever was in the .ini file.

        :param name: name of the value

        :param value: the value.  Note that this value is passed to
         ``ConfigParser.set``, which supports variable interpolation using
         pyformat (e.g. ``%(some_value)s``).   A raw percent sign not part of
         an interpolation symbol must therefore be escaped, e.g. ``%%``.
         The given value may refer to another value already in the file
         using the interpolation format.

        N)set_section_optionr/   r3   rg   rv   s      r4   set_main_optionzConfig.set_main_optionI  s%     	 7uEEEEEr6   c                F    | j                             | j        |           d S r:   )rQ   remove_optionr/   )r3   rg   s     r4   remove_main_optionzConfig.remove_main_optionZ  s$    &&t'>EEEEEr6   sectionc                    | j                             |          s| j                             |           | j                             |||           dS )aW  Set an option programmatically within the given section.

        The section is created if it doesn't exist already.
        The value here will override whatever was in the .ini
        file.

        Does **NOT** consume from the pyproject.toml file.

        .. seealso::

            :meth:`.Config.get_alembic_option` - includes pyproject support

        :param section: name of the section

        :param name: name of the value

        :param value: the value.  Note that this value is passed to
         ``ConfigParser.set``, which supports variable interpolation using
         pyformat (e.g. ``%(some_value)s``).   A raw percent sign not part of
         an interpolation symbol must therefore be escaped, e.g. ``%%``.
         The given value may refer to another value already in the file
         using the interpolation format.

        N)rQ   rt   rP   set)r3   r~   rg   rv   s       r4   rx   zConfig.set_section_option]  sU    4 ++G44 	2((111WdE22222r6   c                    | j                             |          s t          j        d| j        d|d          | j                             ||          r| j                             ||          S |S )z9Return an option from the given section of the .ini file.zNo config file z found, or file has no '[z
]' section)rQ   rt   r   r[   r-   
has_optionrY   )r3   r~   rg   rh   s       r4   get_section_optionzConfig.get_section_option{  s     ++G44 	##$($9$9$9777D   &&w55 	#''666Nr6   c                    d S r:   rA   rk   s      r4   get_main_optionzConfig.get_main_option  s    ?Bsr6   c                    d S r:   rA   rk   s      r4   r   zConfig.get_main_option  	     r6   c                :    |                      | j        ||          S )a  Return an option from the 'main' section of the .ini file.

        This defaults to being a key from the ``[alembic]``
        section, unless the ``-n/--name`` flag were used to
        indicate a different section.

        Does **NOT** consume from the pyproject.toml file.

        .. seealso::

            :meth:`.Config.get_alembic_option` - includes pyproject support

        )r   r/   rk   s      r4   r   zConfig.get_main_option  s      &&t'>gNNNr6   c                    d S r:   rA   rk   s      r4   get_alembic_optionzConfig.get_alembic_option  s    BE#r6   c                    d S r:   rA   rk   s      r4   r   zConfig.get_alembic_option  r   r6   FUnion[None, str, list[str], dict[str, str], list[dict[str, str]], int]c                    | j                             | j        |          r | j                             | j        |          S |                     ||          S )a  Return an option from the "[alembic]" or "[tool.alembic]" section
        of the configparser-parsed .ini file (e.g. ``alembic.ini``) or
        toml-parsed ``pyproject.toml`` file.

        The value returned is expected to be None, string, list of strings,
        or dictionary of strings.   Within each type of string value, the
        ``%(here)s`` token is substituted out with the absolute path of the
        ``pyproject.toml`` file, as are other tokens which are extracted from
        the :paramref:`.Config.config_args` dictionary.

        Searches always prioritize the configparser namespace first, before
        searching in the toml namespace.

        If Alembic was run using the ``-n/--name`` flag to indicate an
        alternate main section name, this is taken into account **only** for
        the configparser-parsed .ini file.  The section name in toml is always
        ``[tool.alembic]``.


        .. versionadded:: 1.16.0

        )rh   )rQ   r   r/   rY   _get_toml_config_valuerk   s      r4   r   zConfig.get_alembic_option  sX    8 &&t'>EE 	F#''(?FFF..tW.EEEr6   boolc                   | j                             | j        |          r$| j                             | j        |          dk    S | j                            |d          }t          |t                    st          j        d|          |S )NtrueFz*boolean value expected for TOML parameter )	rQ   r   r/   rY   r_   rZ   r   r   r[   ry   s      r4   get_alembic_boolean_optionz!Config.get_alembic_boolean_option  s    &&t'>EE 
	 $$T%<dCCvM ,00u==EeT** 'III   Lr6   Optional[Any]c                J    t                      } j                            ||          }||u r|S |t          |t                    r| j        z  }nt          |t                    rI|r*t          |d         t                    r fd|D             }nt          d fd|D                       }nrt          |t                    r/t          d fd|	                                D                       }n.t          |t                    r|S t          j        d|          |S )Nr   c                P    g | ]"}fd |                                 D             #S )c                ,    i | ]\  }}||j         z  S rA   r1   .0kvr3   s      r4   
<dictcomp>z<Config._get_toml_config_value.<locals>.<listcomp>.<dictcomp>  s&    HHHTQA0HHHr6   )ru   )r   dvr3   s     r4   
<listcomp>z1Config._get_toml_config_value.<locals>.<listcomp>  sF        IHHHRXXZZHHH  r6   	list[str]c                $    g | ]}|j         z  S rA   r   )r   r   r3   s     r4   r   z1Config._get_toml_config_value.<locals>.<listcomp>  s     %J%J%Jqa4>&:%J%J%Jr6   zdict[str, str]c                ,    i | ]\  }}||j         z  S rA   r   r   s      r4   r   z1Config._get_toml_config_value.<locals>.<dictcomp>  s&    GGGAQT^,GGGr6   z%unsupported TOML value type for key: )objectr_   rY   rZ   r    r1   listr0   r	   ru   intr   r[   )r3   rg   rh   USE_DEFAULTrv   s   `    r4   r   zConfig._get_toml_config_value  sn   
 hh$(({;; 	 KN%%% 0E4((  Za$77    "'  EE
 !#%J%J%J%JE%J%J%J EE E4(( 
$GGGGGGG  E3'' 'DDDD   r6   MessagingOptionsc                |    t          t          t          j        dt	          | j        dd          i                    S )zThe messaging options.quietF)r	   r   r   immutabledictgetattrr$   r;   s    r4   rG   zConfig.messaging_opts  s?     '$-%@@A 
 
 	
r6   namesc                   |D ]}|                      |          }| nd S ddt          j        ddd}	 ||         }|dk    rt          j        d           |S # t
          $ r}t          d|d	|d
          |d }~ww xY w)N rE   :;)spacenewlineosr   r   version_path_separatorz[The version_path_separator configuration parameter is deprecated; please use path_separator'z' is not a valid value for z-; expected 'space', 'newline', 'os', ':', ';')r   r   pathsepr   warn_deprecatedKeyError
ValueError)r3   r   rg   	separatorsplit_on_pathsepkes          r4   _get_file_separator_charzConfig._get_file_separator_char  s     	 	D,,T22I$ % 4 *
 
		*C ///$?   J  	 	 	* 99ddd$  		s   A 
A>"A99A>Optional[list[str]]c                z   | j                             | j        dd           }|rt|                     dd          }|=t	          j        d           t          j        d          }|                    |          S d |                    |          D             S t          d| 
                    dd                     S )	Nversion_locationsfallbackpath_separatorr   zNo path_separator found in configuration; falling back to legacy splitting on spaces/commas for version_locations.  Consider adding path_separator=os to Alembic config.
, *|(?: +)c                :    g | ]}||                                 S rA   stripr   xs     r4   r   z5Config.get_version_locations_list.<locals>.<listcomp>@  6       GGII  r6   r   rQ   rY   r/   r   r   r   recompilesplitr	   r   )r3   version_locations_str
split_char_split_on_space_commas       r4   get_version_locations_listz!Config.get_version_locations_list(  s     $ 0 4 4#%84 !5 !
 !
 ! 	66 ": J ! $;   )+
=(A(A%,223HIII 288DD    ++,?FF  r6   c                x   | j                             | j        dd           }|rs|                     d          }|=t	          j        d           t          j        d          }|                    |          S d |                    |          D             S t          d| 
                    dd                     S )Nprepend_sys_pathr   r   zNo path_separator found in configuration; falling back to legacy splitting on spaces, commas, and colons for prepend_sys_path.  Consider adding path_separator=os to Alembic config.z, *|(?: +)|\:c                :    g | ]}||                                 S rA   r   r   s     r4   r   z5Config.get_prepend_sys_paths_list.<locals>.<listcomp>`  r   r6   r   r   )r3   prepend_sys_path_strr   _split_on_space_comma_colons       r4   get_prepend_sys_paths_listz!Config.get_prepend_sys_paths_listK  s    #/33#%7$  4  
  
   	667GHHJ! $;   /1j9I.J.J+2889MNNN 177
CC    ++,>EE  r6   list[PostWriteHookConfig]c                   g }| j                             d          sft          d|                     dg                     }|D ]>}t	          |          }|                    d          |d<   |                    |           ?nt          j        d          }| 	                    di           |
                                        dd                    }|D ].sfdD             }|d<   |                    |           /|S )	Npost_write_hookszlist[dict[str, str]]rg   
_hook_namer   hooks c                    i | ];}|                     d z             |t                    dz   d         |         <S ).r   N)
startswithlen)r   keyini_hook_configrg   s     r4   r   z)Config.get_hooks_list.<locals>.<dictcomp>  sY       ~~dSj11D		A(/#*>  r6   )rQ   rt   r	   r   r0   popappendr   r   rl   r   rY   )	r3   r   toml_hook_configcfgoptsr   r   r   rg   s	          @@r4   get_hooks_listzConfig.get_hooks_listk  sU   +-++,>?? 	##&++,>CC    ( # #Cyy%)XXf%5%5\"T""""# %'J}$=$=!"../A2FFO)//##GR00 E  
# 
#     .   &*\"T""""r6   )r   r   r   r   r   r    r!   r"   r#   r   r$   r%   r&   r'   r(   r)   r*   r+   )r*   r8   )r*   r?   )rB   r    rC   r   r*   r+   )r*   r   )r*   r'   )r*   r    )r*   r   ).)rg   r    rh   r+   r*   ri   )rg   r    rh   rm   r*   rm   )rg   r    rh   ro   r*   rp   r:   )rg   r    rh   rr   r*   rr   )rg   r    rv   r    r*   r+   )rg   r    r*   r+   )r~   r    rg   r    rv   r    r*   r+   )r~   r    rg   r    rh   r7   r*   r7   )rg   r    rh   r    r*   r    )rg   r    rh   r7   r*   r7   )rg   r    rh   r7   r*   r   )rg   r    r*   r   )rg   r    rh   r   r*   r   )r*   r   )r   r    r*   r7   )r*   r   )r*   r   )'__name__
__module____qualname____doc__sysr#   r   r   r5   r$   __annotations__r-   r.   propertyr<   r>   r/   memoized_propertyr(   rI   rQ   r_   rd   rf   r   rl   rz   r}   rx   r   r   r   r   r   rG   r   r   r   r   rA   r6   r4   r   r      s        T Tp 598<$*.(,););)=)=/3/ / / / /6 %)H((((	 '+****2$(N(((( + + + X+
 ) ) ) X)
 #"""" 
   &O O O O. 
   , 
   &
. 
. 
. 
.	3 	3 	3 	3 ),' ' ' ' X'    X 7 7 7 X7
 AE2 2 2 2 2F F F F"F F F F3 3 3 3> AE     BBB XB26    X
 37O O O O O$ EEE XE26    X
 37F F F F FB    37# # # # #J 

 
 
 
   @! ! ! !F   @! ! ! ! ! !r6   r   c                      e Zd ZU ded<   dS )r   r   r   N)r   r   r   r   rA   r6   r4   r   r     s         KKKKKr6   r   F)totalc                  &    e Zd ZU dZded<   dd
ZdS )CommandFunctionzA function that may be registered in the CLI as an alembic command.
    It must be a named function and it must accept a :class:`.Config` object
    as the first argument.

    .. versionadded:: 1.15.3

    r    r   configr   argsr   kwargsr*   c                    d S r:   rA   )r3   r   r   r   s       r4   __call__zCommandFunction.__call__  s      r6   N)r   r   r   r   r   r   r*   r   )r   r   r   r   r   r   rA   r6   r4   r   r     s3           MMMMMMMMMr6   r   c            	         e Zd ZU dZdfdgdZi dd	d
 eded          fddd eed          fdd edd          fdd eed          fdd eed          fdd edd           fd!d" ed#d$          fd%d& eed'          fd(d) eed*          fd+d, eed-          fd.d/d0 edd1          fd2d3 edd4          fd5d6 edd7          fd8d9d: ed;d<          fd=d>d? edd@          fdAdB eddC          fdDdE eddF          fdGdHdI eddJ          fiZ edKL           edML           edNdOP          dQZe	j
        dRdSiiZdTedU<   dgdVZdhdYZdid[Zdjd`ZdkdbZdfdldeZdS )mCommandLinez/Provides the command line interface to Alembic.Nprogr7   r*   r+   c                0    |                      |           d S r:   )_generate_args)r3   r   s     r4   r5   zCommandLine.__init__  s    D!!!!!r6   templatez-tz
--templategenericz"Setup template for use with 'init')rh   typehelpmessagez-mz	--messagez%Message string to use with 'revision')r  r  sqlz--sql
store_truez\Don't emit SQL to database - dump to standard output/file instead. See docs on offline mode.actionr  tagz--tagz<Arbitrary 'tag' name - can be used by custom env.py scripts.headz--headzCSpecify head revision or <branchname>@head to base new revision on.splicez--splicez6Allow a non-head revision as the 'head' to splice onto
depends_onz--depends-onr   zNSpecify one or more revision identifiers which this revision should depend on.rev_idz--rev-idz9Specify a hardcoded revision id instead of generating oneversion_pathz--version-pathz2Specify specific path from config for version filebranch_labelz--branch-labelz3Specify a branch label to apply to the new revisionverbosez-vz	--verbosezUse more verbose outputresolve_dependenciesz--resolve-dependenciesz+Treat dependency versions as down revisionsautogeneratez--autogeneratezgPopulate revision script with candidate migration operations, based on comparison of database to model.	rev_rangez-rz--rev-rangestorez1Specify a revision range; format is [start]:[end]indicate_currentz-iz--indicate-currentzIndicate the current revisionpurgez--purgez7Unconditionally erase the version table before stampingpackagez	--packagezFWrite empty __init__.py files to the environment and version locationscheck_heads-cz--check-headsziCheck if all head revisions are applied to the database. Exit with an error code if this is not the case.zlocation of scripts directoryr  zrevision identifier+z/one or more revisions, or 'heads' for all heads)nargsr  )	directoryrevision	revisionsr  r   zdict[Any, dict[str, str]]_POSITIONAL_TRANSLATIONSc                ,   t          |          }|                    dddt          z             |                    dddd	
           |                    ddt          dd           |                    ddd
           |                    ddd
           |                    dddd
           |                                | _        d d t          t                    D             D             }|D ]}|                     |           || _	        d S )Nr   z	--versionversionz%%(prog)s %s)r	  r$  r  z--configr   zAlternate config file; defaults to value of ALEMBIC_CONFIG environment variable, or "alembic.ini". May also refer to pyproject.toml file.  May be specified twice to reference both files separatelyr  z-nz--namer   zfName of section in .ini file to use for Alembic config (only applies to configparser config, not toml))r  rh   r  z-xzlAdditional arguments consumed by custom env.py scripts, e.g. -x setting1=somesetting -x setting2=somesettingz
--raiseerrr  z!Raise a full stack trace on errorz-qz--quietzDo not log to std output.c              3     K   | ]I}t          j        |          r3|j        d          dk    r"|j        dk    2t	          t
          |          V  JdS )r   _zalembic.commandN)inspect
isfunctionr   r   r	   r   )r   fns     r4   	<genexpr>z-CommandLine._generate_args.<locals>.<genexpr>p  sn       
 
"2&&	

 KNc))M%666 "%%
 7666
 
r6   c              3  @   K   | ]}t          t          |          V  d S r:   )r   r   )r   rg   s     r4   r*  z-CommandLine._generate_args.<locals>.<genexpr>r  s,      GG$ww--GGGGGGr6   )
r   add_argumentr   r    add_subparsers
subparsersdirr   register_commandparser)r3   r   r1  alembic_commandsr)  s        r4   r   zCommandLine._generate_argsE  s   T***	>K3O 	 	
 	
 	
 	1	 	 	
 	
 	
 	> 	 	
 	
 	
 	; 	 	
 	
 	
 	4 	 	
 	
 	

 	,	 	 	
 	
 	
 !//11
 
GG#g,,GGG
 
 
 # 	& 	&B!!"%%%%r6   r)  r   c                |   |                      |          \  }}}| j                            |j        |          }|                    |||f           |D ]7}|| j        v r,| j        |         }|dd         |d         }	} |j        |i |	 8|D ]+}| j                            |i           }	 |j        |fi |	 ,dS )a-  Registers a function as a CLI subcommand. The subcommand name
        matches the function name, the arguments are extracted from the
        signature and the help text is read from the docstring.

        .. versionadded:: 1.15.3

        .. seealso::

            :ref:`custom_commandline`
        r  )cmdr   N)	_inspect_functionr.  
add_parserr   set_defaults_KWARGS_OPTSr,  _POSITIONAL_OPTSrY   )
r3   r)  
positionalkwarg	help_text	subparserrC   	kwarg_optr   r   s
             r4   r0  zCommandLine.register_command  s     (,'='=b'A'A$
E9O..r{.KK	B
E#:;;; 	6 	6Cd''' -c2	&qt_imd&	&5555 	0 	0C(,,S"55D"I"3//$////	0 	0r6   tuple[Any, Any, str]c                    t          j                  }|d         I|d         dt          |d                             }|d         t          |d                    d          }n|d         dd          }g } j        v r fd|D             }j        }|rXg }|                    d          D ]?}|                                s n(|                    |                                           @ng }d                    |          }|||fS )N   r   r   c                R    g | ]#}j                                      ||          $S rA   )r!  rY   )r   rg   r)  r3   s     r4   r   z1CommandLine._inspect_function.<locals>.<listcomp>  sA        -b155dDAA  r6   rE   r   )	r   inspect_getfullargspecr   r!  r   r   r   r   join)	r3   r)  specr;  r<  help_
help_linesliner=  s	   ``       r4   r6  zCommandLine._inspect_function  s7   ,R007ac$q'll]!23JGSa\\MOO,EEaJE...    &  J 
 	JD)) 4 4zz|| 4E%%djjll3333JHHZ((	5)++r6   r   r   optionsr   c                    j         \  }}}	  ||gfd|D             R i fd|D              d S # t          j        $ r7}j        r t          j        t          |          fi |j         Y d }~d S d }~ww xY w)Nc                2    g | ]}t          |d           S r:   r   r   r   rJ  s     r4   r   z'CommandLine.run_cmd.<locals>.<listcomp>  s%    @@@''1d++@@@r6   c                4    i | ]}|t          |d           S r:   rM  rN  s     r4   r   z'CommandLine.run_cmd.<locals>.<dictcomp>  s'    ???A1ggq$//???r6   )r4  r   r[   raiseerrerrr    rG   )r3   r   rJ  r)  r;  r<  es     `    r4   run_cmdzCommandLine.run_cmd  s     'J
	:B@@@@Z@@@   @??????    
   	: 	: 	: :Q996#8999999999		:s   $4 A:,A55A:tuple[str, str]c                   |j         }t          j                            d          }|r(t          j                            |          dk    r|}d}n|rd}|}nd}d}|s||fS d x}}|D ]V}t          j                            |          dk    r|t          j        d          |}>|t          j        d          |}W|r|n||r|n|fS )NALEMBIC_CONFIGzpyproject.tomlzalembic.iniz'pyproject.toml indicated more than oncez"only one ini file may be indicated)r   r   environrY   pathbasenamer   r[   )	r3   rJ  r   alembic_config_envdefault_pyproject_tomldefault_alembic_configtomlinirg   s	            r4   _inis_from_configzCommandLine._inis_from_config  s0   Z^^,<==	6  !3448HHH%7"%2"" 	6%5"%7""%2"%5" 	B)+AAAs 	 	Dw%%)999#+A   ?+<   7tt!72CC2
 	
r6   argvOptional[Sequence[str]]c                   | j                             |          }t          |d          s| j                             d           dS |                     |          \  }}t          |||j        |          }|                     ||           dS )z6Executes the command line with the provided arguments.r4  ztoo few arguments)r   r   r   r$   N)r1  
parse_argshasattrerrorr_  r   rg   rS  )r3   r`  rJ  r]  r^  r   s         r4   mainzCommandLine.main  s    +((..w&& 	' K122222..w77ID##L 	  C LLg&&&&&r6   r:   )r   r7   r*   r+   )r)  r   r*   r+   )r)  r   r*   r@  )r   r   rJ  r   r*   r+   )rJ  r   r*   rT  )r`  ra  r*   r+   )r   r   r   r   r5   r0   r    r9  r:  r   stampr!  r   r   r0  r6  rS  r_  rf  rA   r6   r4   r   r     s        99" " " " "LD!9  
L 	Dc GHHH
L 	D#   
L0 	D)  
1L@ 	D+  
ALP 	D#M  
QL^ 	D8  
_Ln 	D!  
oL~ 	DI  
LL 	DJ  
MLZ 	D+DEEE
[Ld 	$D#B  !
eLr 	D#(  
sLD 	DH  
ELT 	 D#4  
ULd 	D#N  
eLr 	D#4  
sLB 	D#G  

CL LL\ T>???D&
 
 
 TB
 
 
	 	 	
K0;    8 8 8 8t0 0 0 06, , , ,>: : : :&
 &
 &
 &
P' ' ' ' ' ' 'r6   r   r`  ra  r   r7   r   r   r*   r+   c                N    t          |                              |            dS )z(The console runner function for Alembic.r#  )r`  N)r   rf  )r`  r   r   s      r4   rf  rf    s,     TT*****r6   __main__)NN)r`  ra  r   r7   r   r   r*   r+   ))
__future__r   argparser   r   configparserr   r'  r   pathlibr   r   r   typingr   r	   r
   r   r   r   r   r   r   r   typing_extensionsr   r   r   r   r   r   util.pyfilesr   r   r    PostWriteHookConfigr   r   r   rf  r   rA   r6   r4   <module>rr     s   " " " " " " # # # # # #       % % % % % %  				       				 



                                                             ' ' ' ' ' '                         1 1 1 1 1 1m	 m	 m	 m	 m	 m	 m	 m	` c3h'     y    N N N N Nh N N N[' [' [' [' [' [' [' ['~
 %)+ + + + + zDFFFFF r6   