
    -Phb                        d Z 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Zddl	Z	ddl
Z
ddlmZ ddlmZ ddlmZ ddlmZ erddlmZ dd	lmZmZ d
Zd3dZd4dZd5dZd6dZd7dZd8dZd9dZdd d:d#Z ej         d$          Z!d;d&Z"d<d(Z#ej$        fd=d,Z%d>d/Z&e%Z' e	j(                    p e	j)                    Z*ej+        j,        Z, G d0 d1          Z-d?d2Z.dS )@z6Operating system-related utility functions for Sphinx.    )annotationsN)StringIO)Path)TYPE_CHECKING)__)TracebackType)AnySelf/canonical_pathstrreturnc               V    |                      t          t          j        j                  S N)replaceSEPospathsep)r   s    R/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sphinx/util/osutil.pyos_pathr      s    !!#rw{333    native_pathstr | os.PathLike[str]c               z    t          j        |                               t           j        j        t
                    S )z"Return path in OS-independent form)r   fspathr   r   r   r   )r   s    r   
canon_pathr   #   s&    9[!!))"'+s;;;r   filepathc               J    t          |           }t          j        d|          S )z+Normalize path separator and unicode stringNFC)r   unicodedata	normalize)r   new_paths     r   path_stabilizer$   (   s"    (##H 111r   basetoc                   |                     t                    r|S |                     d          d                             t                    }|                    d          d                             t                    }t          |dd         |dd         d          D ]7\  }}||k    r n+|                    d           |                    d           8||k    rdS t          |          dk    r|dgk    r
d	t          z   S d
t          z   t          |          dz
  z  t                              |          z   S )z.Return a relative URL from ``base`` to ``to``.#r   NF)strict    ...)
startswithr   splitzippoplenjoin)r%   r&   b2t2xys         r   relative_urir9   .   s   	}}S 		C		!	!#	&	&B	#q				$	$BBssGRWU333  166E
q			
q					Rxx r
2ww!||rd

 Sy3J3r77Q;'#((2,,66r   fileNonec                2    t          j        | d           dS )zEnsure that a path exists.T)exist_okN)r   makedirs)r:   s    r   	ensuredirr?   E   s    Kt$$$$$$r   sourceintc                   t          | t          j                  r|                                 nt          j        |           }|j        dz   S )a5  Return the last modified time of ``filename``.

    The time is returned as integer microseconds.
    The lowest common denominator of modern file-systems seems to be
    microsecond-level precision.

    We prefer to err on the side of re-rendering a file,
    so we round up to the nearest microsecond.
    i)
isinstancer   DirEntrystatst_mtime_ns)r@   sts     r   _last_modified_timerH   J   s>     %VR[99	NrwvB^v%&&r   destc                    t          | t          j                  r|                                 nt          j        |           }t          j        ||j        |j        f           dS )z!Copy a file's modification times.)nsN)rC   r   rD   rE   utimest_atime_nsrF   )r@   rI   rG   s      r   _copy_timesrN   Y   sP    $VR[99	NrwvBHTr~r~6777777r   F)forcerO   boolc                  t          |           } t          |          }|                                 s|  d}t          |          |                                x}rt          j        | |d          s|sM|rKddlm} |                    t                    }t          d          }|
                    || |dd	           d
S t          j        dk    rt          j        | |           d
S t          j        | |           t!          j        t$                    5  t'          | |           d
d
d
           d
S # 1 swxY w Y   d
S d
S )ae  Copy a file and its modification times, if possible.

    :param source: An existing source to copy.
    :param dest: The destination path.
    :param bool force: Overwrite the destination file even if it exists.
    :raise FileNotFoundError: The *source* does not exist.

    .. note:: :func:`copyfile` is a no-op if *source* and *dest* are identical.
    z does not existF)shallowr   )loggingzNAborted attempted copy from %s to %s (the destination path has existing data).misccopy_overwrite)typesubtypeNwin32)r   existsFileNotFoundErrorfilecmpcmpsphinx.utilrS   	getLogger__name__r   warningsysplatformshutilcopy2copyfile
contextlibsuppressOSErrorrN   )r@   rI   rO   msgdest_existsrS   loggers          r   re   re   _   s     &\\F::D==?? %((($$$ !KKMM)[* {64777	*  	 	 ,+++++&&x00F< C NN36CSNTTTF<7""L&&&&&OFD)))$W-- * *FD)))* * * * * * * * * * * * * * * * * *3* *s   D66D:=D:z[^a-zA-Z0-9_-]stringc                <    t                               d|           pdS )Nr+   sphinx)	_no_fn_resub)rl   s    r   make_filenamerq      s    ==V$$00r   projectc                j    t          |                     d                                                    S )Nz Documentation)rq   removesuffixlower)rr   s    r   make_filename_from_projectrv      s+    --.>??@@FFHHHr   r   startstr | os.PathLike[str] | Nonec                    	 t           j                            | |          S # t          $ r t	          |           cY S w xY w)a  Return a relative filepath to *path* either from the current directory or
    from an optional *start* directory.

    This is an alternative of ``os.path.relpath()``.  This returns original path
    if *path* and *start* are on different drives (for Windows platform).
    )r   r   relpath
ValueErrorr   )r   rw   s     r   rz   rz      sJ    wtU+++   4yys   " >>r   rootc               d   d| j         v r|                                 } d|j         v r|                                }| j        |j        k    s	d|j         v r| S t          j        dd         dk     r-t          t          j                            | |                    S | 	                    |d          S )zReturn a relative filepath to *path* from the given *root* directory.

    This is an alternative of ``Path.relative_to``.
    It returns the original path if *path* and *root* are on different drives,
    which may happen on Windows.
    r.   N   )      T)walk_up)
partsresolveanchorra   version_infor   r   r   rz   relative_to)r   r|   s     r   _relative_pathr      s     tz||~~tz||~~{dk!!TTZ%7%7
g%%BGOOD$//000D$///r   c                  B    e Zd ZdZddZdd	Zdd
ZddZddZddZ	dS )FileAvoidWritea  File-like object that buffers output and only writes if content changed.

    Use this class like when writing to a file to avoid touching the original
    file if the content hasn't changed. This is useful in scenarios where file
    mtime is used to invalidate caches or trigger new behavior.

    When writing to this file handle, all writes are buffered until the object
    is closed.

    Objects can be used as context managers.
    r   
str | Pathr   r;   c                "    || _         d | _        d S r   )_path_io)selfr   s     r   __init__zFileAvoidWrite.__init__   s    
$(r   datar   c                n    | j         st                      | _         | j                             |           d S r   )r   r   write)r   r   s     r   r   zFileAvoidWrite.write   s1    x 	"zzDHtr   c                   | j         sd}t          |          |                                 }| j                                          	 t	          | j        d          5 }|                                }ddd           n# 1 swxY w Y   ||k    rdS n# t          $ r Y nw xY wt	          | j        dd          5 }|                    |           ddd           dS # 1 swxY w Y   dS )z0Stop accepting writes and write file, if needed.z,FileAvoidWrite does not support empty files.zutf-8)encodingNw)	r   	Exceptiongetvaluecloseopenr   readrh   r   )r   ri   bufold_fold_contentfs         r   r   zFileAvoidWrite.close   ss   x 	!@CC.. mmoo	dj7333 +u#jjll+ + + + + + + + + + + + + + +c!! " 	 	 	D	 $*cG444 	GGCLLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	sH   B A>2B >BB B	B 
BB9CC #C r
   c                    | S r    )r   s    r   	__enter__zFileAvoidWrite.__enter__   s    r   exc_typetype[BaseException] | None	exc_valueBaseException | None	tracebackTracebackType | NonerP   c                .    |                                   dS )NT)r   )r   r   r   r   s       r   __exit__zFileAvoidWrite.__exit__   s     	

tr   namer	   c                \    | j         sd}t          |          t          | j         |          S )Nz=Must write to FileAvoidWrite before other methods can be used)r   r   getattr)r   r   ri   s      r   __getattr__zFileAvoidWrite.__getattr__   s/    x 	!QCC.. tx&&&r   N)r   r   r   r;   )r   r   r   r;   )r   r;   )r   r
   )r   r   r   r   r   r   r   rP   )r   r   r   r	   )
r_   
__module____qualname____doc__r   r   r   r   r   r   r   r   r   r   r      s        
 
) ) ) )   
   (      ' ' ' ' ' 'r   r   c                   t          |           } |                                 rt          j        |            d S t	          j        |            d S r   )r   is_dirrc   rmtreer   remove)r   s    r   r   r     sD    ::D{{}} d
	$r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r%   r   r&   r   r   r   )r:   r   r   r;   )r@   r   r   rA   )r@   r   rI   r   r   r;   )r@   r   rI   r   rO   rP   r   r;   )rl   r   r   r   )rr   r   r   r   )r   r   rw   rx   r   r   )r   r   r|   r   r   r   )r   r   r   r;   )/r   
__future__r   rf   r[   r   os.pathrerc   ra   r!   ior   pathlibr   typingr   sphinx.localer   typesr   r	   r
   r   r   r   r$   r9   r?   rH   rN   re   compilero   rq   rv   curdirrz   r   safe_relpathgetfilesystemencodinggetdefaultencodingfs_encodingr   abspathr   r   r   r   r   <module>r      s   < < " " " " " "      				  				  



                                   !######         
4 4 4 4< < < <
2 2 2 27 7 7 7.% % % %
' ' ' '8 8 8 8 	1* 1* 1* 1* 1* 1*h BJ())	1 1 1 1I I I I
 JL    0 0 0 0* 'c'))E-CS-C-E-E '/<' <' <' <' <' <' <' <'~     r   