U
    9%e	                     @   s   U zd dl mZ W nF ek
rX   zd dlmZ W n  ek
rR   d dlmZ Y nX Y nX 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 d dlmZ d dlmZmZmZmZ d dlZeejdddZedef ed	< ejdee ee eeeef  eeddf d
ddZdd ZdS )    )JSONDecodeErrorN)partial)Path)Callable	GeneratorOptionalUnionT)streamZallow_unicode.	yaml_dump)suffixprefixdirreturnc                 k   s   t jf || |d|}|jV  zt|j W n> tk
rn   ztj|jtd W n tk
rh   Y nX Y nX z|  W n tk
r   Y nX dS )a  
    Context manager to create a temporary directory and safely delete it.

    If tmp directory cannot be deleted normally, we set the WRITE permission and retry.
    If cleanup still fails, we give up but don't raise an exception. This is equivalent
    to  `tempfile.TemporaryDirectory(..., ignore_cleanup_errors=True)` introduced in
    Python 3.10.

    See https://www.scivision.dev/python-tempfile-permission-error-windows/.
    )r   r   r   )onerrorN)tempfileTemporaryDirectorynameshutilrmtree	Exception_set_write_permission_and_retrycleanup)r   r   r   kwargsZtmpdir r   [/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/huggingface_hub/utils/_fixes.pySoftTemporaryDirectory%   s    r   c                 C   s   t |tj | | d S )N)oschmodstatS_IWRITE)funcpathexcinfor   r   r   r   K   s    r   )NNN)requestsr   ImportErrorZ
simplejsonjson
contextlibr   r   r   r   	functoolsr   pathlibr   typingr   r   r   r   yamldumpr
   str__annotations__contextmanagerr   r   r   r   r   r   <module>   s8        %