o ʎ_@s$GdddeZddZddZdS)c@s eZdZdS)CyclicDependencyErrorN)__name__ __module__ __qualname__rr?/usr/lib/python3/dist-packages/django/utils/topological_sort.pyrsrc#sn|}|r5dd|Ds#tdddd|DVfdd|D}|sd Sd S) ag Variation of Kahn's algorithm (1962) that returns sets. Take a dependency graph as a dictionary of node => dependencies. Yield sets of items in topological order, where the first set contains all nodes without dependencies, and each following set contains all nodes that may depend on the nodes only in the previously yielded sets. cSsh|]\}}|s|qSrr).0nodedepsrrr sz+topological_sort_as_sets..zCyclic dependency in graph: {}z, css|]}t|VqdSN)repr)rxrrr sz+topological_sort_as_sets..cs"i|] \}}|vr||qSrr)rr dependenciescurrentrr s z,topological_sort_as_sets..N)copyitemsrformatjoin)dependency_graphtodorrrtopological_sort_as_setss   rcCs2g}t|D]}|D] }||vr||q q|Sr )rappend)nodesrresultlayerrrrrstable_topological_sorts  rN) ValueErrorrrrrrrrs