Qf%^ddlmZddgZdZdZGddZGddeZGd dZy ) ) GenericAliasTopologicalSorter CycleErrorceZdZdZdZy) _NodeInfonode npredecessors successorsc.||_d|_g|_yNrr )selfr s //opt/alt/python312/lib64/python3.12/graphlib.py__init__z_NodeInfo.__init__ s N)__name__ __module__ __qualname__ __slots__rrrr r s 5I rr ceZdZdZy)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   rc^eZdZdZd dZdZdZdZdZdZ d Z d Z d Z d Z eeZy)rzFProvides functionality to topologically sort a graph of hashable nodesNci|_d|_d|_d|_|,|j D]\}}|j |g|yyr) _node2info _ready_nodes _npassedout _nfinisheditemsadd)rgraphr predecessorss rrzTopologicalSorter.__init__,sS   &+kkm"l- -'4 rct|jj|x}t|x|j|<}|SN)rgetr )rr results r _get_nodeinfozTopologicalSorter._get_nodeinfo6s8oo))$/ /F 8-6t_ ? ?!OO224 4q18LAFF4   " 3e< <  s A> A>c|j tdt|j}|j}|D]}t||_|jj |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. prepare() must be called first) rr+tupler _NODE_OUTr clearrr,)rr(n2ir s r get_readyzTopologicalSorter.get_readyls{    $=> >t(()ooD&/CI # ! CK' rc|j td|j|jkxst |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. r8)rr+r rboolrs r is_activezTopologicalSorter.is_activesA    $=> >!1!11LT$:K:K5LLrc"|jSr&)rAr@s r__bool__zTopologicalSorter.__bool__s~~rc$|j td|j}|D]}|j|x}td|d|j}|t k7r9|dk\rtd|d|t k(rtd|dJd|d|t |_|jD]G}||}|xjd zc_|jdk(s-|jj|I|xjd z c_ y) 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". Nr8znode z was not added using add()rz% was not passed out (still not ready)z was already marked donez: unknown status ) rr+rr'r r: _NODE_DONEr r-r )rnodesr<r r.stat successorsuccessor_infos rdonezTopologicalSorter.dones.    $=> >ooD GGDM)2 50J!KLL))Dy 19$x'LMZ'$uTH4L%MNNIE$1B4&"II5&0H "&00 !$Y,,1,!//14%%,,Y7 1 OOq O9rc|j}g}g}t}i}|D]}||vr ||vr||vro|||d|gzcS|j||jt ||j j t|||<|j||r |d}ny#t$r$||j=|jYnwxYw|rC8)Nr) rsetr"r-iterr __next__r, StopIterationpop)rr<stackitstackseen node2stackir s rr3zTopologicalSorter._find_cyclesoou Dt|4<{*$[%6%89TFBBHHTNNN4D (<(<#=#F#FG(+E K%LL&&*wr{} / 8 )&' 4 & s" B11*CCc#K|j|jr;|j}|Ed{|j||jr:yy7&w)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)r6rAr=rK)r node_groups r static_orderzTopologicalSorter.static_ordersM nn)J! ! ! DIIz "nn !s6A!A#A!A!r&)rrrrrr)r"r6r=rArCrKr3rX classmethodr__class_getitem__rrrrr)sGP. .6=,4 M -!^#J #$L1rN) typesr__all__r:rFr r+rrrrrr]s>  -   "    Q2Q2r