|L ihjddlmZddlZddlZddlmZddlmZddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z dd lm Z dd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZerddlmZeeeeeedffZeee eee efZ eeeedfdfZ!edefZ"edZ#e edfZ$e edeedfedfZ%edZ&edee" Z'ejPd!Z)gd"Z*Gd#d$eZ+Gd%d&e,Z-Gd'd(e-Z.Gd)d*e-Z/Gd+d,e-Z0Gd-d.e-Z1Gd/d0e1Z2Gd1d2e1Z3Gd3d4e2e3Z4Gd5d6Z5Gd7dZ6edd:Z7d?d;Z8y)@) annotationsN)Any)Callable)cast) Collection)Deque)Dict) FrozenSet)Iterable)Iterator)List)Optional)overload)Protocol)Sequence)Set)Tuple) TYPE_CHECKING)TypeVar)Union)util)not_none)Literal.Revision)rzLiteral['base']_T_TR)boundz(?:(.+?)@)?(\w+)?((?:\+|-)\d+))@-+:c,eZdZ ddZy)_CollectRevisionsProtocolcyNr)selfupperlower inclusive implicit_baseassert_relative_lengths ]/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/alembic/script/revision.py__call__z"_CollectRevisionsProtocol.__call__4s GJN r)_RevisionIdentifierTyper*r2r+boolr,r3r-r3returnz;Tuple[Set[Revision], Tuple[Optional[_RevisionOrBase], ...]])__name__ __module__ __qualname__r/rr0r.r%r%3sIJ&J'J J  J !% J EJr0r%c eZdZy) RevisionErrorN)r5r6r7rr0r.r9r9>sr0r9c,eZdZ dfd ZxZS)RangeNotAncestorErrorc\||_||_t| d|xsdd|xsdy)N Revision basez is not an ancestor of revision )r*r)super__init__)r(r*r) __class__s r.r@zRangeNotAncestorError.__init__Cs6    1 r0)r*r2r)r2r4Noner5r6r7r@ __classcell__rAs@r.r;r;Bs% , 5L   r0r;c eZdZdfd ZxZS) MultipleHeadscj||_||_t| d|ddj |y)Nz/Multiple heads are present for given argument 'z'; , )headsargumentr?r@join)r(rJrKrAs r.r@zMultipleHeads.__init__Os1    dii. 0 r0)rJ Sequence[str]rK Optional[str]r4rBrCrEs@r.rGrGNs   r0rGc eZdZdfd ZxZS)ResolutionErrorc2t||||_yr')r?r@rK)r(messagerKrAs r.r@zResolutionError.__init__Ys !  r0)rRstrrKrSr4rBrCrEs@r.rPrPXs !!r0rPc$eZdZdZdfd ZxZS) CycleDetectedCyclecp||_t| |jddj |dy)Nz is detected in revisions (rI)) revisionsr?r@kindrLr(rYrAs r.r@zCycleDetected.__init__as." yy$))I. 0 r0rYrMr4rBr5r6r7rZr@rDrEs@r.rUrU^s D  r0rUc$eZdZdZdfd ZxZS)DependencyCycleDetectedzDependency cyclec$t||yr'r?r@r[s r.r@z DependencyCycleDetected.__init__ls #r0r\r]rEs@r.r_r_is D$$r0r_c$eZdZdZdfd ZxZS) LoopDetectedz Self-loopc&t||gyr'rar(revisionrAs r.r@zLoopDetected.__init__ss ($r0rfrSr4rBr]rEs@r.rcrcps D%%r0rcc$eZdZdZdfd ZxZS)DependencyLoopDetectedzDependency self-loopc$t||yr'rares r.r@zDependencyLoopDetected.__init__zs "r0)rfrMr4rBr]rEs@r.ririws !D##r0ric<eZdZdZd$dZej d%dZej d%dZej d%dZ ej d%dZ ej d&dZ d'dZ d(d Z d(d Z d(d Z d(d Zd)d*d Z d+ d,dZd-dZ d.dZd/dZd0dZ d+ d1dZ d2dZ d) d3dZ d) d4dZ d5dZ d6 d7dZ d8 d9dZ d: d;dZ d) d d?dZ! d@dZ" dAd Z# dBd!Z$ dCd"Z% dDd#Z&y)E RevisionMapzMaintains a map of :class:`.Revision` objects. :class:`.RevisionMap` is used by :class:`.ScriptDirectory` to maintain and traverse the collection of :class:`.Script` objects, which are themselves instances of :class:`.Revision`. c||_y)a Construct a new :class:`.RevisionMap`. :param generator: a zero-arg callable that will generate an iterable of :class:`.Revision` instances to be used. These are typically :class:`.Script` subclasses within regular Alembic use. N) _generator)r( generators r.r@zRevisionMap.__init__s $r0c2|j|jS)zAll "head" revisions as strings. This is normally a tuple of length one, unless unmerged branches are present. :return: a tuple of string revision numbers. ) _revision_maprJr(s r.rJzRevisionMap.heads zzr0c2|j|jS)zAll "base" revisions as strings. These are revisions that have a ``down_revision`` of None, or empty tuple. :return: a tuple of string revision numbers. )rqbasesrrs r.ruzRevisionMap.basesrsr0c2|j|jS)zeAll "real" head revisions as strings. :return: a tuple of string revision numbers. )rq _real_headsrrs r.rwzRevisionMap._real_heads r0c2|j|jS)zeAll "real" base revisions as strings. :return: a tuple of string revision numbers. )rq _real_basesrrs r.rzzRevisionMap._real_basesrxr0c tj}tj}tj}d}d}t}t}|j D]}|j ||j |vr"tjd|j z|||j <|jr|j ||j ||j ||jr||fz }|js||fz }|j} |j|tt||j!|tt||j#D]y} | j$D]h} | |vrtjd| d| d|| } | j'| | | j(vr|j+| |j+| j{|j-|tt||j/| ||||t1|j3} dx| d<| d<t5d|D|_t5d|D|_t5d |D|_t5d |D|_|j?|| | S) z_memoized attribute, initializes the revision map from the initial collection. r%Revision %s is present more than oncer= referenced from  is not presentNc34K|]}|jywr'rf.0revs r. z,RevisionMap._revision_map..9C3<<9c34K|]}|jywr'rrs r.rz,RevisionMap._revision_map.. E# Erc34K|]}|jywr'rrs r.rz,RevisionMap._revision_map..rrc34K|]}|jywr'rrs r.rz,RevisionMap._revision_map..rr) sqlautil OrderedDict OrderedSetsetrnaddrfrwarn branch_labelsis_base _is_real_basecopy_map_branch_labelsr_RevisionMapType_add_depends_onvalues_all_down_revisions add_nextrev_versioned_down_revisionsdiscard_normalize_depends_on_detect_cyclesdictitemstuplerJrwrurz _add_branches)r(map_rJrwrurzhas_branch_labels all_revisionsrfrev_maprdownrev down_revision revision_maps r.rqzRevisionMap._revision_maps~)1(<(<(>'224%-%8%8%: &(,. E ) +H   h '  D( ;h>O>OO'/D"" #%%!%%h/ IIh  OOH %($%%{* ! +())+  t$4d; ]D1A4,HI;;= 3C22 3$&II"C)!%W ))#.c;;;MM-0##M2 3 3 ""=$7G2NO GUE; L)-djjl); 044 T\"-9599  E EE9599  E EE ,l;r0c |sy|r|stt||jd|tt|Dchc]}|j c}j d|jd|tt|D}t|j|z }|rtt||r|stt||jd|tt|Dchc]}|j c}j d|jd|tt|D}t|j|z }|rtt|ycc}wcc}w)Nc|jSr'rrs r.z,RevisionMap._detect_cycles..s !55r0)rc34K|]}|jywr'rrs r.rz-RevisionMap._detect_cycles..  LL rc|jSr'nextrevrs r.rz,RevisionMap._detect_cycles..!s !))r0c|jSr')rrs r.rz,RevisionMap._detect_cycles../s !//r0c34K|]}|jywr'rrs r.rz-RevisionMap._detect_cycles..3rrc|jSr' _all_nextrevrs r.rz,RevisionMap._detect_cycles..6s !..r0) rUlist_iterate_related_revisionsrrrf intersectionrkeyssortedr_) r(rrJrurwrzr total_space deleted_revss r.rzRevisionMap._detect_cycles s EW . .665*G47  LL  , 66#*G47   7<<>*[8 | 45 5+)$w-8 866/*G47  LL  , 66(*G47   7<<>*[8 )&*>? ? K * s E==Fc |D]h}|js|jJ|jD]<}||vr1||}|Jtd|d|jd|j|||<>jy)Nz Branch name 'z' in revision z already used by revision )r_orig_branch_labelsr9rf)r(rYrrf branch_labelmap_revs r.rzRevisionMap._map_branch_labels?s" 2H%%33???$,$@$@ 2L#t+"&|"4&222+!- ( 1 1 ' 0 0 *2D& 2 2r0c|D]}|js|jj|j|j|g|dD]'}|jj|j)}|sy|jr|jr|jj|j|j r||j }n|s|jr|js_yNFinclude_dependencies)rupdate_get_descendant_nodes_is_real_branch_pointis_merge_pointr)r(rYrrfnodeparents r.rzRevisionMap._add_branchesTs" H%%&&--h.D.DE 66J57FD&&--h.D.DEF "88"11((//0F0FG++!%f&:&:!;"88"11 r0c|D]p}|jr[tj|jDcgc]}|| }}t|Dcgc]}||jc}|_jd|_rycc}wcc}w)aResolve the 'dependencies' for each revision in a collection in terms of actual revision ids, as opposed to branch labels or other symbolic names. The collection is then assigned to the _resolved_dependencies attribute on each revision object. Nr) dependenciesrto_tuplerrf_resolved_dependencies)r(rYrrfdepdepsds r.rzRevisionMap._add_depends_onks" 5H$$)-x7L7L)M"%DI38)-?AQZZ?3/35/ 5@s A7 A< A< c|D]}|jrmt|j}|j|gd|D]/}||ur|js|j|j1t ||_|d|_y)aCreate a collection of "dependencies" that omits dependencies that are already ancestor nodes for each revision in a given collection. This builds upon the _resolved_dependencies collection created in the _add_depends_on() method, looking in the fully populated revision map for ancestors, and omitting them as the _resolved_dependencies collection as it is copied to a new collection. The new collection is then assigned to the _normalized_resolved_dependencies attribute on each revision object. The collection is then used to determine the immediate "down revision" identifiers for this revision. F)rrrN)rr_get_ancestor_nodesdifference_updater!_normalized_resolved_dependencies)r(rYrrfnormalized_resolvedrs r.rz!RevisionMap._normalize_depends_ons&" @H..&)(*I*I&J#33J).4 C h 33+==66 >C'>:>@:' @r0c|j}|s1j|vr#tjdjzn(|r&j|vrt djz|j<g}|j |||j |||j||jr |xjjfz c_ jr |xjjfz c_ jD]?}||vrtjd|ddt||jA|j||j r1t#fd|j$Djfz|_j&r2t#fd|j(Djfz|_yy) zadd a single revision to an existing map. This method is for single-revision use cases, it's not appropriate for fully populating an entire revision map. r|zrevision %s not in mapr=r}r~c3K|]7}|tjjjgvr|9ywr')rrunionrfrheadrfs r.rz+RevisionMap.add_revision..sF%8778>>&&'%=Ac3K|]7}|tjjjgvr|9ywr')rrrrfrs r.rz+RevisionMap.add_revision..sF8==>DD&&'rN)rqrfrr Exceptionrrrrrurrzrrrr _is_real_headrrwis_headrJ)r(rf_replacerrYrs ` r. add_revisionzRevisionMap.add_revisions!!H--5 II7(:K:KK (++474x7H7HHI I"*X  J  9d+  40 Y-    JJ8,,. .J  ! !   !2!2 4 4 33 :Gd" * T'] # / / 9  : ""9d3  ! !$% ,,% ""$ %D     JJ""$%DJ r0Nc|j}|r|j||}t|dkDrt||r d|zd|r|dSy)aReturn 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. :param branch_label: optional branch name which will limit the heads considered to those which include that branch_label. :return: a string revision number. .. seealso:: :meth:`.ScriptDirectory.get_heads` z%s@headrrN)rJfilter_for_lineagelenrG)r(r current_headss r.get_current_headzRevisionMap.get_current_headsn((,zz  33|M }  !,8 L( >D   # #r0c:|j|j|Sr')rru)r( identifiers r._get_base_revisionszRevisionMap._get_base_revisionss&&tzz:>>r0ct|ttttfr)t |Dcgc]}j |c}dSj|\}t|dk(rQ t|ddkr<j d}tfd|D}tfd|DS tfd|DScc}w#t$rY%wxYw)aReturn the :class:`.Revision` instances with the given rev id or identifiers. May be given a single identifier, a sequence of identifiers, or the special symbols "head" or "base". The result is a tuple of one or more identifiers, or an empty tuple in the case of "base". In the cases where 'head', 'heads' is requested and the revision map is empty, returns an empty tuple. Supports partial identifiers, where the given identifier is matched against all identifiers that start with the given characters; if there is exactly one match, that determines the full revision. rrrrJc3PK|]}t|jvr|ywr') is_revisionr)rrrs r.rz,RevisionMap.get_revisions..(s01$(#/#.t#4#B#B$C!%1s#&c3DK|]}j|yw))stepsN)_walk)rrrintr(s r.rz,RevisionMap.get_revisions...s&% $!JJt4J8%s c3BK|]}j|ywr')_revision_for_ident)rrev_idrr(s r.rz,RevisionMap.get_revisions..5s&((>s) isinstancerrr frozensetsum get_revisions_resolve_revision_numberrint ValueError)r(id_id_elem resolved_id select_headsrrs` @@r.rzRevisionMap.get_revisions s( cD%i8 93G**73GL L(,(E(Ec(J %K;1${1~.Dax'+'9'9''B '3+01,81,L %%(4%  ") /H("sC0AC C&%C&c|j|\}}t|dkDr t|||r|dnd}|j||S)a Return the :class:`.Revision` instance with the given rev id. If a symbolic name such as "head" or "base" is given, resolves the identifier into the current head or base revision. If the symbolic name refers to multiples, :class:`.MultipleHeads` is raised. Supports partial identifiers, where the given identifier is matched against all identifiers that start with the given characters; if there is exactly one match, that determines the full revision. rrr)rrrGr)r(rrrresolveds r. get_revisionzRevisionMap.get_revision:sS%)$A$A#$F! \ { a  S1 1.s-LQfqj-Lsrz...r=z is not a member of branch ') r rqr r startswithrrPrL_shares_lineagerf)r(r check_branchr rfxrevss r.rzRevisionMap._revision_for_ident_s --l;JJ ))+6H u  ;++Q! [(AD ..t\B%$ #;/!3N"$$    TQ%#DII-L$q)-L$LN  --d1g6 H0) )) ;''!!:#6#6&((,8 e H sD>*E> E  E ct|}t|D]K}|sJ|j|j|gdj |gs;|j |M|Sr)rrrr differencer)r(targetsrs r._filter_into_branch_headsz%RevisionMap._filter_into_branch_headsspg,= %CJ3##**C5u*Mj# $  % r0cj|\}}g|rj||rj|tfd|DS)Nc3JK|]}j|r|yw)rN)r)rtgrr(sharess r.rz1RevisionMap.filter_for_lineage..s4 ##F1E$  s #)rappendextendr)r(r check_againstrrrr!s` ` @r.rzRevisionMap.filter_for_lineagesW !99-H\  MM, '  MM#     r0c|syt|tst|j|}n|}t j |dDcgc]%}t|ts|j|n|'}}t t|j|g|j|j|g|j|Scc}w)NTrdefaultr) rrrrrrr3rrrrr)r(targettest_against_revsrresolved_targettest_against_revresolved_test_against_revss r.rzRevisionMap._shares_lineages !&(+&t'?'?'GHO$O%)MM!2% & !""2H=(()9:%& & " &  **$%)=+  U(($%)=) \4 5   & s *C ct|trd|vr|jdd\}}nN|Jt|tr|rt|dtrt|ttfst d|dd}|j |dk(r.|r|j |j||fS|j|fS|dk(r|j|}|r|f|fSd|fS|d k(s|d|fStj|d |fS) Nr rrzrevision identifier z= is not a string; ensure database driver settings are correctrJrrr>r&) rrSsplitrr9rqrrJrwrrr)r(rr current_heads r.rz$RevisionMap._resolve_revision_numbers c3 C3J # #q 1 L# _ U #Js1vs4KcC<0147   L  '>++DJJ E  ''55 F]00>L$ 44<'' F]ck|# #==d3\A Ar0c#K|r |j}n |j}||||||\}} |j|| D]} t|j |  yw)auIterate 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:`.Revision` objects. )r+r,r-N)_collect_downgrade_revisions_collect_upgrade_revisions_topological_sortrr) r(r)r*r,r+r-select_for_downgradefnrYrJrs r.iterate_revisionszRevisionMap.iterate_revisionsss* 22B00B  '#9   5**9e< 4D4,,T23 3 4sA A"cV|rdfd }n |rdd}ndd}|j|||S)Nc<|vr |jS|jSr')rr)rrs r.r5z-RevisionMap._get_descendant_nodes..fnCs!g%+++;;&r0c|jSr'rrs r.r5z-RevisionMap._get_descendant_nodes..fnKs'''r0c|jSr'rr:s r.r5z-RevisionMap._get_descendant_nodes..fnPs {{"r0rcheckrrr4z Iterable[str]r)r(rrr=omit_immediate_dependenciesrr5s ` r.rz!RevisionMap._get_descendant_nodes9s? ' ' " (  #.. d%/  r0cB|rdd}ndd}|j||||S)Nc|jSr')_normalized_down_revisionsr:s r.r5z+RevisionMap._get_ancestor_nodes..fn`s555r0c|jSr'rr:s r.r5z+RevisionMap._get_ancestor_nodes..fnes444r0r<r>r?)r(rrr=rr5s r.rzRevisionMap._get_ancestor_nodesWs4  6  5.. d%/  r0c #xK| |j}t}tj}|D]}t |}|j ||r t} |r|j } |r j| | |vr*|j| || D]6} || } | J| j| k7r td|j | 8| |r|s j|j|g} | std|jddjd| Dyw)Nz(Dependency resolution failed; broken mapzRequested revision z) overlaps with other requested revisions rIc34K|]}|jywr'rrs r.rz9RevisionMap._iterate_related_revisions..s%CQajj%Cr) rqr collectionsdequerr"poprrfr9rrrL)r(r5rrr=seentodo target_forr( per_targetrrnext_revoverlapss r.rz&RevisionMap._iterate_related_revisionslsE <%%Du + 1 1 3!$ J ,F KK  U hhjNN3'$;  g*F#F|H#///((F2+FKK)* #$%227;FFH'#OO II%C(%CC ;$ sCD: D:##D:3D:c jdfd |Dchc]}|j}}tj}tt|Dchc]}|j|vs|jc}|j}|Dcgc] }| }}g} d} |r|| } t |D]\} } | | k7s | | vs| } n| |vr"| j | |j| | }|J|jDcgc] }||vr||vr|}}|s|| =|| =t| dz d} n|js5t|jdk(r|d|| <|| j| nG|d|| <|j|dd|d|| <|jfd|ddD|r|rJ| Scc}wcc}wcc}wcc}w)zYield revision ids of a collection of Revision objects in topological sorted order (i.e. revisions always come after their down_revisions and dependencies). Uses the order of keys in _revision_map to sort. chj|gDchc]}|jc}Scc}wr')rrf)rr id_to_revr(s r. get_ancestorsz4RevisionMap._topological_sort..get_ancestorss<119V3D2EF  s/)keyrNrc3.K|] }|ywr'r)rrrSs r.rz0RevisionMap._topological_sort..s048M$/0s)rrSr4Set[str])rqrfrrindex enumerater"removerCmaxrrrrr#)r(rYrJrrKinserted_orderrrancestors_by_idxoutputcurrent_candidate_idx candidatecheck_head_index ancestors candidate_revr heads_to_addrSrRs` @@r.r3zRevisionMap._topological_sortsS&&   %..q ..d001 %*AajjD.@A"((  ANNfM&1NN !%&;?,/0E0I1,M)*KK G GHAM?KA &;< ))>?GG%@LA &;<%,,\!"-=>),q/:))>?)//0 0) or down (steps < 0) the revision tree. :branch_label is used to select branches only when walking up. If the walk goes past the boundaries of the tree and :no_overwalk is True, None is returned, otherwise the walk terminates early. A RevisionError is raised if there is no unambiguous revision to walk to. rr>Nr)r>rzAmbiguous walk)rrSrrangeabsrrurrrrJrrr9) r(startrr no_overwalkinitial_rwalk_upchildrenrets r.rzRevisionMap._walks0( eS !''.GGs5z"! "Aqy&((( $11&-o 7??  $  #66w MH&Hf$!H#11"? $22 H $#,*dw X"#$455qkGC! "F?s3Dc^|yt|tsJdtj|}|r|j \}}}t |}|dk\rA|t d|t|fz|j||||} | t d|| fS|du} | r|rtj|} |j| |} | sUttt|j| } |j| |}|Dcgc]}|r |j n|} }t#| dk(sJ| d}nctj|}|st d|t|fzt#t%|dkDrtj&d |d}|}|j||j)|n|j)|d ||| } | &| rt d|t|fzt d|| fS|j+d \}}}|sd}||j)|fScc}w) aX Parse downgrade command syntax :target to retrieve the target revision and branch label (if any) given the :current_revisions stamp of the database. Returns a tuple (branch_label, target_revision) where branch_label is a string from the command specifying the branch to consider (or None if no branch given), and target_revision is a Revision object which the command refers to. target_revisions is None if the command refers to 'base'. The target may be specified in absolute form, or relative to :current_revisions. NNNz(Expected downgrade target in string formr1Relative revision %s didn't produce %d migrations)rhzWalked too farrzadowngrade -1 from multiple heads is ambiguous; this usage will be disallowed in a future release.r rgrrh)rrS_relative_destinationmatchgroupsrr9rfrrrrrrr_get_all_currentrfrrrr rpartition)r(current_revisionsr(r-rsrsymbolrelativerel_intrrelative_revisioncr_tuple symbol_list all_currentsl_all_currentrrjs r._parse_downgrade_targetz#RevisionMap._parse_downgrade_targetEs$ > C  6 5 6 &++F3 -2\\^ *L&((mG!|>'03;S\2JK jj 6 ! ;'(899#S(($*dN!$##'==1B#C&*&=&=$l'  + +/ #H t/D/DX/N+K.2-D-D +\.N *8+$%/0 Q 6+K+ #;/1444!,Q,0MM:K,L)0"/!8#+S\":!;# s#456: II!+ "31!5(. jj(/))&1!..'3V<" 6! ;(+47?W6NO ,,<==#S((#)"3"3C"8 aLT..v666k+sH*c t|trtj|}nd}|s|j |St j |}|j\}}}t|} | dkDr||sd}|} |r|j|j ||} | s{|j|j|j ||} t| D chc]} | jc} | D chc]} | jD]} | c} } z } | sd} t| dkDr td|j!| d| ||} | td|t#| fz| fS|j!|j%|| ||fS|td| t#| fz|j!||j%|n|j%|d|| | fScc} wcc} } w) aJ Parse upgrade command syntax :target to retrieve the target revision and given the :current_revisions stamp of the database. Returns a tuple of Revision objects which should be iterated/upgraded to. The target may be specified in absolute form, or relative to :current_revisions. Nrr'rz1Ambiguous upgrade from multiple current revisions)rgrrrhrpr rq)rrSrrrsrrrrtrrrrrfrCrr9rrfr)r(rwr(r-rscurrent_revisions_tuprrx relative_strry start_revsactive_on_branchrdowns r._parse_upgrade_targetz!RevisionMap._parse_upgrade_targetss fc ")//7EE%%f- -!% .? @-2\\^* fl|$ a<~,,3)2 !%!8!8**+@A$"J&,0+B+B 44 $ 2 23H I) ,(&+5EFcS\\F,<$',/,J,J%)!% $&  **1Jz?Q&'Kjj$Q-"!- 6 ! ;'03?X2OPv JJ"//7&%1$: ~#,/7X.GH  (/))&1!..'3V<# 6   [Gs G)6G. c |j|||\}}|dk(rd}|t|tsJ|6|jj Dcgc]}||j |} }n7|r|g} n1|j |jDcgc] }t|} }|rt| dkDr|j|j|gdDchc]}|j} }|j | Dchc]}|jc}j| Dcgc] }t|} }t| dk(r td|j |} t|j!| d d } t|j| d } | j#| |r/| j%| j'|j| || s|| vr t)d || | fScc}wcc}wcc}wcc}wcc}w) a Compute the set of current revisions specified by :upper, and the downgrade target specified by :target. Return all dependents of target which are currently active. :inclusive=True includes the target revision in the set rwr(r-r>NrFrrz/Not a valid downgrade target from current headsT)rr@zNothing to drop)rrrrqrrrrrrrr rfrr9rrintersection_updaterrr;)r(r)r*r+r,r-rtarget_revisionrrootsrarJdowngrade_revisionsactive_revisionss r.r1z(RevisionMap._collect_downgrade_revisions+sq )-(D(D##9)E) % o f $"O&*_h*OOO  " --446?s'8'8'@E $%E  --o.E.EFC E CJN 33)),78).4 I ---23cS\\3@@KC E5zQ#E""5)"  & &%),1 '    $ $U $ F  //0@A   & & ++D,D,DU,KL   ''u,((95A A"E))Q4sG7G<H;H&H c|j|||Dcgc] }t|}}t|trd|vr|j d\}} } |j |} | G| j |k(r8t| jdk(sJtt| j}|D chc]} || jvs| }} t|j|ddj||j|} |s tfd| Dr t!||t#| t$usJd| rA| d <|j'|||\} }|sJ|d k(r t%} d}n|f} |j }t|j| ddj| } j)| }|r'|j+d |j|D| r>|s<|j-| Dcgc] }t|c}dd }|j/||t%|fScc}wcc} wcc}w) a Compute the set of required revisions specified by :upper, and the current set of active revisions specified by :lower. Find the difference between the two to compute the required upgrades. :inclusive=True includes the current/lower revisions in the set :implicit_base=False only returns revisions which are downstream of the current/lower revisions. Dependencies from branches with different bases will not be included. rr NrT)r=rc3*K|] }||v ywr'r)rrrequired_node_sets r.rz9RevisionMap._collect_upgrade_revisions..s$%  ( (% sz#current_revisions should be a tuplerr>c32K|]}t|ywr')rrs r.rz9RevisionMap._collect_upgrade_revisions..sOcS)OsF)rrrrS partitionrrfrrnextiterrrrranyr;typerrrrrr)r(r)r*r+r,r-rrbranchrjr needrwcurrent_node_setneedslower_descendentsrs @r.r2z&RevisionMap._collect_upgrade_revisionss*11"''=2)   ) )  eS !cUl ??3/LFAq**62J%**=*=*G:334999d:#;#;<=!(Fd6H6H,HG  $ $t$ %   %.  !..u5% (% " (u5 5 " #u , 1 0 1 , !21!5!=11"''=2FAs J3f}$)G!%(F!   $ $!D %   %! "  ",,-=>  LLOT5G5G5NO O ] $ : :->?cS!?%*!;!   % %&7 8eGn$$a) (l@sH:3H?H?Ict|j|}|j|jt |d|j |S)NTr)rrrrrr)r(rtop_revss r.ruzRevisionMap._get_all_currentsOt))#./  $ $T(^$ $ O --h77r0)roz Callable[[], Iterable[Revision]]r4rBr4Tuple[str, ...])r4r) r_InterimRevisionMapTyperJ Set[Revision]ruTuple[Revision, ...]rwrrzrr4rB)rYCollection[Revision]rrr4rB)F)rfrrr3r4rBr')rrNr4rN)rrSr4r)rOptional[_GetRevArg]r4%Tuple[Optional[_RevisionOrBase], ...])rrNr4Optional[Revision])rrSr4r)rzUnion[str, Tuple[()], None]rrNr4r)rz#Iterable[Optional[_RevisionOrBase]]r4Set[Optional[_RevisionOrBase]])rz Iterable[_TR]r$rNrr3r4zTuple[_TR, ...])r(zOptional[_RevisionOrStr]r)zSequence[_RevisionOrStr]rr3r4r3)rrr4z%Tuple[Tuple[str, ...], Optional[str]])FFTF)r)r2r*r2r,r3r+r3r-r3r4r3r4Iterator[Revision])NFFT) r%Collection[Optional[_RevisionOrBase]]rOptional[_RevisionMapType]r=r3r@r3rr3r4z Iterator[Any])NFT) rrrrr=r3rr3r4r) r5z#Callable[[Revision], Iterable[str]]rrrrr=r3r4r)rYrrJrr4z List[str])NT) rgzOptional[Union[str, Revision]]rrrrNrhr3r4zOptional[_RevisionOrBase])rwr2r(r2r-r3r4z/Tuple[Optional[str], Optional[_RevisionOrBase]])rwr2r(r2r-r3r4rr1) r)r2r*r2r+r3r,r3r-r3r4z*Tuple[Set[Revision], Tuple[Revision, ...]])rrr4r)'r5r6r7__doc__r@rmemoized_propertyrJrurwrzrqrrrrrrrrrrr rrrrrr6rrrr3rrrr1r2rurr0r.rlrl~s$             IIV2@(2@2@$ 2@ # 2@ * 2@ 2@h2-25E2 2*-5E .5-55E5 5.&@-&@5E&@ &@P6%r-1")" "H?/'/ ./b@*&'+@0@$@  @D :  ' "&+   % #    4&+ & (& 4& # &  & P&B'&B .&BX$'+%*#4&#4'#4 #4  #4 !% #4##4 #4P,0,1%)  6 )   &*  #    B,0%)  6 )   #    4 0 /070) 0  0  0df'ff  fX'+ =-==$ =  = # =~v72v7(v7!% v7 9 v7pl2l(l!% l / l\e*&e*'e* e*  e* !% e* Ee*Nc%&c%'c% c%  c% !% c% 4c%J8"8 '8r0rlceZdZUdZeZded< eZded<dZded< dZ ded < dZ ded < dZ d ed < d ed<d ed<e ddZ d d dZd!dZd"dZed#dZed#dZed#dZed$dZed$dZed$dZed$dZed$dZed$dZed$dZy)%raoBase class for revisioned objects. The :class:`.Revision` class is the base of the more public-facing :class:`.Script` object, which represents a migration script. The mechanics of revision management and traversal are encapsulated within :class:`.Revision`, while :class:`.Script` applies this logic to Python files in a version directory. zFrozenSet[str]rrNrSrfzOptional[_RevIdType]rrrVrrrrct|jt}|r*tddj t |d|dy)NzCharacter(s) 'rIz&' not allowed in revision identifier 'r)rr_revision_illegal_charsr9rLr)clsrf illegal_charss r. verify_rev_idzRevision.verify_rev_id.sDH 223JK 99VM23X?  r0c|r"|tj|vr t||"|tj|vr t||j |||_t tj||_t tj||_tj|d|_ t|j|_ yNrr&) rrrcrirrftuple_rev_as_scalarrrrrr)r(rfrrrs r.r@zRevision.__init__7s X})EEx( (  %(dmm 7 + )2 2 8$  0}1MN/ l0KL#'==#K  !9!9:r0cTt|jt|jg}|jr|j d|j|j r|j d|j |j jddj|dS)Nz dependencies=zbranch_labels=(rIrX) reprrfrrr"rrAr5rL)r(argss r.__repr__zRevision.__repr__LsyT]]#T$*<*<%=>    KKT->->@ A    KKd.@.@B C>>22DIIdODDr0c|jj|jg|_|j|jvr,|jj|jg|_yyr')rrrfrr)r(rfs r.rzRevision.add_nextrevTsZ --33X5F5F4GH ==H>> ><<--x/@/@.ABDL ?r0ctjtj|jd|jzSr)r dedupe_tuplerrrrrs r.rzRevision._all_down_revisionsYs7  MM$,,b 9)) *  r0ctjtj|jd|jzS)z|return immediate down revisions for a rev, omitting dependencies that are still dependencies of ancestors. rr&)rrrrrrrs r.rCz#Revision._normalized_down_revisions`s9   MM$,,b 944 5  r0cDtj|jdSr)rrrrrs r.rz"Revision._versioned_down_revisionsks}}T//<|jduxr|jduS)zrReturn True if this :class:`.Revision` is a "real" base revision, e.g. that it has no dependencies either.N)rrrrs r.rzRevision._is_real_bases%!!T)Gd.?.?4.GGr0c2t|jdkDS)a+Return True if this :class:`.Script` is a branch point. A branchpoint is defined as a :class:`.Script` which is referred to by more than one succeeding :class:`.Script`, that is more than one :class:`.Script` has a `down_revision` identifier pointing here. r)rrrrs r.is_branch_pointzRevision.is_branch_points4<< 1$$r0c2t|jdkDS)zzReturn True if this :class:`.Script` is a 'real' branch point, taking into account dependencies as well. r)rrrrs r.rzRevision._is_real_branch_points 4$$%))r0c2t|jdkDS)z6Return True if this :class:`.Script` is a merge point.r)rrrrs r.rzRevision.is_merge_points4112Q66r0rgro) rfrSr%Optional[Union[str, Tuple[str, ...]]]rrrrr4rB)r4rS)rfrr4rBr)r4r3)r5r6r7rrr__annotations__rrfrrr classmethodrr@rrpropertyrrCrrrrrrrrrr0r.rrs(kG^);#,;L..Hc%*.M'.*.L&-#M8",+'66?C?C ;;=;< ; = ;  ;*EC     ==&&++** HH % %**77r0cyr'rr:s r.rrs,/r0cyr'rr:s r.rrs+.r0c2|syt|dk(r|dS|S)Nrr)rr:s r.rrs#  SQ1v  r0c*t|tsJ|Sr')rrr:s r.rrs c8 $$ $ Jr0)rrBr4rB)rzUnion[Tuple[_T, ...], List[_T]]r4z#Union[_T, Tuple[_T, ...], List[_T]])rzOptional[Sequence[_T]]r4zUnion[_T, Sequence[_T], None])rrr4r)9 __future__rrGr typingrrrrrr r r r r rrrrrrrrr sqlalchemyrrrrrrS _RevIdType _GetRevArgr2_RevisionOrStr_RevisionOrBaserrrrcompilerrrr%rr9r;rGrPrUr_rcrirlrrrrr0r.rs "  ' 3S 5c?2 3  Xc] SM  U38_d :;z3'56sJ/dCr23Xj5IIJ T] e8N34" #DE.JJ I   M   M !m!  M $m$%=%#4l#A8A8H,d7d7N / / . (.(. .  "r0