Ë
    þI¶d-0  ã                   ó    — d dl Z d dlZd dlmZ 	 	 dd„Z G d„ de«      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d„Zd„ Zy)é    N)Ú	dot_graphc                 ó  — t        ||fd|i|¤Ž}|r| d|j                  dd«      z   z  } t        j                  j	                  |d| z  «      }|� |d|z  «       t        |d«      }	|	j                  |«       |	j                  «        y )NÚtitleÚ_ú, Ú z%s.dotzwriting graph to %sÚw)r   ÚreplaceÚosÚpathÚjoinÚopenÚwriteÚclose)
ÚbasenameÚ	edge_listÚverticesÚlabelÚdot_file_dirÚdebugÚkwargsÚsÚfilenameÚfs
             ú7/usr/lib/python3/dist-packages/samba/kcc/graph_utils.pyÚwrite_dot_filer      s‚   € ä�(˜IÑ=¨UÐ=°fÑ=€AÙà�C˜%Ÿ-™-¨¨bÓ1Ñ1Ñ1ˆä�w‰w�|‰|˜L¨(°XÑ*=Ó>€HØÐÙÐ# hÑ.Ô/ÜˆX�sÓ€AØ‡G�GˆA„JØ‡G�G…Ió    c                   ó   — e Zd Zy)Ú
GraphErrorN)Ú__name__Ú
__module__Ú__qualname__© r   r   r   r   *   s   „ Ør   r   c                 óà   — |D ]i  }t        «       }| D ]3  \  }}||k(  r|j                  |«       Œ||k(  sŒ#|j                  |«       Œ5 t        |«      dz   t        |«      k7  sŒ`t        d«      ‚ y)zXThe graph is complete, which is to say there is an edge between
    every pair of nodes.é   zgraph is not fully connectedN)ÚsetÚaddÚlenr   )Úedgesr   Úedge_verticesÚvÚremotesÚaÚbs          r   Úverify_graph_completer/   .   st   € ð ò =ˆÜ“%ˆØò 	‰DˆAˆqØ�AŠvØ—‘˜A•Ø�a“Ø—‘˜A•ð		ô
 ˆw‹<˜!Ñœs 8›}Ó,ÜÐ;Ó<Ð<ñ=r   c                 ó  ‡
— | st        |«      dk  ryt        d«      ‚t        | «      }t        |j	                  «       «      Š
	 g }t        |«      D ]X  \  }}|\  }}|‰
v r#‰
j                  |«       |j                  |«       Œ2|‰
v sŒ7‰
j                  |«       |j                  |«       ŒZ |snt        |«      D ]  }||= Œ Œ|s‰
t        |«      k7  r3d}	|	dj                  ˆ
fd„t        |«      D «       «      z  }	t        |	«      ‚y)z&There is a path between any two nodes.r%   Nz9all vertices are disconnected because there are no edges:zHthe graph is not connected, as the following vertices are unreachable:
 z
 c              3   ó*   •K  — | ]
  }|‰vr|–— Œ y ­w©Nr#   )Ú.0r+   Úreacheds     €r   ú	<genexpr>z)verify_graph_connected.<locals>.<genexpr>X   s    øè ø€ ò -˜aØ GÑ+ô ñ -ùs   ƒ)r(   r   Úlistr&   ÚpopÚ	enumerater'   ÚappendÚreversedr   Úsorted)r)   r   r*   Úremaining_edgesÚdoomedÚiÚer-   r.   r   r4   s             @r   Úverify_graph_connectedr@   <   s  ø€ áÜˆx‹=˜AÒØÜð /ó 0ð 	0ô ˜5“k€OÜ�/×%Ñ%Ó'Ó(€GØ
ØˆÜ˜oÓ.ò 	!‰DˆAˆqØ‰DˆAˆqØ�G‰|Ø—‘˜A”Ø—‘˜aÕ Ø�g’Ø—‘˜A”Ø—‘˜aÕ ð	!ñ ØÜ˜&Ó!ò 	#ˆAØ Ñ"ð	#ð ñ ˜'¤S¨£]Ò2ð=ˆà	ˆU�Z‰Zó -¤6¨(Ó#3ô -ó -ñ 	-ˆä˜‹mÐð 3r   c                 ó  — t        | «      dk(  rt        | ||«      S t        j                  | t        | «      dz
  «      D ]  }	 t        |||«       Œ y# t        $ r#}| D ]  }||vsŒt	        d|z  «      ‚ Y d}~Œ;d}~ww xY w)z:The graph stays connected when any single edge is removed.r   r%   zFThe graph will be disconnected when the connection from %s to %s failsN)r(   r@   Ú	itertoolsÚcombinationsr   )r)   r   r*   Úsubsetr?   Úedges         r   Ú*verify_graph_connected_under_edge_failuresrF   ]   sŸ   € ä
ˆ5ƒz�Q‚Ü% e¨X°}ÓEÐEä×(Ñ(¨´°E³
¸Q±Ó?ò Nˆð	NÜ" 6¨8°]ÕCñNøô ò 	NØò N�Ø˜vÒ%Ü$ð &FØHLñ&Mó Nð NõNûð	Nús   ÁAÁ	A>Á	A9Á%A9Á9A>c                 ó�   — |D ]7  }|D �cg c]	  }||usŒ|‘Œ }}| D �cg c]	  }||vsŒ|‘Œ }}t        |||«       Œ9 yc c}w c c}w )z<The graph stays connected when any single vertex is removed.N)r@   )r)   r   r*   r+   ÚxÚsub_verticesÚ	sub_edgess          r   Ú,verify_graph_connected_under_vertex_failuresrK   l   sY   € ð ò FˆØ#+Ö:˜a¨q¸ªzšÐ:ˆÐ:Ø %Ö4˜1¨°!ª’QÐ4ˆ	Ð4Ü˜y¨,¸ÕEñFùÚ:ùÚ4s   Š	>”>ž	A¨Ac           	      ó   — | D �cg c]  }t        |«      ‘Œ }}	 t        j                  |d«      D ]F  \  }}||z  }|sŒt        |«      dk(  r||z  }|j	                  |«        nt        d|›d| ›d|›�«      ‚ yŒac c}w )zThe graph contains no loops.é   r%   z'there is a loop in the graph
 vertices z
 edges z
 intersection N©r&   rB   rC   r(   Úremover   )r)   r   r*   r?   Útreesr-   r.   Úintersections           r   Úverify_graph_forestrR   u   s™   € à"Ö#˜ŒS��VÐ#€EÐ#Ø
Ü×*Ñ*¨5°!Ó4ò 	‰DˆAˆqØ˜q™5ˆLÚÜ�|Ó$¨Ò)Ø˜‘F�AØ—L‘L ”OÙå$ò '/²±|ð&Eó Fð Fð	ð& ð) ùò $s   …A;c                 ó  — t        | «      }|D �cg c]  }t        |«      ‘Œ }}	 t        j                  |d«      D ]=  \  }}||z  }|sŒt        |«      dk(  r||z  }|j	                  |«        nt        d«      ‚ yŒXc c}w )a,  This allows a forest with duplicate edges. That is if multiple
    edges go between the same two vertices, they are treated as a
    single edge by this test.

    e.g.:
                        o
    pass: o-o=o  o=o   (|)             fail:  o-o
            `o          o                     `o'
    rM   r%   zthere is a loop in the graphNrN   )	r)   r   r*   Úunique_edgesr?   rP   r-   r.   rQ   s	            r   Úverify_graph_multi_edge_forestrU   �   s’   € ô �u“:€LØ)Ö*˜ŒS��VÐ*€EÐ*Ø
Ü×*Ñ*¨5°!Ó4ò 
	‰DˆAˆqØ˜q™5ˆLÚÜ�|Ó$¨Ò)Ø˜‘F�AØ—L‘L ”OÙä$Ð%CÓDÐDð
	ð ð ùò +s   �A=c                 ó‚   — t        |«      t        |«      z
  }|r&t        ddj                  t        |«      «      z  «      ‚y)z$There are no vertices without edges.z#some vertices are not connected:
%sú
N©r&   r   r   r;   )r)   r   r*   Úlonelys       r   Úverify_graph_no_lonely_verticesrZ   ©   sB   € ä�‹]œS Ó/Ñ/€FÙÜÐ?ØŸ™¤6¨&£>Ó2ñ3ó 4ð 	4ð r   c                 ó‚   — t        |«      t        |«      z
  }|r&t        ddj                  t        |«      «      z  «      ‚y)zBThe edge endpoints contain no vertices that are otherwise unknown.z,some edge vertices are seemingly unknown:
%srW   NrX   )r)   r   r*   Úunknowns       r   Ú verify_graph_no_unknown_verticesr]   ±   sB   € ä�-Ó ¤3 x£=Ñ0€GÙÜÐHØŸ™¤6¨'£?Ó3ñ4ó 5ð 	5ð r   c                 óÂ  ‡— | st        |«      dk  ryt        | «      dt        |«      z  k  rt        d«      ‚t        | «      }t        «       }| D ]I  }|d   |d   f}||v sŒ||v sŒ|j                  |«       |j	                  |«       |j	                  |«       ŒK i }|D ]W  \  }}	|j                  |t        «       «      j                  |	«       |j                  |	t        «       «      j                  |«       ŒY |j                  «       D ]!  \  }
}t        |«      dk(  sŒt        d|
z  «      ‚ t        |j                  «       «      D ]D  }
||
   }|sŒ|D ]2  Š|‰   }|j	                  |
«       |j                  ˆfd„|D «       «       Œ4 ||
= ŒF t        |«      dkD  r+t        dd	j                  |j                  «       «      z  «      ‚t        |||«       t        |||«       y)
a7  Each node has at least two directed edges leaving it, and two
    arriving. The edges work in pairs that have the same end points
    but point in opposite directions. The pairs form a path that
    touches every vertex and form a loop.

    There might be other connections that *aren't* part of the ring.

    Deciding this for sure is NP-complete (the Hamiltonian path
    problem), but there are some easy failures that can be detected.
    So far we check for:
      - leaf nodes
      - disjoint subgraphs
      - robustness against edge and vertex failure
    r%   NrM   zFdirected double ring requires at least twice as many edges as verticesr   z2wanted double directed ring, found a leaf node(%s)c              3   ó.   •K  — | ]  }|‰k7  sŒ	|–— Œ y ­wr2   r#   )r3   rH   Úns     €r   r5   z4verify_graph_directed_double_ring.<locals>.<genexpr>ú   s   øè ø€ Ò: a°1¸³6¤Ñ:ùs   ƒ
ŽzZwanted double directed ring, but this looks like a split graph
(%s can't reach each other)r   )r(   r   r&   r'   rO   Ú
setdefaultÚitemsr6   ÚkeysÚupdater   rF   rK   )r)   r   r*   Úhalf_duplexÚduplex_linksrE   Úrev_edgeÚedge_mapr-   r.   ÚvertexÚ
neighboursÚnsetÚn_neighboursr`   s                 @r   Ú!verify_graph_directed_double_ringrm   ¹   s
  ø€ ñ$ ”S˜“] aÒ'ØÜ
ˆ5ƒz�Aœ˜H›Ñ%Ò%Üð 5ó 6ð 	6ô �e“*€KÜ“5€LØò )ˆØ˜‘G˜T !™WÐ%ˆØ�;Ò 8¨{Ò#:Ø×Ñ˜TÔ"Ø×Ñ˜tÔ$Ø×Ñ˜xÕ(ð)ð( €HØò -‰ˆˆ1Ø×Ñ˜Aœs›uÓ%×)Ñ)¨!Ô,Ø×Ñ˜Aœs›uÓ%×)Ñ)¨!Õ,ð-ð
 'Ÿn™nÓ.ò .Ñˆ�
Üˆz‹?˜aÓÜð $Ø&,ñ-ó .ð .ð.ô
 �x—}‘}“Ó'ò ˆØ˜ÑˆÙØØò 	;ˆAØ# A™;ˆLØ×Ñ Ô'Ø×ÑÓ:¨4Ô:Õ:ð	;ð �VÑðô ˆ8ƒ}�qÒÜð 7ð Ÿ™ 8§=¡=£?Ó3ñ4ó 5ð 	5ô
 /¨|¸XØ/<ô>ä0°¸xØ1>õ@r   c                 óÐ   — t        |«      dk  ryt        |«      dk(  r=	 t        | «      dk(  r#| d   d   | d   d   k(  r| d   d   | d   d   k(  ryt        d«      ‚t        | ||«      S )zŒThis performs the directed_double_ring test but makes special
    concessions for small rings where the strict rules don't really
    apply.rM   Nr   r%   z0A two vertex graph should have an edge each way.)r(   r   rm   )r)   r   r*   s      r   Ú*verify_graph_directed_double_ring_or_smallro   	  s{   € ô ˆ8ƒ}�qÒØÜ
ˆ8ƒ}˜ÒØLÜ�‹J˜!ŠOØ�!‰H�Q‰K˜5 ™8 A™;Ò&Ø�!‰H�Q‰K˜5 ™8 A™;Ò&ØÜÐKÓLÐLä,¨U°H¸mÓLÐLr   c                 óŽ  — g }|D �cg c]  }|j                  dd«      ‘Œ }}t        «       }| D ]'  \  }}|j                  |«       |j                  |«       Œ) |€|}nt        |«      }|D ]  }	d|	z  }
t        «       |
   }	  || ||«       Œ! |S c c}w # t        $ r(}|j                  |	||j                  f«       Y d }~ŒUd }~ww xY w)Nú r   zverify_graph_%s)r
   r&   r'   Úglobalsr   r9   Ú__doc__)r)   r   ÚdirectedÚ
propertiesÚerrorsrH   r*   r-   r.   ÚpÚfnr   r?   s                r   Úverify_graphry     sÞ   € Ø€FØ/9Ö:¨!�!—)‘)˜C Õ%Ð:€JÐ:ä“E€MØò ‰ˆˆ1Ø×Ñ˜!ÔØ×Ñ˜!Õðð ÐØ ‰ä�x“=ˆàò -ˆØ Ñ"ˆÜ‹I�b‰Mˆð	-Ùˆe�X˜}Õ-ð	-ð €Mùò) ;øô" ò 	-Ø�M‰M˜1˜a §¡Ð+×,Ñ,ûð	-ús   ‡BÂ 
BÂ	CÂB?Â?Cc                 ó  — |
�t        | ||||
||||||¬«       |	rkt        |||¬«      }|rZ| ›d|xs d›�} |d|z  «       |D ]  \  }}} |d|d›d|›�«       Œ |r't        d|›d	d
j                  d„ |D «       «      ›�«      ‚y y y )N)	r   r   r   Úreformat_labelsrt   r   Úedge_colorsÚedge_labelsÚvertex_colors)ru   rq   r   z
%s FAILED:z>18ú: zThe 'z(' graph lacks the following properties:
rW   c              3   ó2   K  — | ]  \  }}}|›d |›�–— Œ y­w)r   Nr#   )r3   rw   r?   Údocs       r   r5   z!verify_and_dot.<locals>.<genexpr>L  s'   è ø€ ò 3LÙ7@°q¸!¸Sò @AÁ!Ô3Dñ 3Lùs   ‚)r   ry   r   r   )r   r)   r   r   r{   rt   ru   Úfatalr   Úverifyr   r|   r}   r~   rv   r   rw   r?   r�   s                      r   Úverify_and_dotr„   3  sÊ   € ð ÐÜ�x °ÀØ$0Ø'6ÀØ"°Ø#.¸mõ		Mñ Ü˜e XØ)3ô5ˆáÚ'¨ª°"¨Ð5ˆEÙ�, Ñ&Ô'Ø#ò ,‘	��1�cÚ£Q©Ð*Õ+ð,áÝ â"'¨¯©ñ 3LØDJô3Lô *Lð"Mó Nð Nð ð ð r   c                  ó*  — t        t        «       j                  «       «      D ]o  \  } }| j                  d«      sŒt	        | j                  dd«      «       |j                  r't	        d|j                  j                  «       z  «       Œft	        «        Œq y )NÚverify_graph_r   z    %s)r;   rr   rb   Ú
startswithÚprintr
   rs   Úrstrip)Úkr+   s     r   Úlist_verify_testsr‹   P  sh   € Ü”w“y—‘Ó(Ó)ò ‰ˆˆ1Ø�<‰<˜Õ(Ü�!—)‘)˜O¨RÓ0Ô1Ø�yŠyÜ�h !§)¡)×"2Ñ"2Ó"4Ñ5Õ6ä•ñr   )NNNN)NFr#   )NNTFr#   TNTNNNN)r   rB   Úsamba.graphr   r   Ú	Exceptionr   r/   r@   rF   rK   rR   rU   rZ   r]   rm   ro   ry   r„   r‹   r#   r   r   ú<module>rŽ      s‡   ðó* 
Û å !ð >BØ,0óô	�ô 	ò=òòBNòFòò4ò44ò5òM@ò`Mó"ð2 :>Ø27Ø48Ø-1Ø15Ø!%óNó:r   