o
    ‹åg±“  ã                   @  s(  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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 ddlmZ ddlmZ er¸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' zej(rÉd dl)m*Z* d d l)m+Z+ nd dl,m*Z* d d l,m+Z+ W n e-yá   dZ*Y nw e .d!¡Z/e .d"¡Z0e .d#¡Z1e .d$¡Z2d%Z3e .d&¡Z4e .d'¡Z5G d(d)„ d)ƒZ6G d*d+„ d+ej!ƒZ7dS ),é    )Úannotations)ÚcontextmanagerN)Ú
ModuleType)ÚAny)Úcast)ÚIterator)ÚList)ÚMapping)ÚOptional)ÚSequence)ÚSet)ÚTuple)ÚTYPE_CHECKING)ÚUnioné   ©Úrevision)Úwrite_hooksé   )Úutil)Ú	migration)Úcompat)Únot_none)Ú
_GetRevArg)Ú
_RevIdType)ÚRevision)ÚConfig)ÚMessagingOptions)ÚRevisionStep)Ú	StampStep)ÚZoneInfo)ÚZoneInfoNotFoundErrorz (?!\.\#|__init__)(.*\.py)(c|o)?$z(?!\.\#|__init__)(.*\.py)$z([a-f0-9]+)\.py$z\w+z%(rev)s_%(slug)sz
, *|(?: +)z, *|(?: +)|\:c                   @  sl  e Zd ZdZedddddddedejƒf	d~dd„Ze	ddd„ƒZ
ejd€dd„ƒZd�d!d"„Zed‚d%d&„ƒZe					dƒd„d-d.„ƒZ	0d…d†d2d3„Zd‡d7d8„Zdˆd;d<„Zd‰d>d?„ZdŠdAdB„Zd‹dHdI„ZdŒdJdK„Zd�dMdN„ZdŒdOdP„Zd�dQdR„ZdŽdVdW„Zd�dXdY„Zd�d]d^„Zd‘d_d`„Ze	ddadb„ƒZ d’dedf„Z!d“dgdh„Z"d”djdk„Z#d•dmdn„Z$					d–d—dxdy„Z%d˜d|d}„Z&dS )™ÚScriptDirectoryaH  Provides operations upon an Alembic script directory.

    This object is useful to get information as to current revisions,
    most notably being able to get at the "head" revision, for schemes
    that want to test if the current revision in the database is the most
    recent::

        from alembic.script import ScriptDirectory
        from alembic.config import Config
        config = Config()
        config.set_main_option("script_location", "myapp:migrations")
        script = ScriptDirectory.from_config(config)

        head_revision = script.get_current_head()



    é(   NFúutf-8r   ÚdirÚstrÚfile_templateÚtruncate_slug_lengthúOptional[int]Úversion_locationsúOptional[List[str]]Ú
sourcelessÚboolÚoutput_encodingÚtimezoneúOptional[str]Úhook_configúOptional[Mapping[str, str]]Úrecursive_version_locationsÚmessaging_optsÚreturnÚNonec                 C  sv   || _ || _|| _|pd| _|| _|| _t | j¡| _	|| _
|| _|	| _|
| _t |tj¡s9t dtj |¡ ¡‚d S )Nr#   zVPath doesn't exist: %r.  Please use the 'init' command to create a new scripts folder.)r%   r'   r*   r(   r,   r.   r   ÚRevisionMapÚ_load_revisionsÚrevision_mapr/   r1   r3   r4   ÚosÚaccessÚF_OKr   ÚCommandErrorÚpathÚabspath)Úselfr%   r'   r(   r*   r,   r.   r/   r1   r3   r4   © rA   úO/var/www/html/flaskapp/venv/lib/python3.10/site-packages/alembic/script/base.pyÚ__init__N   s$   

þÿÿzScriptDirectory.__init__c                 C  s$   | j }t|ƒdkrt d¡‚|d S )Nr   z"Multiple version_locations presentr   )Ú_version_locationsÚlenr   r=   )r@   ÚlocrA   rA   rB   Úversionsp   s   
zScriptDirectory.versionsúSequence[str]c                 C  s0   | j rdd„ | j D ƒS tj tj | jd¡¡fS )Nc                 S  s   g | ]}t j t |¡¡‘qS rA   )r:   r>   r?   r   Úcoerce_resource_to_filename)Ú.0ÚlocationrA   rA   rB   Ú
<listcomp>{   s    ÿÿz6ScriptDirectory._version_locations.<locals>.<listcomp>rG   )r*   r:   r>   r?   Újoinr%   ©r@   rA   rA   rB   rD   x   s
   þz"ScriptDirectory._version_locationsúIterator[Script]c           	      c  s¬   � | j rdd„ | jD ƒ}n| jg}tƒ }|D ]=}t | |¡D ]4}tj |¡}||v r2t	 
d| ¡ q| |¡ tj |¡}tj |¡}t | ||¡}|d u rOq|V  qqd S )Nc                 S  s   g | ]
}t j |¡r|‘qS rA   )r:   r>   Úexists)rJ   ÚversrA   rA   rB   rL   „   s    
ýÿz3ScriptDirectory._load_revisions.<locals>.<listcomp>zJFile %s loaded twice! ignoring. Please ensure version_locations is unique.)r*   rD   rG   ÚsetÚScriptÚ_list_py_dirr:   r>   Úrealpathr   ÚwarnÚaddÚbasenameÚdirnameÚ_from_filename)	r@   ÚpathsÚdupesrQ   Ú	file_pathÚ	real_pathÚfilenameÚdir_nameÚscriptrA   rA   rB   r8   ‚   s4   €þÿÿ
ñÿzScriptDirectory._load_revisionsÚconfigr   c                 C  sJ  |  d¡}|du rt d¡‚|  d¡}|durt|ƒ}nd}|  d¡}|rc|  d¡}dddtjd	d
dœ}z|| }W n tyM }	 ztd| ƒ|	‚d}	~	ww |du rXt 	|¡}
ndd„ | 	|¡D ƒ}
nd}
|  d¡}|rxt
t 	|¡ƒtjdd…< |  d¡dk}tt |¡|  dt¡||  d¡dk|  dd¡|
|  d¡| di ¡||jd�
S )z¶Produce a new :class:`.ScriptDirectory` given a :class:`.Config`
        instance.

        The :class:`.Config` need only have the ``script_location`` key
        present.

        Úscript_locationNz0No 'script_location' key found in configuration.r(   r*   Úversion_path_separatorú Ú
ú:ú;)NÚspaceÚnewliner:   rg   rh   za'%s' is not a valid value for version_path_separator; expected 'space', 'newline', 'os', ':', ';'c                 S  s   g | ]}|r|  ¡ ‘qS rA   )Ústrip)rJ   ÚxrA   rA   rB   rL   Ö   s    ýÿz/ScriptDirectory.from_config.<locals>.<listcomp>Úprepend_sys_pathr   r3   Útruer'   r,   r.   r$   r/   Úpost_write_hooks)	r'   r(   r,   r.   r*   r/   r1   r3   r4   )Úget_main_optionr   r=   Úintr:   ÚpathsepÚKeyErrorÚ
ValueErrorÚ_split_on_space_commaÚsplitÚlistÚ_split_on_space_comma_colonÚsysr>   r"   rI   Ú_default_file_templateÚget_sectionr4   )Úclsrb   rc   Útslr(   Úversion_locations_strrd   Úsplit_on_pathÚ
split_charÚker*   rm   ÚrvlrA   rA   rB   Úfrom_configŸ   s~   
	ÿ


ÿú	ÿýÿû€ÿÿþ
ÿÿ

ôzScriptDirectory.from_configÚancestorÚmultiple_headsÚstartÚendÚ
resolutionúIterator[None]c           
   
   c  s  � zd V  W d S  t jy9 } z%|d u rtt|jƒ}|d u r$tt|jƒ}|s(d}|||dœ }t |¡|‚d }~w t jy] } z|sEd}||pJ|j	t 
|j¡dœ }t |¡|‚d }~w t jyx } z|d u rnd|j	 }t |¡|‚d }~w t jy� }	 z	t |	jd ¡|	‚d }	~	ww )NzgRequested range %(start)s:%(end)s does not refer to ancestor/descendant revisions along the same branch©r†   r‡   zÄMultiple head revisions are present for given argument '%(head_arg)s'; please specify a specific target revision, '<branchname>@%(head_arg)s' to narrow to a specific head, or 'heads' for all heads)Úhead_argÚheadsz(Can't locate revision identified by '%s'r   )r   ÚRangeNotAncestorErrorr   r   ÚlowerÚupperr   r=   ÚMultipleHeadsÚargumentÚformat_as_commarŒ   ÚResolutionErrorÚRevisionErrorÚargs)
r@   r„   r…   r†   r‡   rˆ   ÚrnaÚmhÚreÚerrrA   rA   rB   Ú_catch_revision_errorsô   sF   €	ÿ€ÿ
þ€ÿ€€ÿz&ScriptDirectory._catch_revision_errorsÚbaserŒ   Úheadc                 c  s\   � | j ||d�� | jj||ddd�D ]}tt|ƒV  qW d  ƒ dS 1 s'w   Y  dS )a-  Iterate through all revisions.

        :param base: the base revision, or "base" to start from the
         empty revision.

        :param head: the head revision; defaults to "heads" to indicate
         all head revisions.  May also be "head" to indicate a single
         head revision.

        rŠ   TF)Ú	inclusiveÚassert_relative_lengthN)rš   r9   Úiterate_revisionsr   rS   )r@   r›   rœ   ÚrevrA   rA   rB   Úwalk_revisions"  s   €
ÿý"ÿzScriptDirectory.walk_revisionsÚid_r   úTuple[Script, ...]c                 C  sF   |   ¡ � tttdf | j |¡ƒW  d  ƒ S 1 sw   Y  dS )z€Return the :class:`.Script` instance with the given rev identifier,
        symbolic name, or sequence of identifiers.

        .N)rš   r   r   rS   r9   Úget_revisions©r@   r¢   rA   rA   rB   r¤   5  s   


þ$ÿzScriptDirectory.get_revisionsúTuple[str, ...]úSet[Script]c                 C  sB   |   ¡ � ttt | j |¡ƒW  d   ƒ S 1 sw   Y  d S ©N)rš   r   r   rS   r9   Ú_get_all_currentr¥   rA   rA   rB   Úget_all_current@  s   
$ÿzScriptDirectory.get_all_currentrS   c                 C  s>   |   ¡ � tt| j |¡ƒW  d  ƒ S 1 sw   Y  dS )z�Return the :class:`.Script` instance with the given rev id.

        .. seealso::

            :meth:`.ScriptDirectory.get_revisions`

        N)rš   r   rS   r9   Úget_revisionr¥   rA   rA   rB   r«   D  s   
	$ÿzScriptDirectory.get_revisionú%Optional[Union[str, Tuple[str, ...]]]c                 C  sT   |   ¡ � | j |¡\}}W d  ƒ n1 sw   Y  |s dS |dkr&|S |d S )z[Convert a symbolic revision, i.e. 'head' or 'base', into
        an actual revision number.NrŒ   r   )rš   r9   Ú_resolve_revision_number)r@   r¢   r    Úbranch_namerA   rA   rB   Úas_revision_numberP  s   
ÿz"ScriptDirectory.as_revision_numberr�   ú!Union[str, Tuple[str, ...], None]rŽ   Úkwr   c                 K  s    t tt | jj||fi |¤ŽƒS )a½  Iterate through script revisions, starting at the given
        upper revision identifier and ending at the lower.

        The traversal uses strictly the `down_revision`
        marker inside each migration script, so
        it is a requirement that upper >= lower,
        else you'll get nothing back.

        The iterator yields :class:`.Script` objects.

        .. seealso::

            :meth:`.RevisionMap.iterate_revisions`

        )r   r   rS   r9   rŸ   )r@   r�   rŽ   r±   rA   rA   rB   rŸ   a  s   þz!ScriptDirectory.iterate_revisionsc                 C  s:   | j dd�� | j ¡ W  d  ƒ S 1 sw   Y  dS )aG  Return the current head revision.

        If the script directory has multiple heads
        due to branching, an error is raised;
        :meth:`.ScriptDirectory.get_heads` should be
        preferred.

        :return: a string revision number.

        .. seealso::

            :meth:`.ScriptDirectory.get_heads`

        z}The script directory has multiple heads (due to branching).Please use get_heads(), or merge the branches using alembic merge.©r…   N)rš   r9   Úget_current_headrN   rA   rA   rB   r³   {  s
   þ$ùz ScriptDirectory.get_current_headú	List[str]c                 C  ó   t | jjƒS )aU  Return all "versioned head" revisions as strings.

        This is normally a list of length one,
        unless branches are present.  The
        :meth:`.ScriptDirectory.get_current_head()` method
        can be used normally when a script directory
        has only one head.

        :return: a tuple of string revision numbers.
        )rw   r9   rŒ   rN   rA   rA   rB   Ú	get_heads“  s   zScriptDirectory.get_headsc                 C  s.   |   ¡ }t|ƒdkrt d¡‚|r|d S dS )a#  Return the "base" revision as a string.

        This is the revision number of the script that
        has a ``down_revision`` of None.

        If the script directory has multiple bases, an error is raised;
        :meth:`.ScriptDirectory.get_bases` should be
        preferred.

        r   z@The script directory has multiple bases. Please use get_bases().r   N)Ú	get_basesrE   r   r=   )r@   ÚbasesrA   rA   rB   Úget_base   s   ÿzScriptDirectory.get_basec                 C  rµ   )z”return all "base" revisions as strings.

        This is the revision number of all scripts that
        have a ``down_revision`` of None.

        )rw   r9   r¸   rN   rA   rA   rB   r·   ¶  s   zScriptDirectory.get_basesÚdestinationÚcurrent_revúList[RevisionStep]c                   s\   ˆ j d|d�� ˆ j||dd�}‡ fdd„tt|ƒƒD ƒW  d   ƒ S 1 s'w   Y  d S )NzFDestination %(end)s is not a valid upgrade target from current head(s)©r„   r‡   T)Úimplicit_basec                   ó   g | ]
}t j ˆ j|¡‘qS rA   )r   ÚMigrationStepÚupgrade_from_scriptr9   ©rJ   ra   rN   rA   rB   rL   Ê  ó    ýÿÿz1ScriptDirectory._upgrade_revs.<locals>.<listcomp>)rš   rŸ   Úreversedrw   ©r@   rº   r»   ÚrevsrA   rN   rB   Ú_upgrade_revs¿  s   ýÿ

ü$øzScriptDirectory._upgrade_revsc                   sT   ˆ j d|d�� ˆ j||dd�}‡ fdd„|D ƒW  d   ƒ S 1 s#w   Y  d S )NzHDestination %(end)s is not a valid downgrade target from current head(s)r½   T)Úselect_for_downgradec                   r¿   rA   )r   rÀ   Údowngrade_from_scriptr9   rÂ   rN   rA   rB   rL   Ü  rÃ   z3ScriptDirectory._downgrade_revs.<locals>.<listcomp>)rš   rŸ   rÅ   rA   rN   rB   Ú_downgrade_revsÑ  s   ýÿ
ü$øzScriptDirectory._downgrade_revsr   r   úList[StampStep]c              	     sš  ˆ j dd��½ ˆ  |¡}g }|sd}g }t |¡D ]}|r.| ˆ jjttt	 |ƒ|dd�¡ qt 
|¡}ˆ  |¡p;d g}|D ]{}|d u rQ| ‡ fdd„|D ƒ¡ q>||v rVq>tˆ j |g¡ƒ}	tˆ j |g¡ƒ}
|	 |¡rŒ|
 |¡rtJ ‚dd„ |D ƒ}t ||jd	d	ˆ j¡}| |¡ q>|
 |¡r©d
d„ |D ƒ}t ||jdd	ˆ j¡}| |¡ q>t d|jddˆ j¡}| |¡ q>|W  d   ƒ S 1 sÆw   Y  d S )NzCMultiple heads are present; please specify a single target revisionr²   r›   T)Úinclude_dependenciesc              	     s"   g | ]}t  |jd ddˆ j¡‘qS )NFT)r   r   r   r9   ©rJ   rœ   rN   rA   rB   rL     s    ùûÿz/ScriptDirectory._stamp_revs.<locals>.<listcomp>c                 S  ó   g | ]}|j ‘qS rA   r   rÍ   rA   rA   rB   rL     ó    Fc                 S  rÎ   rA   r   rÍ   rA   rA   rB   rL   ,  rÏ   rA   )rš   r¤   r   Úto_tupleÚextendr9   Úfilter_for_lineager   r   rS   Úunique_listrR   Ú_get_descendant_nodesÚ_get_ancestor_nodesÚintersectionr   r   r   Úappend)r@   r   rŒ   Ú
heads_revsÚstepsÚfiltered_headsr    ÚdestsÚdestÚdescendantsÚ	ancestorsÚ
todo_headsÚsteprA   rN   rB   Ú_stamp_revsã  s€   ÿ
ýÿ€

øÿÿ
û

û
ÿ
$§zScriptDirectory._stamp_revsc                 C  s   t  | jd¡ dS )zÞRun the script environment.

        This basically runs the ``env.py`` script present
        in the migration environment.   It is called exclusively
        by the command functions in :mod:`alembic.command`.


        úenv.pyN)r   Úload_python_filer%   rN   rA   rA   rB   Úrun_envA  s   	zScriptDirectory.run_envc                 C  s   t j t j | jd¡¡S )Nrâ   )r:   r>   r?   rM   r%   rN   rA   rA   rB   Úenv_py_locationL  s   zScriptDirectory.env_py_locationÚsrcrÜ   c                 K  s`   t jdtj |¡› �fi | j¤Ž� t j||| jfi |¤Ž W d   ƒ d S 1 s)w   Y  d S ©NzGenerating )r   Ústatusr:   r>   r?   r4   Útemplate_to_filer.   )r@   ræ   rÜ   r±   rA   rA   rB   Ú_generate_templateP  s   ÿÿ"ýz"ScriptDirectory._generate_templatec                 C  sT   t jdtj |¡› �fi | j¤Ž� t ||¡ W d   ƒ d S 1 s#w   Y  d S rç   )r   rè   r:   r>   r?   r4   ÚshutilÚcopy)r@   ræ   rÜ   rA   rA   rB   Ú
_copy_fileV  s   ÿÿ"ýzScriptDirectory._copy_filer>   c                 C  sf   t j |¡}t j |¡s1tjd|› �fi | j¤Ž� t  |¡ W d   ƒ d S 1 s*w   Y  d S d S )NzCreating directory )r:   r>   r?   rP   r   rè   r4   Úmakedirs)r@   r>   rA   rA   rB   Ú_ensure_directory\  s   ÿÿ"ýÿz!ScriptDirectory._ensure_directoryúdatetime.datetimec                 C  s¬   | j d urOtd u rt d¡‚zt| j ƒ}W n ty    d }Y nw |d u r?z	t| j  ¡ ƒ}W n ty>   t d| j  ¡d ‚w tj ¡ jtj j	d� 
|¡}|S tj ¡ }|S )NzePython >= 3.9 is required for timezone support or the 'backports.zoneinfo' package must be installed.zCan't locate timezone: %s)Útzinfo)r/   r    r   r=   r!   r�   ÚdatetimeÚutcnowÚreplaceÚutcÚ
astimezoneÚnow)r@   rñ   Úcreate_daterA   rA   rB   Ú_generate_create_dated  s8   
ÿÿÿþÿÿý
ÿz%ScriptDirectory._generate_create_dateÚrevidÚmessageúOptional[_RevIdType]ÚspliceúOptional[bool]Úbranch_labelsÚversion_pathÚ
depends_onúOptional[Script]c              
     s  |du rd}zt  |¡ W n tjy# }	 z	t |	jd ¡|	‚d}	~	ww ˆ jdd��" tt	t
d df ˆ j |¡ƒ}
|
D ]}|dksDJ ‚q<W d  ƒ n1 sOw   Y  tt|
ƒƒt|
ƒkrct d	¡‚ˆ  ¡ }|du r”tˆ jƒd
kr‘|
D ]}|durŠt|t ƒs�J ‚tj |j¡} nqtt d¡‚nˆ j}tj tj |¡¡}ˆ jD ]}tj |¡|kr­ nq¡t d| ¡‚ˆ jr½ˆ  |¡ ˆ  ||||¡}|sÛ|
D ]}|durÚ|jsÚt d|j ¡‚qÉ|�rˆ  ¡ � dd„ ‡ fdd„t |¡D ƒD ƒ}W d  ƒ n1 sþw   Y  nd}ˆ jtj ˆ jd¡|ft |ƒt !t"dd„ |
D ƒƒ¡t #|¡t !|¡|tj$|du�r1|nddœ|¤Ž ˆ j%}|�rDt& '||¡ zt  (ˆ |¡}W n tj�yc }	 z	t |	jd ¡|	‚d}	~	ww |du �rkdS |�r~|j)�s~t d|j||jf ¡‚ˆ j *|¡ |S )aÄ  Generate a new revision file.

        This runs the ``script.py.mako`` template, given
        template arguments, and creates a new file.

        :param revid: String revision id.  Typically this
         comes from ``alembic.util.rev_id()``.
        :param message: the revision message, the one passed
         by the -m argument to the ``revision`` command.
        :param head: the head revision to generate against.  Defaults
         to the current "head" if no branches are present, else raises
         an exception.
        :param splice: if True, allow the "head" version to not be an
         actual head; otherwise, the selected head must be a head
         (e.g. endpoint) revision.

        Nrœ   r   z{Multiple heads are present; please specify the head revision on which the new revision should be based, or perform a merge.r²   r   .r›   z"Duplicate head revisions specifiedr   zAMultiple version locations present, please specify --version-pathz7Path %s is not represented in current version locationszeRevision %s is not a head revision; please specify --splice to create a new branch from this revisionc                 S  s$   g | ]\}}||j v r|n|j‘qS rA   )rÿ   r   )rJ   r    ÚdeprA   rA   rB   rL   á  s    
ýÿüz5ScriptDirectory.generate_revision.<locals>.<listcomp>c                   s    g | ]}t ˆ j |¡ƒ|f‘qS rA   )r   r9   r«   )rJ   r  rN   rA   rB   rL   ç  s    ÿÿzscript.py.makoc                 s  s"   � | ]}|d ur|j nd V  qd S r¨   r   )rJ   ÚhrA   rA   rB   Ú	<genexpr>ô  s   €  z4ScriptDirectory.generate_revision.<locals>.<genexpr>zempty message)Úup_revisionÚdown_revisionrÿ   r  rø   Úcommarû   z¦Version %s specified branch_labels %s, however the migration file %s does not have them; have you upgraded your script.py.mako to include the 'branch_labels' section?)+rS   Úverify_rev_idr   r”   r   r=   r•   rš   r   r   r
   r9   r¤   rE   rR   rù   rD   Ú
isinstancer:   r>   rY   rG   Únormpathr?   r*   rï   Ú	_rev_pathÚis_headÚto_listrê   rM   r%   r&   Útuple_rev_as_scalarÚtuplerÐ   r’   r1   r   Ú
_run_hooksÚ
_from_pathrÿ   Úadd_revision)r@   rú   rû   rœ   rý   rÿ   r   r  r±   r™   rŒ   r  rø   Úhead_Ú	norm_pathÚ	vers_pathr>   Úresolved_depends_onro   ra   rA   rN   rB   Úgenerate_revision€  sÌ   €ÿþ
þÿõ
ýÿþ
ÿÿÿ
þÿ€

þúÿ€þÿõô€ÿ
üÿz!ScriptDirectory.generate_revisionÚrev_idrø   c                 C  sŒ   t | ¡ ƒ}d t |pd¡¡ ¡ }t|ƒ| jkr(|d | j…  dd¡d d }d| j	||||j
|j|j|j|j|jdœ	  }tj ||¡S )NÚ_Ú r   r   z%s.py)	r    ÚslugÚepochÚyearÚmonthÚdayÚhourÚminuteÚsecond)rq   Ú	timestamprM   Ú_slug_reÚfindallrŽ   rE   r(   Úrsplitr'   r  r  r   r!  r"  r#  r:   r>   )r@   r>   r  rû   rø   r  r  r_   rA   rA   rB   r    s&   ÷ÿÿzScriptDirectory._rev_path)r%   r&   r'   r&   r(   r)   r*   r+   r,   r-   r.   r&   r/   r0   r1   r2   r3   r-   r4   r   r5   r6   ©r5   r&   )r5   rH   )r5   rO   )rb   r   r5   r"   )NNNNN)r„   r0   r…   r0   r†   r0   r‡   r0   rˆ   r0   r5   r‰   )r›   rŒ   )r›   r&   rœ   r&   r5   rO   )r¢   r   r5   r£   )r¢   r¦   r5   r§   )r¢   r&   r5   rS   )r¢   r0   r5   r¬   )r�   r°   rŽ   r°   r±   r   r5   rO   )r5   r0   )r5   r´   )rº   r&   r»   r&   r5   r¼   )rº   r&   r»   r0   r5   r¼   )r   r   rŒ   r   r5   rË   )r5   r6   )ræ   r&   rÜ   r&   r±   r   r5   r6   )ræ   r&   rÜ   r&   r5   r6   )r>   r&   r5   r6   )r5   rð   )NFNNN)rú   r&   rû   r0   rœ   rü   rý   rþ   rÿ   rü   r   r0   r  rü   r±   r   r5   r  )
r>   r&   r  r&   rû   r0   rø   rð   r5   r&   )'Ú__name__Ú
__module__Ú__qualname__Ú__doc__rz   r   r   Ú
EMPTY_DICTrC   ÚpropertyrG   Úmemoized_propertyrD   r8   Úclassmethodrƒ   r   rš   r¡   r¤   rª   r«   r¯   rŸ   r³   r¶   r¹   r·   rÇ   rÊ   rá   rä   rå   rê   rí   rï   rù   r  r  rA   rA   rA   rB   r"   :   sr    ÿõ"
	Tú.ÿ









	


^



 ø r"   c                      sØ   e Zd ZU dZd0‡ fdd„Zded< 	 ded< 	 d	Zd
ed< 	 ed1dd„ƒZed1dd„ƒZ	ed1dd„ƒZ
d1dd„Z					d2d3dd„Z				d4d5d d!„Zd1d"d#„Zed6d'd(„ƒZed7d*d+„ƒZed8d.d/„ƒZ‡  ZS )9rS   z¶Represent a single revision file in a ``versions/`` directory.

    The :class:`.Script` instance is returned by methods
    such as :meth:`.ScriptDirectory.iterate_revisions`.

    Úmoduler   r  r&   r>   c              	     sJ   || _ || _tƒ j||jtjt|dd ƒdd�tjt|dd ƒdd�d� d S )Nrÿ   rA   )Údefaultr  )rÿ   Údependencies)r1  r>   ÚsuperrC   r  r   rÐ   Úgetattr)r@   r1  r  r>   ©Ú	__class__rA   rB   rC   7  s   ÿÿ
úzScript.__init__Nrþ   Ú_db_current_indicatorr5   c                 C  s   t  d| j¡d S )ú)Return the docstring given in the script.z

r   )r˜   rv   ÚlongdocrN   rA   rA   rB   ÚdocO  s   z
Script.docc                 C  s2   | j j}|rt| j dƒr| | j j¡}| ¡ S dS )r9  Ú_alembic_source_encodingr  )r1  r,  ÚhasattrÚdecoder<  rk   )r@   r;  rA   rA   rB   r:  U  s   ÿzScript.longdocc                 C  sî   d| j | jrdnd| jrdnd| jrdnd| jrdndf }| jr+|d|  ¡ f 7 }n	|d|  ¡ f 7 }| jrA|d	t | j¡ 7 }| jrN|d
t | j	¡ 7 }| j
r\|dt | j
¡f 7 }|d| jf 7 }|dd dd„ | j ¡ D ƒ¡ 7 }|S )NzRev: %s%s%s%s%s
ú (head)r  ú (branchpoint)ú (mergepoint)ú
 (current)zMerges: %s
zParent: %s
zAlso depends on: %s
zBranches into: %s
zBranch names: %s
z	Path: %s
z
%s
rf   c                 s  s   � | ]}d | V  qdS )z    %sNrA   )rJ   ÚpararA   rA   rB   r  ƒ  s   € z#Script.log_entry.<locals>.<genexpr>)r   r  Úis_branch_pointÚis_merge_pointr8  Ú_format_down_revisionr3  r   r’   Únextrevrÿ   r>   rM   r:  Ú
splitlines)r@   ÚentryrA   rA   rB   Ú	log_entryc  s6   û
ÿ
ÿ
ÿÿzScript.log_entryc                 C  s:   d|   ¡ | j| jrdnd| jrdnd| jrdnd| jf S )Nz%s -> %s%s%s%s, %sr?  r  r@  rA  )rF  r   r  rD  rE  r;  rN   rA   rA   rB   Ú__str__‡  s   úzScript.__str__FTÚinclude_branchesr-   Úinclude_docÚinclude_parentsÚtree_indicatorsÚhead_indicatorsc                 C  sâ   | j }|r| jrd|  ¡ t | j¡|f }nd|  ¡ |f }|d us$J ‚|r3| jr3|dt | j¡ 7 }|s7|rR|d| jr>dnd| jrG| jsGdnd| jrMdndf 7 }|rf|d	| j	r[d
nd| j
radndf 7 }|ro|d| j 7 }|S )Nz%s (%s) -> %sz%s -> %sz (%s)z%s%s%sr?  r  z (effective head)rB  z%s%sr@  rA  z, %s)r   r3  rF  r   r’   rÿ   Ú_is_real_headr  r8  rD  rE  r;  )r@   rL  rM  rN  rO  rP  ÚtextrA   rA   rB   Ú
_head_only‘  s<   
ý
ÿÿù	þzScript._head_onlyÚverbosec                 C  s   |r| j S |  ||||¡S r¨   )rJ  rS  )r@   rT  rL  rM  rN  rO  rA   rA   rB   Ú
cmd_format¹  s
   ÿzScript.cmd_formatc                 C  s   | j sdS t | j¡S )Nz<base>)r  r   r’   Ú_versioned_down_revisionsrN   rA   rA   rB   rF  È  s   zScript._format_down_revisionÚ	scriptdirr"   r  c                 C  s   t j |¡\}}|  |||¡S r¨   )r:   r>   rv   rZ   )r|   rW  r>   Údir_r_   rA   rA   rB   r  Î  s   zScript._from_pathr´   c                   s²   g }t j|dd�D ]M\}}}| d¡rq	t|ƒD ]}| t j ||¡¡ q|jrLt j |d¡‰t j ˆ¡rLdd„ |D ƒ‰ | 	‡ ‡fdd„t  
ˆ¡D ƒ¡ |jsR |S | ¡  q	|S )NT)ÚtopdownÚ__pycache__c                 S  s   h | ]	}|  d ¡d ’qS )Ú.r   )rv   )rJ   r_   rA   rA   rB   Ú	<setcomp>è  s    z&Script._list_py_dir.<locals>.<setcomp>c                 3  s0   � | ]}|  d ¡d ˆ vrtj ˆ|¡V  qdS )r[  r   N)rv   r:   r>   rM   )rJ   Úpyc©ÚnamesÚpy_cache_pathrA   rB   r  é  s   € þýz&Script._list_py_dir.<locals>.<genexpr>)r:   ÚwalkÚendswithÚsortedr×   r>   rM   r,   rP   rÑ   Úlistdirr3   Úsort)r|   rW  r>   r[   ÚrootÚdirsÚfilesr_   rA   r^  rB   rT   Õ  s$   
þ
þzScript._list_py_dirrX  r_   c                 C  sü   |j r	t |¡}nt |¡}|sd S | d¡}|j r)| d¡dk}| d¡dk}nd }}|s1|rQtj tj ||¡¡}tj tj ||d ¡¡}	|sO|rQ|	rQd S t	 
||¡}
t|
dƒspt |¡}|sjt	 d| ¡‚| d¡}n|
j}t|
|tj ||¡ƒS )Nr   r   ÚcÚoFr   z¶Could not determine revision id from filename %s. Be sure the 'revision' variable is declared inside the script (please see 'Upgrading from Alembic 0.1 to 0.2' in the documentation).)r,   Ú_sourceless_rev_fileÚmatchÚ_only_source_rev_fileÚgroupr:   r>   rP   rM   r   rã   r=  Ú_legacy_revr=   r   rS   )r|   rW  rX  r_   Úpy_matchÚpy_filenameÚis_cÚis_oÚ	py_existsÚ
pyc_existsr1  Úmr   rA   rA   rB   rZ   ú  s6   



üÿzScript._from_filename)r1  r   r  r&   r>   r&   r(  )FFFTT)rL  r-   rM  r-   rN  r-   rO  r-   rP  r-   r5   r&   )FFFT)rT  r-   rL  r-   rM  r-   rN  r-   rO  r-   r5   r&   )rW  r"   r>   r&   r5   r  )rW  r"   r>   r&   r5   r´   )rW  r"   rX  r&   r_   r&   r5   r  )r)  r*  r+  r,  rC   Ú__annotations__r8  r.  r;  r:  rJ  rK  rS  rU  rF  r0  r  rT   rZ   Ú__classcell__rA   rA   r6  rB   rS   /  sD   
 
#ú+ú
$rS   )8Ú
__future__r   Ú
contextlibr   rò   r:   r˜   rë   ry   Útypesr   Útypingr   r   r   r   r	   r
   r   r   r   r   r   r  r   r   r   Úruntimer   r   r   r   r   r   rb   r   r   Úruntime.migrationr   r   Úpy39Úzoneinfor    r!   Úbackports.zoneinfoÚImportErrorÚcompilerk  rm  ro  r%  rz   ru   rx   r"   rS   rA   rA   rA   rB   Ú<module>   sr    €ÿ





     z