o
    ‹ågÈV  ã                   @  sF  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&„Zed'kr¡eƒ  dS dS )*é    )Úannotations)ÚArgumentParser)Ú	Namespace)ÚConfigParserN)ÚAny)Úcast)ÚDict)ÚMapping)ÚOptional)Úoverload)ÚSequence)ÚTextIO)ÚUnion)Ú	TypedDicté   )Ú__version__)Úcommand)Úutil)Úcompatc                   @  s6  e Zd ZU dZdddejde ¡ dfdDdd„ZdZ	de
d< 	 dZde
d< 	 dZde
d< 	 ejdEdd„ƒZdFdd„ZejdGd!d"„ƒZdHd#d$„Ze	%dIdJd)d*„ƒZedKd,d*„ƒZedLd/d*„ƒZ	dMdNd1d*„ZdOd3d4„ZdPd5d6„ZdQd8d9„Z	dMdRd;d<„ZedSd=d>„ƒZe	dMdTd?d>„ƒZ	dMdTd@d>„ZejdUdBdC„ƒZdS )VÚ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[str, Any]]Ú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+   úJ/var/www/html/flaskapp/venv/lib/python3.10/site-packages/alembic/config.pyÚ__init__d   s   
ÿzConfig.__init__r&   r'   úDict[str, Any]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ÚtextÚargr   c                 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*   r0   r1   Ú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 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*   r8   Úfile_configr+   r+   r,   r?   º   s   

ÿzConfig.file_configc                 C  s,   ddl }tj tj |j¡¡}tj |d¡S )z¥Return the directory where Alembic setup templates are found.

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

        r   NÚ	templates)r   r9   r:   r;   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*   rE   rF   r+   r+   r,   Úget_sectionÝ   ó   zConfig.get_sectionúDict[str, str]c                 C  rH   rI   r+   rJ   r+   r+   r,   rK   å   rL   úMapping[str, str]ú(Union[Dict[str, str], Mapping[str, str]]c                 C  rH   rI   r+   rJ   r+   r+   r,   rK   ê   rL   úOptional[Mapping[str, str]]c                 C  s    | j  |¡s|S t| j  |¡ƒS )zùReturn 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(   ÚitemsrJ   r+   r+   r,   rK   ï   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*   rE   rS   r+   r+   r,   Úset_main_optionþ   s   zConfig.set_main_optionc                 C  s   | j  | j|¡ d S rI   )r?   Úremove_optionr'   )r*   rE   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?   rQ   r>   Úset)r*   rX   rE   rS   r+   r+   r,   rT     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?   rQ   r   ÚCommandErrorr&   Ú
has_optionÚget)r*   rX   rE   rF   r+   r+   r,   Úget_section_option*  s   ÿÿzConfig.get_section_optionc                 C  rH   rI   r+   rJ   r+   r+   r,   Úget_main_option8  s   zConfig.get_main_optionc                 C  rH   rI   r+   rJ   r+   r+   r,   r_   ;  rL   c                 C  s   |   | j||¡S )zã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.

        )r^   r'   rJ   r+   r+   r,   r_   @  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,   r4   L  s   ÿþzConfig.messaging_opts)r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   )r$   r.   )r0   r   r1   r   r$   r%   )r$   r   )r$   r   ).)rE   r   rF   r%   r$   rG   )rE   r   rF   rM   r$   rM   )rE   r   rF   rN   r$   rO   rI   )rE   r   rF   rP   r$   rP   )rE   r   rS   r   r$   r%   )rE   r   r$   r%   )rX   r   rE   r   rS   r   r$   r%   )rX   r   rE   r   rF   rZ   r$   rZ   )rE   r   rF   r   r$   r   )rE   r   rF   rZ   r$   rZ   )r$   r`   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úsysr   r   rb   r-   r   Ú__annotations__r&   r'   Úmemoized_propertyr"   r6   r?   rD   r   rK   rU   rW   rT   r^   r_   r4   r+   r+   r+   r,   r      sZ   
 Jø

ÿÿ


ÿÿÿr   c                   @  s   e Zd ZU ded< dS )r`   Úboolra   N)rd   re   rf   ri   r+   r+   r+   r,   r`   W  s   
 r`   F)Útotalc                   @  s8   e Zd Zdddd„Zddd	„Zddd„Zdddd„ZdS )ÚCommandLineNÚprogrZ   r$   r%   c                 C  s   |   |¡ d S rI   )Ú_generate_args)r*   rn   r+   r+   r,   r-   \  s   zCommandLine.__init__c                   sÜ  d1‡‡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rèt ˆ ¡}|d* d ur–|d' d+t|d* ƒ … }|d' t|d* ƒ d … }n
|d' d+d … }g }ˆ ˆv r®‡ ‡fd,d&„|D ƒ}ˆ j}|rËg }	| d-¡D ]}
|
 ¡ sÂ n|	 |
 ¡ ¡ qºng }	|jˆ jd. |	¡d/�‰|ˆ ˆ||ƒ ˆjˆ ||fd0� q]|| _d S )2NÚfnr   ÚparserÚ
positionalÚkwargsr$   r%   c           	   	     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� qÉd S )JNÚtemplatez-tz
--templateÚgenericz"Setup template for use with 'init')rF   ÚtypeÚhelpÚmessagez-mz	--messagez%Message string to use with 'revision')rv   rw   Úsqlz--sqlÚ
store_truez\Don't emit SQL to database - dump to standard output/file instead. See docs on offline mode.©Úactionrw   Ú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�   ú+)Únargsrw   ©rw   )r(   r   Úadd_argumentr]   )	rp   rq   rr   rs   Úkwargs_optsÚpositional_helpr1   ÚargsÚkw)Úpositional_translationsÚ	subparserr+   r,   Úadd_options`  sF  ýýÿ
ÿýöþþïþþæ"þþÞ*þþÖ2þþÎ:þþÆBþþ¾Jþþ¶R
ý®Wþþ©^þþ¢gþý™pþý�xþþˆ þþ �ÿ ý€ýôz/CommandLine._generate_args.<locals>.add_options©rn   z	--versionÚversionz%%(prog)s %s)r|   r�   z-cz--configÚALEMBIC_CONFIGzalembic.inizaAlternate config file; defaults to value of ALEMBIC_CONFIG environment variable, or "alembic.ini")rv   rF   rw   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=somesettingr{   z
--raiseerrrz   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+   )rc   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+   )r]   )rŸ   rE   )rp   r™   r+   r,   r¡   @  s    ÿÿr2   ú r“   )Úcmd)
rp   r   rq   r   rr   r   rs   r   r$   r%   )r   r”   r   r   r9   Úenvironr]   Úadd_subparsersr   ÚstampÚdirÚinspectÚ
isfunctionrd   re   r   Úinspect_getfullargspecÚlenrg   ÚsplitÚstripr�   Ú
add_parserrB   Úset_defaultsrq   )r*   rn   r›   rq   Ú
subparsersÚspecrr   ÚkwargÚhelp_Ú	help_textÚliner+   )rp   r™   rš   r,   ro   _  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 rI   ©rc   ©rŸ   Úk©r¹   r+   r,   r¡   ]  s    z'CommandLine.run_cmd.<locals>.<listcomp>c                   s   i | ]	}|t ˆ |d ƒ“qS rI   rº   r»   r½   r+   r,   Ú
<dictcomp>^  s    z'CommandLine.run_cmd.<locals>.<dictcomp>)r¥   r   r[   ÚraiseerrÚerrr   r4   )r*   r¸   r¹   rp   rr   r´   Úer+   r½   r,   Úrun_cmdW  s   ÿþý&€üzCommandLine.run_cmdÚargvúOptional[Sequence[str]]c                 C  sH   | j  |¡}t|dƒs| j  d¡ d S t|j|j|d�}|  ||¡ d S )Nr¥   ztoo few arguments)r   r   r   )rq   Ú
parse_argsÚhasattrÚerrorr   r¸   rE   rÂ   )r*   rÃ   r¹   Úcfgr+   r+   r,   Úmainf  s   
ýzCommandLine.mainrI   )rn   rZ   r$   r%   )r¸   r   r¹   r   r$   r%   )rÃ   rÄ   r$   r%   )rd   re   rf   r-   ro   rÂ   rÉ   r+   r+   r+   r,   rm   [  s    
 
yrm   rÃ   rÄ   rn   rZ   rs   r   r$   r%   c                 K  s   t |d�j| d� dS )z(The console runner function for Alembic.rœ   )rÃ   N)rm   rÉ   )rÃ   rn   rs   r+   r+   r,   rÉ   u  s   rÉ   Ú__main__)NN)rÃ   rÄ   rn   rZ   rs   r   r$   r%   ) Ú
__future__r   Úargparser   r   Úconfigparserr   rª   r9   rh   Útypingr   r   r   r	   r
   r   r   r   r   Útyping_extensionsr   r7   r   r   r   r   r   r`   rm   rÉ   rd   r+   r+   r+   r,   Ú<module>   sD      >  þ

ÿ