
    .Ph                     |    d Z ddlZddlZddlZddlmZ ddZddZdd
Z G d de	          Z
 G d d          ZdS )zSafe access to git files.    N)ClassVarreturnc                 R    	 t          j        |            dS # t          $ r Y dS w xY w)z1Ensure a directory exists, creating if necessary.N)osmakedirsFileExistsError)dirnames    L/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/dulwich/file.pyensure_dir_existsr      s?    
G   s    
&&c                 .   t           j                            |          s(	 t          j        | |           n# t          $ r  w xY wdS ddl}	 |                    d| d          \  }}t          j        |           t          j        |           n# t          $ r  w xY w	 t          j        ||           n# t          $ r  w xY w	 t          j        | |           n$# t          $ r t          j        ||            w xY wt          j        |           dS )zCRename file with temporary backup file to rollback if rename fails.Nr   z.tmp.)prefixdir)	r   pathexistsrenameOSErrortempfilemkstempcloseremove)oldnamenewnamer   fdtmpfiles        r
   _fancy_renamer   &   s]   7>>'"" 	Igw'''' 	 	 		 OOO ((S(IIW

	'    	
	'7####   
	'7####   
	'7### Igs.   7 AAB B!B7 7CC !C>rb  c                     d|v rt          d          d|v rt          d          d|vrt          d          d|v rt          | |||          S t          | ||          S )a  Create a file object that obeys the git file locking protocol.

    Returns: a builtin file object or a _GitFile object

    Note: See _GitFile for a description of the file locking protocol.

    Only read-only and write-only (binary) modes are supported; r+, w+, and a
    are not.  To read and write from the same file, you can take advantage of
    the fact that opening a file for write does not actually open the file you
    request.

    The default file mask makes any created files user-writable and
    world-readable.

    az'append mode not supported for Git files+z+read/write mode not supported for Git filesbz%text mode not supported for Git filesw)r   _GitFileopen)filenamemodebufsizemasks       r
   GitFiler+   G   s{      d{{?@@@
d{{CDDD
$=>>>
d{{$666HdG,,,    c                   $     e Zd ZdZd fdZ xZS )
FileLockedzFile is already locked.r   Nc                 h    || _         || _        t                                          ||           d S N)r'   lockfilenamesuper__init__)selfr'   r1   	__class__s      r
   r3   zFileLocked.__init__f   s2     (<00000r,   r   N)__name__
__module____qualname____doc__r3   __classcell__)r5   s   @r
   r.   r.   c   sC        !!1 1 1 1 1 1 1 1 1 1r,   r.   c                       e Zd ZU dZh dZeee                  ed<   h dZ	eee                  ed<   ddZ
dd	Zdd
ZddZd Zd Zd ZdS )r%   ap  File that follows the git locking protocol for writes.

    All writes to a file foo will be written into foo.lock in the same
    directory, and the lockfile will be renamed to overwrite the original file
    on close.

    Note: You *must* call close() or abort() on a _GitFile for the lock to be
        released. Typically this will happen in a finally block.
    >   r(   nameclosederrorsencodingnewlines	softspacePROXY_PROPERTIES>   readseektellflushwritefilenoisatty__iter__readlinetruncate	readlines
writelinesPROXY_METHODSr   Nc           	      &   || _         t          | j         t                    r| j         dz   | _        n| j         dz   | _        	 t	          j        | j        t          j        t          j        z  t          j        z  t          t          dd          z  |          }n(# t          $ r}t          || j                  |d }~ww xY wt	          j        |||          | _        d| _        | j        D ]&}t!          | |t          | j        |                     'd S )Ns   .lockz.lockO_BINARYr   F)	_filename
isinstancebytes_lockfilenamer   r&   O_RDWRO_CREATO_EXCLgetattrr   r.   fdopen_file_closedrP   setattr)r4   r'   r(   r)   r*   r   excmethods           r
   r3   z_GitFile.__init__   s   !dne,, 	:!%(!:D!%'!9D	D"	BJ&2WRQ5O5OO BB
  	D 	D 	DXt'9::C	DYr411
( 	? 	?FD&'$*f"="=>>>>	? 	?s   AB 
B>#B99B>c                     | j         rdS | j                                         	 t          j        | j                   d| _         dS # t          $ r d| _         Y dS w xY w)zClose and discard the lockfile without overwriting the target.

        If the file is already closed, this is a no-op.
        NT)r]   r\   r   r   r   rV   FileNotFoundErrorr4   s    r
   abortz_GitFile.abort   sr    
 < 	F
	 Id()))DLLL  	  	  	 DLLLL	 s    A AAc                 .   | j         rdS | j                                         t          j        | j                                                   | j                                         	 t          t          dd           t          j        | j	        | j
                   nJt          j        dk    r t          j        | j	        | j
                   nt          | j	        | j
                   |                                  dS # |                                  w xY w)a7  Close this file, saving the lockfile over the original.

        Note: If this method fails, it will attempt to delete the lockfile.
            However, it is not guaranteed to do so (e.g. if a filesystem
            becomes suddenly read-only), which will prevent future writes to
            this file until the lockfile is removed manually.

        Raises:
          OSError: if the original file could not be overwritten. The
            lock file is still closed, so further attempts to write to the same
            file object will raise ValueError.
        Nreplacewin32)r]   r\   rG   r   fsyncrI   r   rZ   rf   rV   rS   sysplatformr   r   rd   rc   s    r
   r   z_GitFile.close   s     < 	F

""$$%%%
	r9d++7
4-t~>>>><7**Id0$.AAAA "$"4dnEEEJJLLLLLDJJLLLLs   (B C> >Dc                     t          | dd          s5t          j        d| t          d           |                                  d S d S )Nr]   Tz	unclosed    )
stacklevel)rZ   warningswarnResourceWarningrd   rc   s    r
   __del__z_GitFile.__del__   sQ    tY-- 	M.d..ANNNNJJLLLLL	 	r,   c                     | S r0    rc   s    r
   	__enter__z_GitFile.__enter__   s    r,   c                 ^    ||                                   d S |                                  d S r0   )rd   r   )r4   exc_typeexc_valexc_tbs       r
   __exit__z_GitFile.__exit__   s*    JJLLLLLJJLLLLLr,   c                 \    || j         v rt          | j        |          S t          |          )z,Proxy property calls to the underlying file.)rC   rZ   r\   AttributeError)r4   r=   s     r
   __getattr__z_GitFile.__getattr__   s0    4(((4:t,,,T"""r,   r6   )r7   r8   r9   r:   rC   r   setstr__annotations__rP   r3   rd   r   rq   rt   ry   r|   rs   r,   r
   r%   r%   l   s          , , ,hs3x(   ) ) )M8CH%   ? ? ? ?(          >   
    # # # # #r,   r%   r6   )r   r   r   )r:   r   ri   rn   typingr   r   r   r+   	Exceptionr.   r%   rs   r,   r
   <module>r      s   ,    				 



             B- - - -81 1 1 1 1 1 1 1w# w# w# w# w# w# w# w# w# w#r,   