
    h""                         S r SSKrSSKrSSKJr  / SQrS r\" SSS9SS	 j5       r\" SS
S9\R                  " SSS9SS j5       5       r
\R                  " SSS9S 5       rS rg)a
  
*****
Pajek
*****
Read graphs in Pajek format.

This implementation handles directed and undirected graphs including
those with self loops and parallel edges.

Format
------
See http://vlado.fmf.uni-lj.si/pub/networks/pajek/doc/draweps.htm
for format information.

    N)	open_file)
read_pajekparse_pajekgenerate_pajekwrite_pajekc              #     #    U R                   S:X  a  SnOU R                   nSU R                  5        3v   [        U 5      n[        [	        U[        S[        U5      S-   5      5      5      nU GHA  nU R                  R                  U0 5      R                  5       nUR                  SS5      nUR                  SS5      n [        UR                  SX4   5      5      nXU'   UR                  SS5      n
SR                  [        [         XXgU
45      5      nUR#                  5        H  u  p[%        U[&        5      (       a3  UR)                  5       S:w  a  US[!        U5       S[!        U5       3-  nMM  [*        R,                  " SU S[%        U[&        5      (       a  SOS S35        M     Uv   GMD     U R/                  5       (       a  Sv   OSv   U R1                  SS9 H  u  pnUR                  5       nUR                  SS5      nSR                  [        [         X>   X=   U45      5      nUR#                  5        H  u  p[%        U[&        5      (       a3  UR)                  5       S:w  a  US[!        U5       S[!        U5       3-  nMM  [*        R,                  " SU S[%        U[&        5      (       a  SOS S35        M     Uv   M     g
! [         a  n	U	=R                  S	-  sl        e S
n	A	ff = f7f)zGenerate lines in Pajek graph format.

Parameters
----------
G : graph
   A Networkx graph

References
----------
See http://vlado.fmf.uni-lj.si/pub/networks/pajek/doc/draweps.htm
for format information.
 NetworkXz
*vertices    xg        yid)zSPajek format requires 'id' to be an int(). Refer to the 'Relabeling nodes' section.Nshapeellipse zNode attribute z is not processed. zEmpty attributezNon-string attribute.*arcs*edgesT)dataweightg      ?zEdge attribute )nameorderlistdictziprangelennodesgetcopypopint
ValueErrorargsjoinmap	make_qstritems
isinstancestrstripwarningswarnis_directededges)Gr   r   
nodenumbernnar   r   r   errr   skvuedgedatadvalues                     J/var/www/html/env/lib/python3.13/site-packages/networkx/readwrite/pajek.pyr   r      s     	vv|vv qwwyk
""GEc%q#e*q.!9:;J WW[[B$$&FF3FF3		RVVD*-01B 1w	*HHSRA%$89:HHJDA!S!!aggi2oq1a	!~66%aS(;R\]^`cRdRd=N  kA  <C  CD  E	  7 < 	}}''t',hMMOh$HHSZ]JM5$IJKGGIDA!S!!aggi2oq1a	!~66%aS(;R\]^`cRdRd=N  kA  <C  CD  E	   -5  	HH  H 	s+   B?K6KG/K6
K3K..K33K6r   wb)modec                 r    [        U 5       H(  nUS-  nUR                  UR                  U5      5        M*     g)a^  Write graph in Pajek format to path.

Parameters
----------
G : graph
   A Networkx graph
path : file or string
   File or filename to write.
   Filenames ending in .gz or .bz2 will be compressed.

Examples
--------
>>> G = nx.path_graph(4)
>>> nx.write_pajek(G, "test.net")

Warnings
--------
Optional node attributes and edge attributes must be non-empty strings.
Otherwise it will not be written into the file. You will need to
convert those attributes to strings if you want to keep them.

References
----------
See http://vlado.fmf.uni-lj.si/pub/networks/pajek/doc/draweps.htm
for format information.

N)r   writeencode)r0   pathencodinglines       r<   r   r   c   s1    8 q!

4;;x() "    rbT)graphsreturns_graphc                 2   ^ U4S jU  5       n[        U5      $ )a
  Read graph in Pajek format from path.

Parameters
----------
path : file or string
   File or filename to write.
   Filenames ending in .gz or .bz2 will be uncompressed.

Returns
-------
G : NetworkX MultiGraph or MultiDiGraph.

Examples
--------
>>> G = nx.path_graph(4)
>>> nx.write_pajek(G, "test.net")
>>> G = nx.read_pajek("test.net")

To create a Graph instead of a MultiGraph use

>>> G1 = nx.Graph(G)

References
----------
See http://vlado.fmf.uni-lj.si/pub/networks/pajek/doc/draweps.htm
for format information.
c              3   D   >#    U  H  oR                  T5      v   M     g 7f)N)decode).0rE   rD   s     r<   	<genexpr>read_pajek.<locals>.<genexpr>   s     4tt[[""ts    )r   )rC   rD   liness    ` r<   r   r      s    < 5t4EurF   c                 	  ^ SSK n[        U [        5      (       a  [        U R	                  S5      5      n [        U  Vs/ s H  o"R                  S5      PM     sn5      n [        R                  " 5       n/ mU (       Ga   [        U 5      nUR                  5       R                  S5      (       a%   UR	                  SS5      u  pVXcR                  S'   GOfUR                  5       R                  S5      (       Ga7  0 nUR	                  5       u  pH[        [        U5      5       GH  n	[        U 5      n UR	                  [        U5      R                  S5      5       V
s/ s H  oR!                  S5      PM     nn
USS	 u  pTR%                  U5        UR'                  U5        XWU'   XR(                  U   S
'    US	S u  pnUR(                  U   R+                  [-        U
5      [-        U5      US.5        [/        USSS	2   USSS	2   5      nUR(                  U   R+                  U5        GM     GO
UR                  5       R                  S5      (       d%  UR                  5       R                  S5      (       Gaa  UR                  5       R                  S5      (       a  [        R0                  " U5      nUR                  5       R                  S5      (       a  UR3                  5       nU  H  n UR	                  [        U5      R                  S5      5       V
s/ s H  oR!                  S5      PM     nn
[5        U5      S	:  a  M\  USS	 u  nnWR7                  UU5      nUR7                  UU5      n0 n US	S nUR+                  S[-        US   5      05        [/        USSS	2   USSS	2   5      nUR+                  U5        UR8                  " UU40 UD6  M     O`UR                  5       R                  S5      (       a<  [        R:                  " U5      nU4S j[=        U 5       5       nUR?                  U5        U (       a  GM  U$ s  snf !    U$ = f! [         a     N%f = fs  sn
f ! ["         a    UR	                  [        U5      5      n GNf = f!    GN= fs  sn
f ! ["         a    UR	                  [        U5      5      n GNf = f!    GN8= f)zParse Pajek format graph from string or iterable.

Parameters
----------
lines : string or iterable
   Data in Pajek format.

Returns
-------
G : NetworkX graph

See Also
--------
read_pajek

r   Nr@   z*networkr   r   z	*verticeszutf-8   r      )r   r   r      r   r   z*edge   r      z*matrixc              3      >#    U  HQ  u  p[        UR                  5       5        H.  u  p4[        U5      S :w  d  M  TU   TU   S[        U5      04v   M0     MS     g7f)r   r   N)	enumeratesplitr"   )rM   rowrE   colr   labelss        r<   rN   parse_pajek.<locals>.<genexpr>  s[      #3KS#,TZZ\#:KSt9> BfSkHc$i+@A#: B#3s
   4A!A) shlexr)   r*   iterrY   rstripnxMultiDiGraphnextlower
startswithgraphr#   r   r"   rB   rL   AttributeErrorappendadd_noder   updatefloatr   
MultiGraphto_directedr   r   add_edgeDiGraphrX   add_edges_from)rP   r^   rE   r0   llabelr   
nodelabelsnnodesir   	splitliner   r   r   
extra_attruivir8   r7   	edge_datawadj_listr\   s                          @r<   r   r      s9   $  %U[[&'6++d#67E
AF
	UA 779
++'ggdA.
 #'WWY!!+..J	IA3v;'K438;;s1v}}W?U3V!3Va)3V  !
 &aN	e$

5!!&2')t$"+Aa.KA%GGEN))#AhU1XF
 !14a4)ADqD/B
%%j1+ (, WWY!!(++qwwy/C/CG/L/Lwwy##G,,MM!$wwy##G,,MMO438;;s1v}}W?U3V!3Va)3V  ! y>A%"1QBNN2r*NN2r*	!!AA$$had%<=
 !14a4)ADqD/B
  , 

1a-9-7 8 WWY!!),,

1A#,U#3H X&c %f Hm 7	^ HW  ! & 4 %CF 3I4! & 4 %CF 3I4s   Q?Q
 /Q 0+Q'Q"5Q'6<R,+RR1R3$S

Q
QQ"Q''$RRRR$SS
Sc                 ^    [        U [        5      (       d  [        U 5      n SU ;   a  SU  S3n U $ )z[Returns the string representation of t.
Add outer double-quotes if the string has a space.
r   ")r)   r*   )ts    r<   r'   r'     s3     aF
axs!HHrF   )zUTF-8)__doc__r,   networkxra   networkx.utilsr   __all__r   r   _dispatchabler   r   r'    rF   r<   <module>r      s       $
HGT 14* *@ 14T2 3 @ T2l 3l^rF   