
    g                        U d dl m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 d dlmZ d dlmZmZmZmZ d dlZd dlmZmZmZmZ ddlmZ d	d
lmZ  ej8                  e      Z eej>                  dd      Z ede!f   e"d<   ejF                  	 	 	 ddee!   dee!   deeee!f      deeddf   fd       Z$d Z%ejF                  dee!ef   deeddf   fd       Z&y# e$ r 	 d dlmZ n# e$ r	 d dlmZ Y nw xY wY w xY w)    )JSONDecodeErrorN)partial)Path)Callable	GeneratorOptionalUnion)BaseFileLockFileLockSoftFileLockTimeout   )	constants   )loggingT)streamallow_unicode.	yaml_dumpsuffixprefixdirreturnc              +     K   t        j                  d|| |d|}t        |j                        j	                          	 t        j                  |j                         	 |j                          y# t        $ r9 	 t        j                  |j                  t               n# t        $ r Y nw xY wY Sw xY w# t        $ r Y yw xY ww)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TemporaryDirectoryr   nameresolveshutilrmtree	Exception_set_write_permission_and_retrycleanup)r   r   r   kwargstmpdirs        Q/var/www/openai/venv/lib/python3.12/site-packages/huggingface_hub/utils/_fixes.pySoftTemporaryDirectoryr(   *   s     " ((Yv3YRXYF
v{{

#
#
%%fkk"  	MM&++/NO 			  sk   ?CA3 "B8 2C3	B5=%B#"B5#	B/,B5.B//B52C4B55C8	CCCCc                 \    t        j                  |t        j                          | |       y )N)oschmodstatS_IWRITE)funcpathexcinfos      r'   r#   r#   P   s    HHT4==!J    	lock_filec              #     K   t        | t        j                        }	 	 |j                          	 | 	 |j                         S # t        $ r t
        j                  d|        Y nXt        $ rM}dt        |      v r6t
        j                  d|        t        | t        j                        }Y d}~Y d}~nd}~ww xY w# t        $ r- 	 t        |       j                          Y y# t        $ r Y Y yw xY ww xY ww)aM  A filelock with some custom logic.

    This filelock is weaker than the default filelock in that:
    1. It won't raise an exception if release fails.
    2. It will default to a SoftFileLock if the filesystem does not support flock.

    An INFO log message is emitted every 10 seconds if the lock is not acquired immediately.
    )timeoutz#still waiting to acquire lock on %szuse SoftFileLock insteadzPFileSystem does not appear to support flock. Falling back to SoftFileLock for %sN)r   r   FILELOCK_LOG_EVERY_SECONDSacquirer   loggerinfoNotImplementedErrorstrwarningr   releaseOSErrorr   unlink)r2   lockes      r'   WeakFileLockrA   U   s      Iy'K'KLD
	LLN 
J||~#  	JKK=yI" 	)SV3 fhq $Iy7[7[\ 4	 *  	O""$ 		sz   C9A C9C  C9B<%C9'B</>B7-
C97B<<C9 	C6
C%#C9%	C2.C6/C91C22C66C9)NNN)'requestsr   ImportError
simplejsonjson
contextlibr*   r    r,   r   	functoolsr   pathlibr   typingr   r   r   r	   yamlfilelockr
   r   r   r    r   r   
get_logger__name__r7   dumpr   r:   __annotations__contextmanagerr(   r#   rA   r   r1   r'   <module>rR      sG  )(  	      7 7  B B   
		H	% !(		$d S	8CH S   &*"SM"SM" 
%c	"	#"
 tT4 " "J
 #E#t), #<t;S1T # #a  )). )())s5   C C; C'&C;'C52C;4C55C;:C;