Ë
    åhiZ  ã                   óB   — d Z ddlmZ ddlmZ ddlmZ  G d„ de«      Zy)zá
altgraph.ObjectGraph - Graph of objects with an identifier
==========================================================

A graph of objects that have a "graphident" attribute.
graphident is the key for the object in the graph
é    )Ú
GraphError)ÚGraph)Úfilter_stackc                   óŽ   — e Zd ZdZdd„Zd„ Zdd„Zd„ Zd„ Zd„ Z	d	„ Z
d
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zdd„Zd„ Zd„ Zd„ Zd„ Zy)ÚObjectGraphzv
    A graph of objects that have a "graphident" attribute.
    graphident is the key for the object in the graph
    Nc                 óx   — |€
t        «       }| | _        || _        || _        d| _        |j                  | d «       y ©Nr   )r   Ú
graphidentÚgraphÚdebugÚindentÚadd_node)Úselfr   r   s      ú@C:\des-py\Monitor\venv\Lib\site-packages\altgraph/ObjectGraph.pyÚ__init__zObjectGraph.__init__   s8   € Øˆ=Ü“GˆEØˆŒØˆŒ
ØˆŒ
ØˆŒØ�‰�t˜TÕ"ó    c                 ó4   — dt        | «      j                  ›d�S )Nú<ú>)ÚtypeÚ__name__)r   s    r   Ú__repr__zObjectGraph.__repr__   s   � Ü˜d›×,Ó,Ð.Ð.r   c                 óf   — |€| }| j                  |«      }| j                  j                  ||¬«      S )z–
        Iterate over the subgraph that is entirely reachable by condition
        starting from the given start node or the ObjectGraph root
        )ÚstartÚ	condition)ÚgetRawIdentr   Úiterdata)r   r   r   s      r   ÚflattenzObjectGraph.flatten    s8   € ð
 ˆ=ØˆEØ× Ñ  Ó'ˆØ�z‰z×"Ñ"¨¸)Ð"ÓDÐDr   c              #   ó¤   K  — | j                   D ]=  }| j                   j                  |«      }|€Œ!| j                   j                  |«      –— Œ? y ­w©N)r   Ú	node_data)r   ÚidentÚnodes      r   ÚnodeszObjectGraph.nodes*   sH   è ø€ Ø—Z‘Zò 	2ˆEØ—:‘:×'Ñ'¨Ó.ˆDØÑØ—j‘j×*Ñ*¨5Ó1Ó1ñ	2ùs
   ‚-A° Ac                 óœ   ‡ — |€‰ }‰ j                  |«      }‰ j                  j                  |«      \  }}}}ˆ fd„} ||d«       ||d«      fS )Nc              3   óž   •K  — t        «       }ˆfd„| D «       D ]0  }||   }||vsŒ‰j                  |«      –— |j                  |«       Œ2 y ­w)Nc              3   óT   •K  — | ]  }‰j                   j                  |«      –— Œ! y ­wr    )r   Údescribe_edge)Ú.0Úer   s     €r   ú	<genexpr>z<ObjectGraph.get_edges.<locals>.iter_edges.<locals>.<genexpr>8   s    øè ø€ ÒA¸˜Ÿ
™
×0Ñ0°×3ÑAùs   ƒ%()ÚsetÚfindNodeÚadd)ÚlstÚnÚseenÚtplr"   r   s        €r   Ú
iter_edgesz)ObjectGraph.get_edges.<locals>.iter_edges6   sM   øè ø€ Ü“5ˆDÛA¸SÔAò $�Ø˜A™�Ø Ò$ØŸ-™-¨Ó.Ò.Ø—H‘H˜U•Oñ	$ùs
   ƒ"A¦'Aé   é   )r   r   Údescribe_node)r   r#   r   Ú_ÚoutrawÚincrawr3   s   `      r   Ú	get_edgeszObjectGraph.get_edges0   sZ   ø€ Øˆ<ØˆDØ× Ñ  Ó&ˆØ#Ÿz™z×7Ñ7¸Ó>Ñˆˆ1ˆf�fô	$ñ ˜& !Ó$¡j°¸Ó&;Ð;Ð;r   c                 ó¼   — |€| }| j                  |«      }| j                  |«      }| j                  j                  ||«      }| j                  j                  |«      S r    )r   r   Úedge_by_nodeÚ	edge_data)r   ÚfromNodeÚtoNoder   ÚstopÚedges         r   ÚedgeDatazObjectGraph.edgeData@   sX   € ØÐØˆHØ× Ñ  Ó*ˆØ×Ñ Ó'ˆØ�z‰z×&Ñ& u¨dÓ3ˆØ�z‰z×#Ñ# DÓ)Ð)r   c                 óÀ   — |€| }| j                  |«      }| j                  |«      }| j                  j                  ||«      }| j                  j                  ||«       y r    )r   r   r<   Úupdate_edge_data)r   r>   r?   rB   r   r@   rA   s          r   ÚupdateEdgeDatazObjectGraph.updateEdgeDataH   sW   € ØÐØˆHØ× Ñ  Ó*ˆØ×Ñ Ó'ˆØ�z‰z×&Ñ& u¨dÓ3ˆØ�
‰
×#Ñ# D¨(Õ3r   c                 ó  — t        | j                  | |«      \  }}}|D ]#  \  }}| j                  j                  ||d¬«       Œ% |D ]  }| j                  j                  |«       Œ t	        |«      dz
  t	        |«      t	        |«      fS )zþ
        Filter the ObjectGraph in-place by removing all edges to nodes that
        do not match every filter in the given filter list

        Returns a tuple containing the number of:
            (nodes_visited, nodes_removed, nodes_orphaned)
        Úorphan©r=   é   )r   r   Úadd_edgeÚ	hide_nodeÚlen)r   ÚfiltersÚvisitedÚremovesÚorphansÚ	last_goodÚtailr#   s           r   ÚfilterStackzObjectGraph.filterStackP   sŽ   € ô %1°·±¸TÀ7Ó$KÑ!ˆ�˜'à&ò 	E‰OˆI�tØ�J‰J×Ñ 	¨4¸8ÐÕDð	Eð ò 	'ˆDØ�J‰J× Ñ  Õ&ð	'ô �7‹|˜aÑ¤ W£¬s°7«|Ð;Ð;r   c                 ób   — | j                  |«      }|�| j                  j                  |«       yy)zC
        Remove the given node from the graph if it exists
        N)ÚgetIdentr   rK   ©r   r#   r"   s      r   Ú
removeNodezObjectGraph.removeNodeb   s/   € ð —‘˜dÓ#ˆØÐØ�J‰J× Ñ  Õ'ð r   c                 óÒ   — |€| }| j                  |«      }| j                  |«      }|�?|�<	 | j                  j                  ||«      }|€y| j                  j                  |«       Œ;yy)z:
        Remove all edges from fromnode to tonode
        N)rU   r   r<   Ú	hide_edge)r   ÚfromnodeÚtonodeÚ	fromidentÚtoidentrA   s         r   ÚremoveReferencezObjectGraph.removeReferencej   sv   € ð ÐØˆHØ—M‘M (Ó+ˆ	Ø—-‘- Ó'ˆØÐ  WÐ%8ØØ—z‘z×.Ñ.¨y¸'ÓB�Ø�<ØØ—
‘
×$Ñ$ TÔ*ð	 ð &9Ð r   c                 ól   — | j                  |«      }|�|S | j                  |«      }|€y|j                  S )z5
        Get the graph identifier for a node
        N)r   r-   r
   rV   s      r   rU   zObjectGraph.getIdenty   s?   € ð × Ñ  Ó&ˆØÐØˆLØ�}‰}˜TÓ"ˆØˆ<ØØ�‰Ðr   c                 ó,   — || u r|S t        |dd«      }|S )z6
        Get the identifier for a node object
        r
   N)ÚgetattrrV   s      r   r   zObjectGraph.getRawIdent…   s#   € ð �4‰<ØˆKÜ˜˜l¨DÓ1ˆØˆr   c                 ó(   — | j                  |«      d uS r    )r-   ©r   r#   s     r   Ú__contains__zObjectGraph.__contains__Ž   s   € Ø�}‰}˜TÓ"¨$Ð.Ð.r   c                 ó‚   — | j                  |«      }|€|}	 | j                  j                  |«      S # t        $ r Y yw xY w)z,
        Find the node on the graph
        N)r   r   r!   ÚKeyErrorrV   s      r   r-   zObjectGraph.findNode‘   sJ   € ð × Ñ  Ó&ˆØˆ=ØˆEð	Ø—:‘:×'Ñ'¨Ó.Ð.øÜò 	Ùð	ús   —2 ²	>½>c                 óà   — | j                  dd|«       	 | j                  j                  |j                  «       y# t        $ r) | j                  j                  |j                  |«       Y yw xY w)z@
        Add a node to the graph referenced by the root
        é   ÚaddNodeN)Úmsgr   Úrestore_noder
   r   r   rc   s     r   ri   zObjectGraph.addNode�   sV   € ð 	�‰��I˜tÔ$ð	7Ø�J‰J×#Ñ# D§O¡OÕ4øÜò 	7Ø�J‰J×Ñ §¡°Ö6ð	7ús   •%; »/A-Á,A-c                 óÀ   — |€| }| j                  |«      | j                  |«      }}|�|€y| j                  dd|||«       | j                  j                  |||¬«       y)z<
        Create a reference from fromnode to tonode
        Nrh   ÚcreateReferencerH   )rU   rj   r   rJ   )r   rZ   r[   r=   r\   r]   s         r   rm   zObjectGraph.createReference¨   se   € ð ÐØˆHØ!Ÿ]™]¨8Ó4°d·m±mÀFÓ6K�7ˆ	ØÐ  ØØ�‰�Ð% x°¸ÔCØ�
‰
×Ñ˜I w¸)ÐÕDr   c                 óf   — | j                  |«      }|€ ||g|¢­i |¤Ž}| j                  |«       |S )zl
        Add a node of type cls to the graph if it does not already exist
        by the given name
        )r-   ri   )r   ÚclsÚnameÚargsÚkwÚms         r   Ú
createNodezObjectGraph.createNode´   s;   € ð
 �M‰M˜$ÓˆØˆ9Ù�DÐ&˜4Ò& 2Ñ&ˆAØ�L‰L˜ŒOØˆr   c                 ó¢   — |rM|| j                   k  r=t        d| j                  z  ›|›ddj                  t	        t
        |«      «      ›�«       yyy)z<
        Print a debug message with the given level
        z  ú N)r   Úprintr   ÚjoinÚmapÚrepr©r   ÚlevelÚsrq   s       r   rj   zObjectGraph.msg¿   s@   € ñ �˜$Ÿ*™*Ò$Ü˜t d§k¡kÒ1²1°c·h±h¼sÄ4È»Ô6OÐPÕQð %ˆ1r   c                 ót   — || j                   k  r) | j                  ||g|¢­Ž  | j                  dz   | _        yy)z2
        Print a debug message and indent
        rI   N)r   rj   r   r{   s       r   ÚmsginzObjectGraph.msginÆ   s9   € ð �D—J‘JÒØˆD�H‰H�U˜AÐ% Ó%ØŸ+™+¨™/ˆD�Kð r   c                 ót   — || j                   k  r)| j                  dz
  | _         | j                  ||g|¢­Ž  yy)z2
        Dedent and print a debug message
        rI   N)r   r   rj   r{   s       r   ÚmsgoutzObjectGraph.msgoutÎ   s9   € ð �D—J‘JÒØŸ+™+¨™/ˆDŒKØˆD�H‰H�U˜AÐ% Ô%ð r   r	   )NNr    )r   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r$   r:   rB   rE   rS   rW   r^   rU   r   rd   r-   ri   rm   rt   rj   r   r�   © r   r   r   r      sn   „ ñó
#ò/óEò2ò<ò *ò4ò<ò$(ò+ò
òò/ò
ò	7ó
Eò	òRò*ó&r   r   N)	r„   Úaltgraphr   Úaltgraph.Graphr   Úaltgraph.GraphUtilr   Úobjectr   r…   r   r   ú<module>rŠ      s#   ðñõ  Ý  Ý +ôF&�&õ F&r   