a
    ø£Bek  ã                   @   s¤   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lmZm	Z	 ddd„Z
dd„ ZG d	d
„ d
e	eef ƒZz
ejZW n eyŽ   dZY n0 dd„ Zdd„ ZdS )zio-related utilitiesé    N)ÚAnyÚDictÚstdoutc                 C   sF   | dv sJ ‚t t| ƒ} z
| j}W n ty6   |  Y S 0 t d¡|ƒS )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Â¶Å§â†�')
    )r   Ústderrúutf-8)ÚgetattrÚsysÚbufferÚAttributeErrorÚcodecsÚ	getwriter©ÚstreamZstream_b© r   úU/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/nbconvert/utils/io.pyÚunicode_std_stream   s    



r   c                  C   s6   t j} z
| j}W n ty&   |  Y S 0 t d¡|ƒS )zÔGet 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   r   r   r   Úunicode_stdin_stream%   s    	

r   c                   @   s   e Zd ZdZdd„ ZdS )ÚFormatSafeDictzFormat a dictionary safely.c                 C   s   d| d S )zHandle missing value.Ú{Ú}r   )ÚselfÚkeyr   r   r   Ú__missing__:   s    zFormatSafeDict.__missing__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   7   s   r   iÎ  c              
   C   sR   t tdƒstS d}zt | |¡ W n* tyL } z|j}W Y d}~n
d}~0 0 |S )z³Hard 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Úer   r   r   r   E   s    
r   c                 C   sÖ   t j |¡r"t j |t j | ¡¡}t| |ƒ}|tjkr¾t  | ¡j	t  |¡j	krRdS |dt
 dd¡d›� }zt| |ƒ W n6 ty®   zt  |¡ W n ty¦   Y n0 ‚ Y n0 t  ||¡ n|dkrÒt | |¡ dS )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   Z04Xr   )r!   ÚpathÚisdirÚjoinÚbasenamer   r$   ÚEEXISTÚstatÚst_inoÚrandomÚrandintÚlink_or_copyÚBaseExceptionÚremover#   ÚrenameÚshutilÚcopy)r%   r&   r'   Znew_dstr   r   r   r3   V   s$    


r3   )r   )r   r   r$   r!   r1   r7   r   Útypingr   r   r   r   r   r"   r
   r   r3   r   r   r   r   Ú<module>   s    


