o
    hU                     @  s4  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 G dd dZG dd deddZG dd dZdddZedkre  dS dS )     )annotations)ArgumentParser)	Namespace)ConfigParserN)Any)cast)Dict)Mapping)Optional)overload)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ZdZ	de
d< 	 dZde
d< 	 dZde
d< 	 ejdd ZdAddZejdd ZdBdd Ze	!dCdDd%d&ZedEd(d&ZedFd+d&Z	dGdHd-d&ZdId/d0ZdJd1d2ZdKd4d5Z	dGdLd7d8ZedMd9d:Ze	dGdNd;d:ZdGd<d:ZejdOd>d?ZdS )P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alembicfile_"Union[str, os.PathLike[str], None]ini_sectionstroutput_bufferOptional[TextIO]stdoutr   cmd_optsOptional[Namespace]config_argsMapping[str, Any]
attributesOptional[dict]returnNonec                 C  s@   || _ || _|| _|| _|| _t|| _|r| j| dS 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*   Q/var/www/html/aiguide_backend/venv/lib/python3.10/site-packages/alembic/config.py__init__c   s   
zConfig.__init__r%   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.attributestextc                 G  s8   |r	t || }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)r)   r.   argoutputr*   r*   r+   print_stdout   s   zConfig.print_stdoutc                 C  s`   | j rtjtj| j }nd}|| jd< t| j}| j r(t|| j g |S |	| 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   read_config_parseradd_sectionr&   )r)   r6   file_configr*   r*   r+   r=      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   N	templates)r   r7   r8   r9   r:   __file__join)r)   r   package_dirr*   r*   r+   get_template_directory   s   zConfig.get_template_directory.namedefaultOptional[Dict[str, str]]c                 C     d S Nr*   r)   rC   rD   r*   r*   r+   get_section      zConfig.get_sectionDict[str, str]c                 C  rF   rG   r*   rH   r*   r*   r+   rI      rJ   Mapping[str, str](Union[Dict[str, str], Mapping[str, str]]c                 C  rF   rG   r*   rH   r*   r*   r+   rI      rJ   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.

        )r=   has_sectionr'   itemsrH   r*   r*   r+   rI      s   
valuec                 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)   rC   rQ   r*   r*   r+   set_main_option   s   zConfig.set_main_optionc                 C  s   | j | j| d S rG   )r=   remove_optionr&   )r)   rC   r*   r*   r+   remove_main_option  s   zConfig.remove_main_optionsectionc                 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)r=   rO   r<   set)r)   rV   rC   rQ   r*   r*   r+   rR     s   zConfig.set_section_optionOptional[str]c                 C  s@   | j |std| j|f | j ||r| j ||S |S )z9Return an option from the given section of the .ini file.z6No config file %r found, or file has no '[%s]' section)r=   rO   r   CommandErrorr%   
has_optionget)r)   rV   rC   rD   r*   r*   r+   get_section_option,  s   zConfig.get_section_optionc                 C  rF   rG   r*   rH   r*   r*   r+   get_main_option:  s   zConfig.get_main_optionc                 C  rF   rG   r*   rH   r*   r*   r+   r]   >  rJ   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.

        )r\   r&   rH   r*   r*   r+   r]   D  s   MessagingOptionsc              	   C  s   t ttdt| jddiS )zThe messaging options.quietF)r   r^   r   immutabledictgetattrr   r-   r*   r*   r+   r1   N  s   zConfig.messaging_opts)r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   )r.   r   r#   r$   )r#   r   ).)rC   r   rD   r$   r#   rE   )rC   r   rD   rK   r#   rK   )rC   r   rD   rL   r#   rM   rG   )rC   r   rD   rN   r#   rN   )rC   r   rQ   r   r#   r$   )rC   r   r#   r$   )rV   r   rC   r   rQ   r   r#   r$   )rV   r   rC   r   rD   rX   r#   rX   )rC   r   rD   r   r#   r   )rC   r   rD   rX   r#   rX   )r#   r^   )__name__
__module____qualname____doc__sysr   r   r`   r,   r   __annotations__r%   r&   memoized_propertyr!   r4   r=   rB   r   rI   rS   rU   rR   r\   r]   r1   r*   r*   r*   r+   r      sX   
 J








r   c                   @  s   e Zd ZU ded< dS )r^   boolr_   N)rb   rc   rd   rg   r*   r*   r*   r+   r^   Y  s   
 r^   F)totalc                   @  s6   e Zd ZddddZddd	ZdddZdddZdS )CommandLineNprogrX   r#   r$   c                 C  s   |  | d S rG   )_generate_args)r)   rl   r*   r*   r+   r,   ^  s   zCommandLine.__init__c                   s  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 ur|d  d$t|d#   }|d  t|d#  d  }n
|d  d$d  }g } v r fd%d|D } j}|rg }	|d&D ]}
|
 s n|	|
  qng }	|j jd'|	d(| || j ||fd) q\|| _d S )*Nc           	   	     s  i dddt dtddfddd	t td
dfddt dddfddt tddfddt tddfddt dddfddt dddfddt td dfd!d"t td#dfd$d%t td&dfd'd(d)t dd*dfd+d,t dd-dfd.d/t dd0dfd1d2d3t d4d5dfd6d7d8t dd9dfd:d;t dd<dfd=d>t dd?df}d@dAdBdC}|D ]}||v r|| }|dDdE |dE }}|j|i | q|D ](}|dFks|  v r |  | dFkrjdFdG|dFdH qɈj|||dI qd S )JNtemplatez-tz
--templategenericz"Setup template for use with 'init')rD   typehelpmessagez-mz	--messagez%Message string to use with 'revision')rp   rq   sqlz--sql
store_truez\Don't emit SQL to database - dump to standard output/file instead. See docs on offline mode.actionrq   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-onappendzNSpecify 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 locationszlocation of scripts directoryzrevision identifierz/one or more revisions, or 'heads' for all heads)	directoryrevision	revisionsr   r   +)nargsrq   rq   )r'   r   add_argumentr[   )	fnparser
positionalkwargskwargs_optspositional_helpr2   argskw)positional_translations	subparserr*   r+   add_optionsb  sF  
"*2:BJR
W^gpx   z/CommandLine._generate_args.<locals>.add_optionsrl   z	--versionversionz%%(prog)s %s)rv   r   z-cz--configALEMBIC_CONFIGzalembic.inizaAlternate config file; defaults to value of ALEMBIC_CONFIG environment variable, or "alembic.ini")rp   rD   rq   z-nz--namer   z6Name of section in .ini file to use for Alembic configz-xr{   zlAdditional arguments consumed by custom env.py scripts, e.g. -x setting1=somesetting -x setting2=somesettingru   z
--raiseerrrt   z!Raise a full stack trace on errorz-qz--quietzDo not log to std output.r   r   c                 S  s   g | ]}t t|qS r*   )ra   r   ).0nr*   r*   r+   
<listcomp>/  s    z.CommandLine._generate_args.<locals>.<listcomp>r   _zalembic.command   r   c                   s   g | ]
}   ||qS r*   )r[   )r   rC   )r   r   r*   r+   r   >  s    r/    r   )cmd)r   r   r   r   r7   environr[   add_subparsersr   stampdirinspect
isfunctionrb   rc   r   inspect_getfullargspeclenre   splitstripr{   
add_parserr@   set_defaultsr   )r)   rl   r   r   
subparsersspecr   kwarghelp_	help_textliner*   )r   r   r   r+   rm   a  s    
$



zCommandLine._generate_argsconfigr   optionsr   c              
     s    j \}}}z||g fdd|D R i  fdd|D  W d S  tjyF } z jr/ tjt|fi |j W Y d }~d S d }~ww )Nc                   s   g | ]}t  |d qS rG   ra   r   kr   r*   r+   r   [  s    z'CommandLine.run_cmd.<locals>.<listcomp>c                   s   i | ]	}|t  |d qS rG   r   r   r   r*   r+   
<dictcomp>\  s    z'CommandLine.run_cmd.<locals>.<dictcomp>)r   r   rY   raiseerrerrr   r1   )r)   r   r   r   r   r   er*   r   r+   run_cmdU  s   &zCommandLine.run_cmdc                 C  sH   | j |}t|ds| j d d S t|j|j|d}| || d S )Nr   ztoo few arguments)r   r   r   )r   
parse_argshasattrerrorr   r   rC   r   )r)   argvr   cfgr*   r*   r+   maind  s   
zCommandLine.mainrG   )rl   rX   r#   r$   )r   r   r   r   r#   r$   )rb   rc   rd   r,   rm   r   r   r*   r*   r*   r+   rk   ]  s    
 
urk   c                 K  s   t |dj| d dS )z(The console runner function for Alembic.r   )r   N)rk   r   )r   rl   r   r*   r*   r+   r   s  s   r   __main__)NN)
__future__r   argparser   r   configparserr   r   r7   rf   typingr   r   r   r	   r
   r   r   r   typing_extensionsr   r5   r   r   r   r   r   r^   rk   r   rb   r*   r*   r*   r+   <module>   s>      A  

