Vc%rddlmZddgZdZdZGddZGddeZGd dZd S) ) GenericAliasTopologicalSorter CycleErrorceZdZdZdZdS) _NodeInfonode npredecessors successorsc0||_d|_g|_dSNrr )selfr s !/usr/lib64/python3.11/graphlib.py__init__z_NodeInfo.__init__ s  N)__name__ __module__ __qualname__ __slots__rrrr r s(5I     rr ceZdZdZdS)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__rrrrrs   DrcfeZdZdZd dZdZdZdZdZdZ d Z d Z d Z d Z eeZdS)rzFProvides functionality to topologically sort a graph of hashable nodesNci|_d|_d|_d|_|(|D]\}}|j|g|RdSdSr) _node2info _ready_nodes _npassedout _nfinisheditemsadd)rgraphr predecessorss rrzTopologicalSorter.__init__,su   .&+kkmm . ."l- ----- . . . .rcp|j|x}t|x|j|<}|SN)rgetr )rr results r _get_nodeinfozTopologicalSorter._get_nodeinfo6s;o))$// /F =-6t__ z-TopologicalSorter.prepare..as6   18L F   rznodes are in a cycle)rr+rvalues _find_cycler)rcycles rpreparezTopologicalSorter.prepareVs   @>?? ?   O2244     ""  =4e<< < = =rc|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+tupler _NODE_OUTr clearrr,)rr(n2ir s r get_readyzTopologicalSorter.get_readyls   ?=>> >t())o 0 0D&/CI # # !!! CKK' rcv|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+r rboolrs r is_activezTopologicalSorter.is_actives>   ?=>> >!11LT$:K5L5LLrc*|Sr&)rDrCs r__bool__zTopologicalSorter.__bool__s~~rc|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 ) rr+rr'r r= _NODE_DONEr r-r )rnodesr?r r.stat successorsuccessor_infos rdonezTopologicalSorter.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 ! !rc|j}g}g}t}i}|D]}||vr ||vr||vr|||d|gzcSnn|||t ||jjt|||<|||rM |d}n<#t$r,|| =| YnwxYw|MnތdS)NTr) rsetr"r-iterr __next__r, StopIterationpop)rr?stackitstackseen node2stackir s rr7zTopologicalSorter._find_cycles[ouu   Dt|  4< '{*C$[%6%8%89TFBBBBCHHTNNNNN4D (<#=#=#FGGG(+E K%LL&&&&*wr{}}(&&&' 4 & / .ts6C3C=<C=c#K||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)r9rDr@rN)r node_groups r static_orderzTopologicalSorter.static_orders nn #))J! ! ! ! ! ! ! ! DIz " "nn # # # # #rr&)rrrrrr)r"r9r@rDrFrNr7r[ classmethodr__class_getitem__rrrrr)sPP.... ...6===,4 M M M   -!-!-!^###J # # #$ L11rN) typesr__all__r=rIr r+rrrrrr`s  -   "          Q2Q2Q2Q2Q2Q2Q2Q2Q2Q2r