o
    ii                     @   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yG   dZY nw 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y   |  Y S w 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streamstream_b r   M/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/nbconvert/utils/io.pyunicode_std_stream   s   


r   c                  C   s6   t j} z| j}W n ty   |  Y S w td|S )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   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 |S  ty( } z
|j}W Y d}~|S d}~w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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r)dS |dt
ddd }zt| | W n tyT   zt | W   tyS   Y  w w t || dS |dkrit| | dS 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   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_dstr   r   r   r5   V   s,   


r5   )r   )r   r   r%   r"   r3   r9   r   typingr   r   r   r   r   r#   r
   r    r5   r   r   r   r   <module>   s$    

