o
    hV                     @  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re  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+   b/var/www/html/construction_image-detection-poc/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 )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   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 )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(   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 )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'   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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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 qd 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      >  

