U
    ^g%iV                     @  sJ  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	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 dZG dd deddZG dd dZd%dddd d!d"d#Zed$krFe  dS )&    )annotations)ArgumentParser)	Namespace)ConfigParserN)Any)cast)Dict)Mapping)Optional)overload)Sequence)TextIO)Union)	TypedDict   )__version__)command)util)compatc                
   @  s  e Zd ZU dZdddejde dfdddddd	d
ddddZdZ	de
d< dZde
d< dZde
d< ejddddZddddddZejddddZddddZed?ddd d!d"d#Zedd$d$d!d%d#Zedd&d'd!d(d#Zd@dd)d)d!d*d#Zdddd+d,d-Zddd.d/d0Zddddd1d2d3ZdAddd4d4d5d6d7Zedddd!d8d9ZedBdd4d4d!d:d9ZdCdd4d4d!d;d9Zejd<dd=d>ZdS )D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.
    :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.  The dictionary as given
     is **copied** to a new one, stored locally as the attribute
     ``.config_args``. When the :attr:`.Config.file_config` attribute is
     first invoked, the replacement variable ``here`` will be added to this
     dictionary before the dictionary is passed to ``ConfigParser()``
     to parse the .ini file.

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

     .. seealso::

        :ref:`connection_sharing`

    Nalembicz"Union[str, os.PathLike[str], None]strzOptional[TextIO]r   zOptional[Namespace]zMapping[str, Any]zOptional[Dict[str, Any]]None)file_ini_sectionoutput_bufferstdoutcmd_optsconfig_args
attributesreturnc                 C  s<   || _ || _|| _|| _|| _t|| _|r8| j| dS )z Construct a new :class:`.Config`N)	config_file_nameconfig_ini_sectionr   r   r   dictr   r   update)selfr   r   r   r   r   r   r    r&   M/var/www/html/api-medvista/venv/lib/python3.8/site-packages/alembic/config.py__init__d   s    
zConfig.__init__r   r!   r"   zDict[str, Any])r    c                 C  s   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&   r%   r&   r&   r'   r      s    zConfig.attributesr   )textargr    c                 G  s4   |rt || }nt |}tj| j|df| 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   Zwrite_outstreamr   messaging_opts)r%   r*   r+   outputr&   r&   r'   print_stdout   s    zConfig.print_stdoutr   c                 C  s^   | j rtjtj| j }nd}|| jd< t| j}| j rNt|| j g n|	| j
 |S )a  Return the underlying ``ConfigParser`` object.

        Direct 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!   ospathabspathdirnamer   r   r   Zread_config_parseradd_sectionr"   )r%   r1   file_configr&   r&   r'   r7      s    

zConfig.file_configc                 C  s,   ddl }tjtj|j}tj|dS )zReturn the directory where Alembic setup templates are found.

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

        r   NZ	templates)r   r2   r3   r4   r5   __file__join)r%   r   package_dirr&   r&   r'   get_template_directory   s    zConfig.get_template_directory.zOptional[Dict[str, str]])namedefaultr    c                 C  s   d S Nr&   r%   r<   r=   r&   r&   r'   get_section   s    zConfig.get_sectionzDict[str, str]c                 C  s   d S r>   r&   r?   r&   r&   r'   r@      s    zMapping[str, str]z(Union[Dict[str, str], Mapping[str, str]]c                 C  s   d S r>   r&   r?   r&   r&   r'   r@      s    zOptional[Mapping[str, str]]c                 C  s    | 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.

        )r7   has_sectionr#   itemsr?   r&   r&   r'   r@      s    
)r<   valuer    c                 C  s   |  | 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"   )r%   r<   rC   r&   r&   r'   set_main_option   s    zConfig.set_main_option)r<   r    c                 C  s   | j | j| d S r>   )r7   remove_optionr"   )r%   r<   r&   r&   r'   remove_main_option  s    zConfig.remove_main_option)sectionr<   rC   r    c                 C  s,   | j |s| j | | j ||| dS )a  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.

        :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)r7   rA   r6   set)r%   rH   r<   rC   r&   r&   r'   rD     s    zConfig.set_section_optionOptional[str])rH   r<   r=   r    c                 C  sD   | j |s td| j|f | j ||r<| j ||S |S dS )z9Return an option from the given section of the .ini file.z6No config file %r found, or file has no '[%s]' sectionN)r7   rA   r   CommandErrorr!   
has_optionget)r%   rH   r<   r=   r&   r&   r'   get_section_option*  s    zConfig.get_section_optionc                 C  s   d S r>   r&   r?   r&   r&   r'   get_main_option8  s    zConfig.get_main_optionc                 C  s   d S r>   r&   r?   r&   r&   r'   rO   ;  s    c                 C  s   |  | j||S )zReturn 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.

        )rN   r"   r?   r&   r&   r'   rO   @  s    
MessagingOptionsc              	   C  s   t ttdt| jddiS )zThe messaging options.quietF)r   rP   r   immutabledictgetattrr   r)   r&   r&   r'   r-   L  s    zConfig.messaging_opts).)N)N)N)N)__name__
__module____qualname____doc__sysr   r   rR   r(   r   __annotations__r!   r"   Zmemoized_propertyr   r/   r7   r;   r   r@   rE   rG   rD   rN   rO   r-   r&   r&   r&   r'   r      sR   
J     r   c                   @  s   e Zd ZU ded< dS )rP   boolrQ   N)rT   rU   rV   rY   r&   r&   r&   r'   rP   W  s   
rP   F)totalc                   @  sR   e Zd ZddddddZdddddZd	d
ddddZddddddZdS )CommandLineNrJ   r   )progr    c                 C  s   |  | d S r>   )_generate_args)r%   r]   r&   r&   r'   r(   \  s    zCommandLine.__init__c                   s  ddddddfdd}t |d}|jddd	t d
 |jddttjdddd |jddtddd |jdddd |jdddd |jddddd | }tj	dd iid!d" t
tD D ]$ t rƈ jd# d$krƈ jd%krt }|d& d k	r<|d# d't|d&   }|d# t|d&  d  }n|d# d'd  }g } krn fd(d"|D } j}|rg }	|d)D ]&}
|
 s qn|	|
  qng }	|j jd*|	d+| || j ||fd, q|| _d S )-Nr   r   )fnparser
positionalkwargsr    c           	        s  ddt dtddfddt tdd	fd
t dddfdt tdd	fdt tdd	fdt dddfdt dddfdt tdd	fdt tdd	fdt tdd	fddt dddfd t dd!dfd"t dd#dfd$d%t d&d'dfd(d)t dd*dfd+t dd,dfd-t dd.dfd/}d0d1d2d3}|D ]:}||kr|| }|d4d5 |d5  }}|j|| q|D ]X}|d6ksz|  kr |  | d6krjd6d7|d6d8 nj|||d9 qPd S ):Nz-tz
--templateZgenericz"Setup template for use with 'init')r=   typehelpz-mz	--messagez%Message string to use with 'revision')rc   rd   z--sql
store_truez\Don't emit SQL to database - dump to standard output/file instead. See docs on offline mode.actionrd   z--tagz<Arbitrary 'tag' name - can be used by custom env.py scripts.z--headzCSpecify head revision or <branchname>@head to base new revision on.z--splicez6Allow a non-head revision as the 'head' to splice ontoz--depends-onappendzNSpecify one or more revision identifiers which this revision should depend on.z--rev-idz9Specify a hardcoded revision id instead of generating onez--version-pathz2Specify specific path from config for version filez--branch-labelz3Specify a branch label to apply to the new revisionz-vz	--verbosezUse more verbose outputz--resolve-dependenciesz+Treat dependency versions as down revisionsz--autogeneratezgPopulate revision script with candidate migration operations, based on comparison of database to model.z-rz--rev-rangestorez1Specify a revision range; format is [start]:[end]z-iz--indicate-currentzIndicate the current revisionz--purgez7Unconditionally erase the version table before stampingz	--packagezFWrite empty __init__.py files to the environment and version locations)templatemessagesqltagheadZspliceZ
depends_onZrev_idZversion_pathZbranch_labelverboseZresolve_dependenciesZautogenerateZ	rev_rangeZindicate_currentpurgepackagezlocation of scripts directoryzrevision identifierz/one or more revisions, or 'heads' for all heads)	directoryrevision	revisionsr   rt   +)nargsrd   rd   )r#   r   add_argumentrM   )	r_   r`   ra   rb   Zkwargs_optsZpositional_helpr+   argskw)positional_translations	subparserr&   r'   add_options`  s   
 
							


		 
z/CommandLine._generate_args.<locals>.add_optionsr]   z	--versionversionz%%(prog)s %s)rg   r   z-cz--configZALEMBIC_CONFIGzalembic.inizaAlternate config file; defaults to value of ALEMBIC_CONFIG environment variable, or "alembic.ini")rc   r=   rd   z-nz--namer   z6Name of section in .ini file to use for Alembic configz-xrh   zlAdditional arguments consumed by custom env.py scripts, e.g. -x setting1=somesetting -x setting2=somesettingrf   z
--raiseerrre   z!Raise a full stack trace on errorz-qz--quietzDo not log to std output.rs   rt   c                 S  s   g | ]}t t|qS r&   )rS   r   ).0nr&   r&   r'   
<listcomp>1  s     z.CommandLine._generate_args.<locals>.<listcomp>r   _zalembic.command   r   c                   s   g | ]}   ||qS r&   )rM   )r   r<   )r_   r|   r&   r'   r   @  s   r,    rx   )cmd)r   ry   r   r   r2   environrM   add_subparsersr   Zstampdirinspect
isfunctionrT   rU   r   Zinspect_getfullargspeclenrW   splitstriprh   
add_parserr9   set_defaultsr`   )r%   r]   r~   r`   Z
subparsersspecra   kwarghelp_	help_textliner&   )r_   r|   r}   r'   r^   _  s     &
   


 zCommandLine._generate_argsr   r   )configoptionsr    c              
     s    j \}}}z0||f fdd|D  fdd|D  W nB tjk
r~ } z" jrZ ntjt|f|j W 5 d }~X Y nX d S )Nc                   s   g | ]}t  |d qS r>   rS   r   kr   r&   r'   r   ]  s     z'CommandLine.run_cmd.<locals>.<listcomp>c                   s   i | ]}|t  |d qS r>   r   r   r   r&   r'   
<dictcomp>^  s      z'CommandLine.run_cmd.<locals>.<dictcomp>)r   r   rK   Zraiseerrerrr   r-   )r%   r   r   r_   ra   r   er&   r   r'   run_cmdW  s    zCommandLine.run_cmdOptional[Sequence[str]])argvr    c                 C  sF   | j |}t|ds$| j d nt|j|j|d}| || d S )Nr   ztoo few arguments)r   r   r   )r`   
parse_argshasattrerrorr   r   r<   r   )r%   r   r   cfgr&   r&   r'   mainf  s    
zCommandLine.main)N)N)rT   rU   rV   r(   r^   r   r   r&   r&   r&   r'   r\   [  s
    yr\   r   rJ   r   r   )r   r]   rb   r    c                 K  s   t |dj| d dS )z(The console runner function for Alembic.r   )r   N)r\   r   )r   r]   rb   r&   r&   r'   r   u  s    r   __main__)NN) 
__future__r   argparser   r   configparserr   r   r2   rX   typingr   r   r   r	   r
   r   r   r   r   Ztyping_extensionsr   r0   r   r   r   r   r   rP   r\   r   rT   r&   r&   r&   r'   <module>   s@     >    

