
    b%                         d Z ddlZddlZddlZddlZddlZddlZddZd Z G d de	      Z
	 ej                  Zd Zd	 Zdd
Zy# e$ r dZY w xY w)zio-related utilities    Nc                     | dv sJ t        t        |       } 	 | j                  } t	        j
                  d      |      S # t        $ r | cY S w xY w)u   Get a wrapper to write unicode to stdout/stderr as UTF-8.

    This ignores environment variables and default encodings, to reliably write
    unicode to stdout or stderr.

    ::

        unicode_std_stream().write(u'ł@e¶ŧ←')
    )stdoutstderrutf-8)getattrsysbufferAttributeErrorcodecs	getwriterstreamstream_bs     4/usr/lib/python3/dist-packages/nbconvert/utils/io.pyunicode_std_streamr      s]     ))))S&!F==
 %6G$X..	  s   ? AAc                      t         j                  } 	 | j                  } t	        j
                  d      |      S # t        $ r | cY S w xY w)zGet a wrapper to read unicode from stdin as UTF-8.

    This ignores environment variables and default encodings, to reliably read unicode from stdin.

    ::

        totreat = unicode_stdin_stream().read()
    r   )r   stdinr	   r
   r   	getreaderr   s     r   unicode_stdin_streamr   $   sK     YYF== %6G$X..  s   9 AAc                       e Zd Zd Zy)FormatSafeDictc                     d|z   dz   S )N{} )selfkeys     r   __missing__zFormatSafeDict.__missing__7   s    Sy3    N)__name__
__module____qualname__r   r   r   r   r   r   6   s    r   r   i  c                     t        t        d      st        S d}	 t        j                  | |       |S # t        $ r}|j
                  }Y d}~|S d}~ww xY w)zHard links ``src`` to ``dst``, returning 0 or errno.

    Note that the special errno ``ENOLINK`` will be returned if ``os.link`` isn't
    supported by the operating system.
    linkr   N)hasattrosENOLINKr$   OSErrorerrno)srcdst
link_errnoes       r   r$   r$   A   sT     2vJ
S   WW
s   2 	AAAc                    t         j                  j                  |      r=t         j                  j                  |t         j                  j	                  |             }t        | |      }|t        j                  k(  rt        j                  |       j                  t        j                  |      j                  k(  ry|dt        j                  dd      dz   }	 t        | |       t        j                   ||       y|dk7  rt#        j$                  | |       yy# t        $ r' 	 t        j                  |        # t        $ r Y  w xY ww xY w)a+  Attempts to hardlink ``src`` to ``dst``, copying if the link fails.

    Attempts to maintain the semantics of ``shutil.copy``.

    Because ``os.link`` does not overwrite files, a unique temporary file
    will be used if the target already exists, then that file will be moved
    into place.
    Nz-temp-   i   04Xr   )r&   pathisdirjoinbasenamer$   r)   EEXISTstatst_inorandomrandintlink_or_copyBaseExceptionremover(   renameshutilcopy)r*   r+   r,   new_dsts       r   r:   r:   R   s    
ww}}Sggll3 0 0 56c3JU\\!773<"''#,"5"55 &5!9# >??	g& 			'3	q 	C 
  			'"   	s0   D 	E
$D:9E
:	EE
EE
c                 6   t         j                  j                  |       s	 t        j                  | |       yt         j                  j                  |       st	        d| z        y# t        $ r(}|j
                  t
        j                  k7  r Y d}~yd}~ww xY w)zensure that a directory exists

    If it doesn't exist, try to create it and protect against a race condition
    if another process is doing the same.

    The default permissions are 755, which differ from os.makedirs default of 777.
    )modeNz %r exists but is not a directory)r&   r1   existsmakedirsr(   r)   r5   r2   )r1   rB   r-   s      r   ensure_dir_existsrE   w   sy     77>>$	KK4( WW]]4 84?@@ !  	ww%,,& '	s   A' '	B0BB)r   )i  )__doc__r   r)   r&   r8   r>   r   r   r   dictr   r'   r
   r$   r:   rE   r   r   r   <module>rH      sh    
   	   
/,/$T 
mmG
""JAu  Gs   A AA