
    CgS                         d dl mZ ddlmZmZ d dlmZ d dlmZ  G d de      Z	 edg d	      Z
d
 Zd Z G d de	      Zd Zy)    )unicode_literals   )get_hashget_hash_int)object)
namedtuplec                   B    e Zd ZdZd Zd Zd Zed        Zed        Z	y)DagNodea  Node in a directed-acyclic graph (DAG).

    Edges:
        DagNodes are connected by edges.  An edge connects two nodes with a label for each side:
         - ``upstream_node``: upstream/parent node
         - ``upstream_label``: label on the outgoing side of the upstream node
         - ``downstream_node``: downstream/child node
         - ``downstream_label``: label on the incoming side of the downstream node

        For example, DagNode A may be connected to DagNode B with an edge labelled "foo" on A's side, and "bar" on B's
        side:

           _____               _____
          |     |             |     |
          |  A  >[foo]---[bar]>  B  |
          |_____|             |_____|

        Edge labels may be integers or strings, and nodes cannot have more than one incoming edge with the same label.

        DagNodes may have any number of incoming edges and any number of outgoing edges.  DagNodes keep track only of
        their incoming edges, but the entire graph structure can be inferred by looking at the furthest downstream
        nodes and working backwards.

    Hashing:
        DagNodes must be hashable, and two nodes are considered to be equivalent if they have the same hash value.

        Nodes are immutable, and the hash should remain constant as a result.  If a node with new contents is required,
        create a new node and throw the old one away.

    String representation:
        In order for graph visualization tools to show useful information, nodes must be representable as strings.  The
        ``repr`` operator should provide a more or less "full" representation of the node, and the ``short_repr``
        property should be a shortened, concise representation.

        Again, because nodes are immutable, the string representations should remain constant.
    c                     t               )z#Return an integer hash of the node.NotImplementedErrorselfs    S/var/www/it7/html/youtubeDownloader/venv/lib/python3.12/site-packages/ffmpeg/dag.py__hash__zDagNode.__hash__.       !##    c                     t               )zTCompare two nodes; implementations should return True if (and only if) hashes match.r   r   others     r   __eq__zDagNode.__eq__2   r   r   c                     t               )z0Return a full string representation of the node.r   r   s     r   __repr__zDagNode.__repr__6   r   r   c                     t               )z4Return a partial/concise representation of the node.r   r   s    r   
short_reprzDagNode.short_repr:   s     "##r   c                     t               )a  Provides information about all incoming edges that connect to this node.

        The edge map is a dictionary that maps an ``incoming_label`` to ``(outgoing_node, outgoing_label)``.  Note that
        implicity, ``incoming_node`` is ``self``.  See "Edges" section above.
        r   r   s    r   incoming_edge_mapzDagNode.incoming_edge_map?   s     "##r   N)
__name__
__module____qualname____doc__r   r   r   propertyr   r    r   r   r
   r
      s?    #J$$$ $ $ $ $r   r
   DagEdge)downstream_nodedownstream_labelupstream_nodeupstream_labelupstream_selectorc           	      ~    g }t        |j                               D ]  \  }}|\  }}}|t        | ||||      gz  }  |S N)listitemsr$   )r%   r   edgesr&   upstream_infor'   r(   r)   s           r   get_incoming_edgesr0   U   se    E+/0A0G0G0I+J 

'-;H8~'8 !
 	


 Lr   c           
          g }t        |j                               D ]%  \  }}|D ]  }|\  }}}|t        ||| ||      gz  } ' |S r+   )sortedr-   r$   )	r'   outgoing_edge_mapr.   r(   downstream_infosdownstream_infor%   r&   downstream_selectors	            r   get_outgoing_edgesr7   e   su    E,23D3J3J3L,M ((/ 
	OETBO-/B#$!"' E
	 Lr   c                       e Zd ZdZed        Zed        Zd Zd Zd Z	d Z
ed        Zdd	Zd
 Zed        Zed        Zed        Zy)KwargReprNodez?A DagNode that can be represented as a set of args+kwargs.
    c                     g }t        | j                  j                               D ]+  \  }}|\  }}}|||||fD cg c]  }t        |       c}z  }- |S c c}w r+   )r,   r   r-   hash)r   hashesr&   r/   r'   r(   r)   xs           r   __upstream_hasheszKwargReprNode.__upstream_hashesz   s}    /3D4J4J4P4P4R/S 
	+m?L<M>+< %!"%	 Q F
	 s   Ac                 J    | j                   | j                  d}t        |      S )N)argskwargs)r@   rA   r   )r   propss     r   __inner_hashzKwargReprNode.__inner_hash   s    dkk:r   c                 L    | j                   | j                  gz   }t        |      S r+   )_KwargReprNode__upstream_hashes_KwargReprNode__inner_hashr   )r   r<   s     r   
__get_hashzKwargReprNode.__get_hash   s&    ''4+<+<*==F##r   c                 f    || _         || _        || _        || _        | j	                         | _        y r+   )!_KwargReprNode__incoming_edge_mapnamer@   rA   _KwargReprNode__get_hash_KwargReprNode__hash)r   r   rJ   r@   rA   s        r   __init__zKwargReprNode.__init__   s-    #4 		oo'r   c                     | j                   S r+   )rL   r   s    r   r   zKwargReprNode.__hash__   s    {{r   c                 0    t        |       t        |      k(  S r+   )r;   r   s     r   r   zKwargReprNode.__eq__   s    DzT%[((r   c                 N    dj                  t        t        |                   d d S )Nz{:x}   )formatabsr;   r   s    r   
short_hashzKwargReprNode.short_hash   s     }}Sd_-cr22r   c           	         | j                   D cg c]  }dj                  |       }}|t        | j                        D cg c]!  }dj                  || j                  |         # c}z  }dj                  | j                  dj                  |            }|r|dj                  | j                        z  }|S c c}w c c}w )Nz{!r}z{}={!r}z{}({})z, z <{}>)r@   rR   r2   rA   rJ   joinrT   )r   include_hashargformatted_propskeyouts         r   	long_reprzKwargReprNode.long_repr   s    9=C#6==-CC?Edkk?R
8;IS$++c"23
 	
 oodii?)CD7>>$//22C
 D
s   B9&B>c                 "    | j                         S r+   )r\   r   s    r   r   zKwargReprNode.__repr__   s    ~~r   c                 .    t        | | j                        S r+   )r0   r   r   s    r   incoming_edgeszKwargReprNode.incoming_edges   s    !$(>(>??r   c                     | j                   S r+   )rI   r   s    r   r   zKwargReprNode.incoming_edge_map   s    '''r   c                     | j                   S r+   )rJ   r   s    r   r   zKwargReprNode.short_repr   s    yyr   N)T)r   r   r    r!   r"   rE   rF   rK   rM   r   r   rT   r\   r   r_   r   r   r#   r   r   r9   r9   v   s        $() 3 3  @ @ ( (  r   r9   c                     g g i 	 dfd	| D cg c]  }|d f }}|r!|j                         \  }} ||d d        |r!fS c c}w )Nc                    | v rt        d      |7	j                  | i       }|j                  |g       }||||fgz  }|||<   |	| <   | 
vrj                  |        | j                  D ]@  } |j                  |j
                  |j                  |j                  |j                         B j                  |        
j                  |        y y )NzGraph is not a DAG)
RuntimeErrorgetappendr_   r'   r(   r%   r&   r)   remove)r'   r(   r%   r&   r6   r3   outgoing_edge_infosedgemarked_nodesoutgoing_edge_mapssorted_nodesvisits           r   rm   ztopo_sort.<locals>.visit   s     L(344& 2 6 6}b I"3"7"7"K "24GH$  1Dn-0A}-,.%44 &&''(())** .. -r   r+   )pop)	downstream_nodesnodeunmarked_nodesr'   r(   rj   rk   rl   rm   s	        @@@@r   	topo_sortrr      sz    LL !/ /@ 0@@ttTl@N@
(6(:(:(<%~m^T48  +++	 As   AN)
__future__r   _utilsr   r   builtinsr   collectionsr   r
   r$   r0   r7   r9   rr   r#   r   r   <module>rw      sP    ' *  ">$f >$B 	 "EG EP),r   