
    ci]              	       (   d Z ddlZddlZddlZddlZddlmZ ddlmZ ddlm	Z	 ddlm
Z
 ddlmZ dd	lmZ dd
lmZ dgZ ej                  e      Z G d dej$                  e	j&                  e
j(                  ej*                  ej,                        Zy)zDSave DOT code objects, render with Graphviz dot, and open in viewer.    N   )DEFAULT_ENCODING)_tools)saving)jupyter_integration)piping)	rendering)unflatteningSourcec                   `    e Zd ZU dZe ej                  dd      dddeddfdej                  e
j                  ef   dej                  e
j                  edf   dej                  e   d	ej                  e   d
ej                  e   dej                  e   dej                  e   dd fd              Z ej                  dd      ddddefdddddedej                  e
j                  edf   dej                  e
j                  edf   dej                  e   d	ej                  e   d
ej                  e   dej                  e   dej                  e   dej                  e
j                     ddf fd       Zeed<   ej                  e
j                     ed<    fdZdej$                  e   fdZedefd       Z ej                  dd      	 	 ddddej                  e
j                  edf   dej                  e
j                  edf   dej                  e   def fd       Z xZS )r   a{  Verbatim DOT source code string to be rendered by Graphviz.

    Args:
        source: The verbatim DOT source code string.
        filename: Filename for saving the source (defaults to ``'Source.gv'``).
        directory: (Sub)directory for source saving and rendering.
        format: Rendering output format (``'pdf'``, ``'png'``, ...).
        engine: Layout engine used (``'dot'``, ``'neato'``, ...).
        encoding: Encoding for saving the source.

    Note:
        All parameters except ``source`` are optional. All of them
        can be changed under their corresponding attribute name
        after instance creation.
    r   cls)supported_number
ignore_argNfilename	directoryformatengineencodingrenderer	formatterreturnc                    t        j                  |      }|j                  r t        j                  j                  ||      nt        j                  |      }|t        j                         }t        j                  d||       t        ||      5 }	|	j                         }
ddd        | 
||||||||	      S # 1 sw Y   xY w)a  Return an instance with the source string read from the given file.

        Args:
            filename: Filename for loading/saving the source.
            directory: (Sub)directory for source loading/saving and rendering.
            format: Rendering output format (``'pdf'``, ``'png'``, ...).
            engine: Layout command used (``'dot'``, ``'neato'``, ...).
            encoding: Encoding for loading/saving the source.
        Nzread %r with encoding %r)r   )r   r   r   r   r   r   r   loaded_from_path)r   promote_pathlike_directorypartsospathjoinfspathlocalegetpreferredencodinglogdebugopenread)r   r   r   r   r   r   r   r   filepathfdsources              7/tmp/pip-target-z3e9_cxr/lib/python/graphviz/sources.py	from_filezSource.from_file)   s    $ 55i@	9BBGGLLH58, 	 224H		,hA(X. 	"WWYF	 6$	 ($	$,	. 	.	 	s   B;;Cself)r   r   r   r(   r   c          	      N    t         
|   |||||||       |	| _        || _        y )N)r   r   r   r   r   r   r   )super__init___loaded_from_path_source)r+   r(   r   r   r   r   r   r   r   r   	__class__s             r)   r.   zSource.__init__L   s9     	(i &v"*i"* 	 	, "2    r0   r/   c                 P    t        |   d| j                  | j                  d|S )z3Return the kwargs to create a copy of the instance.)r(   r    )r-   _copy_kwargsr0   r/   )r+   kwargsr1   s     r)   r5   zSource._copy_kwargsa   s1    w# .4<<595K5K.&,. 	.r2   c              #      K   | j                   j                  d      }|dd E d{    |dd D ]  }|j                  d      sdnd}||z      y7 +w)zwYield the DOT source code read from file line by line.

        Yields: Line ending with a newline (``'\n'``).
        T)keependsN
 )r0   
splitlinesendswith)r+   lineslinesuffixs       r)   __iter__zSource.__iter__g   sd     
 '''6":"#J 	 D!%t!4T"F-	  	s   %AA,Ac                 J    | j                   }|j                  d      s|dz  }|S )znThe DOT source code as string.

        Normalizes so that the string always ends in a final newline.
        r:   )r0   r=   )r+   r(   s     r)   r(   zSource.sourcer   s'     t$dNFr2   )skip_existingrC   c                    |du xrB | j                   xr4 t        j                  j                  | j                   | j                        }|r t
        j                  d| j                         t        | !  |||      S )a  Save the DOT source to file. Ensure the file ends with a newline.

        Args:
            filename: Filename for saving the source (defaults to ``name`` + ``'.gv'``)
            directory: (Sub)directory for source saving and rendering.
            skip_existing: Skip write if file exists (default: ``None``).
                By default skips if instance was loaded from the target path:
                ``.from_file(self.filepath)``.

        Returns:
            The (possibly relative) path of the saved source file.
        Nz;.save(skip_existing=None) skip writing Source.from_file(%r))r   r   rC   )	r/   r   r   samefiler&   r"   r#   r-   save)r+   r   r   rC   skipr1   s        r)   rF   zSource.save}   sz      % L$*@*@ LGG$$T%;%;T]]K 	IISmm%w|X*.  0 	0r2   )NN)__name__
__module____qualname____doc__classmethodr   deprecate_positional_argsr   typingUnionr   PathLikestrOptionalr*   r.   __annotations__r5   IteratorrA   propertyr(   boolrF   __classcell__)r1   s   @r)   r   r      s     %V%%qUKDH15153C3748.bkk3.>!? .#\\"++sD*@A. //#.. !//#.. #OOC0	.
 #OOC0. $__S1. >F. L .B &V%%qVLBFCG04042B 3737BFs !<<S$(>?"LLc4)?@  -  -	
 "??3/ "??3/ #OOC0 $*??2;;#? LP M" Lr{{33.	 &//#. 	     &V%%qVLDH?C0480V\\"++sD*@A 0R[[#t%;<0"OOD10=@0 M0r2   )rK   r    loggingr   rN   r   r   r;   r   r   r   r   r	   r
   __all__	getLoggerrH   r"   RenderSaveJupyterIntegrationPipe	Unflattenr   r4   r2   r)   <module>r`      sv    J   	  &   !   * g!}0Yv{{ 33V[[##}0r2   