File: //usr/local/lib/python3.9/site-packages/celery/utils/__pycache__/graph.cpython-39.pyc
a
X>hQ# � @ sn d Z ddlmZ ddlmZ ddlmZmZ dZG dd� d�Z G dd � d e
�ZG d
d� d�ZG dd
� d
�Z
dS )z Dependency graph implementation.� )�Counter)�dedent)�bytes_to_str�safe_str)�DOT�
CycleError�DependencyGraph�GraphFormatterc @ s6 e Zd ZdZed�ZdZdZdZdZ ddd �Z
d
ZdS )r z$Constants related to the dot format.z=
{IN}{type} {id} {{
{INp}graph [{attrs}]
z{name}={value}z{INp}"{0}" [{attrs}]z {INp}"{0}" {dir} "{1}" [{attrs}]z, z--z->)�graph�digraphz{IN}}}N)�__name__�
__module__�__qualname__�__doc__r �HEAD�ATTR�NODE�EDGE�ATTRSEP�DIRS�TAIL� r r �</usr/local/lib/python3.9/site-packages/celery/utils/graph.pyr
s
r c @ s e Zd ZdZdS )r z)A cycle was detected in an acyclic graph.N)r r
r r r r r r r s r c @ s� e Zd ZdZd+dd�Zdd� Zdd� Zd d
� Zdd� Zd
d� Z dd� Z
dd� Zdd� Zdd� Z
d,dd�Zdd� Zdd� Zdd� Zdd � Zd!d"� Zd#d$� Ze ZZd%d&� Zd-d)d*�ZdS ).r a6 A directed acyclic graph of objects and their dependencies.
Supports a robust topological sort
to detect the order in which they must be handled.
Takes an optional iterator of ``(obj, dependencies)``
tuples to build the graph from.
Warning:
Does not support cycle detection.
Nc C s( |pt � | _i | _|d ur$| �|� d S �N)r � formatter�adjacent�update)�self�itr r r r �__init__* s zDependencyGraph.__init__c C s | j �|g � dS )zAdd an object to the graph.N)r �
setdefault�r �objr r r �add_arc0 s zDependencyGraph.add_arcc C s | | � |� dS )z]Add an edge from object ``A`` to object ``B``.
I.e. ``A`` depends on ``B``.
N)�append)r �A�Br r r �add_edge4 s zDependencyGraph.add_edgec C s | j �|j � dS )zAdd nodes from another graph.N)r r )r r
r r r �connect; s zDependencyGraph.connectc C s~ t � }| �� }dd� |D �}|D ]}|�|� q | D ]6}|| }| | D ] }|| }||krH|�||� qHq4dd� |�� D �S )z�Sort the graph topologically.
Returns:
List: of objects in the order in which they must be handled.
c S s i | ]}|D ]
}||�qqS r r )�.0� component�noder r r �
<dictcomp>H s z+DependencyGraph.topsort.<locals>.<dictcomp>c S s g | ]}|d �qS )r r )r) �tr r r �
<listcomp>S � z+DependencyGraph.topsort.<locals>.<listcomp>)r � _tarjan72r# r'