Vc%csrddlmZddgZdZdZGddZGddeZGd dZd S) ) GenericAliasTopologicalSorter CycleErroricseZdZdZdZdS) _NodeInfonode npredecessors successorscs0||_d|_g|_dSNrr)selfr !/usr/lib64/python3.11/graphlib.py__init__z_NodeInfo.__init__ s  N)__name__ __module__ __qualname__Z __slots__rrr rr s(5I     rrcseZdZdZdS)raCSubclass of ValueError raised by TopologicalSorter.prepare if cycles exist in the working graph. If multiple cycles exist, only one undefined choice among them will be reported and included in the exception. The detected cycle can be accessed via the second element in the *args* attribute of the exception instance and consists in a list of nodes, such that each node is, in the graph, an immediate predecessor of the next node in the list. In the reported list, the first and the last node will be the same, to make it clear that it is cyclic. N)rrr__doc__rrr rrs   DrcsfeZdZdZd dZdZdZdZdZdZ d Z d Z d Z d Z eeZdS)rzFProvides functionality to topologically sort a graph of hashable nodesNcsi|_d|_d|_d|_|(|D]\}}|j|g|RdSdSr ) _node2info _ready_nodes _npassedout _nfinishedZitemsadd)r Zgraphr predecessors r rzTopologicalSorter.__init__,su   .&+kkmm . ."l- ----- . . . .rcsp|j|x}t|x|j|<}|SN)rgetr)r rresults r _get_nodeinfozTopologicalSorter._get_nodeinfo6s;o))$// /F =-6t__ z-TopologicalSorter.prepare..as6   18L F   rznodes are in a cycle)rr rZvalues _find_cycler)r Zcycler r preparezTopologicalSorter.prepareVs   @>?? ?   O2244     ""  =4e<< < = =rcs|jtdt|j}|j}|D]}t||_|j|xjt|z c_|S)aReturn a tuple of all the nodes that are ready. Initially it returns all nodes with no predecessors; once those are marked as processed by calling "done", further calls will return all new nodes that have all their predecessors already processed. Once no more progress can be made, empty tuples are returned. Raises ValueError if called without calling "prepare" previously. Nprepare() must be called first) rr Ztupler _NODE_OUTrZclearrr!)r rn2irrr get_readyzTopologicalSorter.get_readyls   ?=>> >t())o 0 0D&/CI # # !!! CKK' rcsv|jtd|j|jkpt |jS)aReturn ``True`` if more progress can be made and ``False`` otherwise. Progress can be made if cycles do not block the resolution and either there are still nodes ready that haven't yet been returned by "get_ready" or the number of nodes marked "done" is less than the number that have been returned by "get_ready". Raises ValueError if called without calling "prepare" previously. Nr&)rr rrZboolr  r is_activezTopologicalSorter.is_actives>   ?=>> >!11LT$:K5L5LLrcs*|Sr)r,r*r+r __bool__zTopologicalSorter.__bool__s~~rcs|jtd|j}|D]}||x}td|d|j}|t krG|dkrtd|d|t krtd|dJd|d |t |_|jD]?}||}|xjd zc_|jdkr|j|@|xj d z c_ dS) aMarks a set of nodes returned by "get_ready" as processed. This method unblocks any successor of each node in *nodes* for being returned in the future by a call to "get_ready". Raises :exec:`ValueError` if any node in *nodes* has already been marked as processed by a previous call to this method, if a node was not added to the graph by using "add" or if called without calling "prepare" previously or if node has not yet been returned by "get_ready". Nr&znode z was not added using add()rz% was not passed out (still not ready)z was already marked doneFz: unknown status i) rr rrrr' _NODE_DONEr r"r)r Znodesr(rr#ZstatZ successorZsuccessor_infos r donezTopologicalSorter.donesu   ?=>> >o ! !D GGDMM) M !K!K!K!KLLL)Dy  J19J$MMMMZ'J$%MT%M%M%MNNNI"I$"I"I4"I"IIII&0H "&0 8 8 !$Y,,1,,!/148%,,Y777 OOq OOO9 ! !rcs|j}g}g}t}i}|D]}||vr ||vr||vr|||d|gzcSnn|||t ||jjt|||<|||rM |d}n<#t$r,|| =| YnwxYw|MnތdS)NTr) rZsetrr"Ziterr Z__next__r!Z StopIterationZpop)r r(ZstackZitstackZseenZ node2stackirs r r$zTopologicalSorter._find_cycles[ouu   Dt|  4< '{*C$[%6%8%89TFBBBBCHHTNNNNN4D (<#=#=#FGGG(+E K%LL&&&&*wr{}}(&&&' 4 & / .ts6C3C=<C=c#sK||r<|}|Ed{V|j||:dSdS)aQReturns an iterable of nodes in a topological order. The particular order that is returned may depend on the specific order in which the items were inserted in the graph. Using this method does not require to call "prepare" or "done". If any cycle is detected, :exc:`CycleError` will be raised. N)r%r,r)r/)r Z node_groupr r static_orderzTopologicalSorter.static_orders nn #))J! ! ! ! ! ! ! ! DIz " "nn # # # # #rr)rrrrrrrr%r)r,r-r/r$r0Z classmethodrZ__class_getitem__rrr rr)sPP.... ...6===,4 M M M   -!-!-!^###J # # #$ L11rN) ZtypesrZ__all__r'r.rr rrrrr r1s  -   "          Q2Q2Q2Q2Q2Q2Q2Q2Q2Q2r