
    }c                     j   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 ddlm	Z	 ddl
mZmZmZmZmZmZ 	 ddlm	Z n# e$ r dZY nw xY wdZdedefd	Zd
edefdZdededefdZdeddfdZdee         dedee         fdZdededdfdZdededdfdZ ej        d          Z ej        d          Z dedefdZ!dedefdZ"ej#        fdededefdZ$e$Z% ej&                    p ej'                    Z(d edefd!Z)ej*        d"eded#         fd$            Z+ G d% d&          Z,deddfd'Z-dS )(z6Operating system-related utility functions for Sphinx.    N)StringIOpath)Any	GeneratorIteratorListOptionalType/canonicalpathreturnc                 L    |                      t          t          j                  S N)replaceSEPr   sep)r   s    2lib/python3.11/site-packages/sphinx/util/osutil.pyos_pathr      s      dh///    
nativepathc                 L    |                      t          j        t                    S )z"Return path in OS-independent form)r   r   r   r   )r   s    r   
canon_pathr       s    dh,,,r   basetoc                 ~   |                     t                    r|S |                     d          d                             t                    }|                    d          d                             t                    }t          |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   N    .z..)
startswithr   splitzippoplenjoin)r   r   b2t2xys         r   relative_urir,   %   s#   	}}S 		C		!	!#	&	&B	#q				$	$BBssGRW%%  16 	E
q			
q					Rx  r
2ww!| rd
  Sy3J3r77Q;'#((2,,66r   r   c                 2    t          j        | d           dS )zEnsure that a path exists.T)exist_okN)osmakedirsr   s    r   	ensuredirr1   <   s    Kt$$$$$$r   dirnamessuffixc           	   #      K   | D ]r}t          j        |          D ][\  }}}|D ]R}|                    |          r;	 t          j        t          j        ||                    V  B# t          $ r Y Nw xY wS\sd S r   )r/   walkendswithr   getmtimer'   OSError)r2   r3   dirnameroot_dirsfilessfiles          r   mtimes_of_filesr>   A   s        "$''"2"2 	 	D%  >>&)) "mDIdE,B,BCCCCCC"   	 s   )A%%
A2	1A2	sourcedestc                     t          j        |           }t          t           d          r#t          j        ||j        |j        f           dS dS )z!Copy a file's modification times.utimeN)r/   stathasattrrB   st_atimest_mtime)r?   r@   sts      r   	copytimesrH   L   sL    	Br7 3
R[1222223 3r   c                     t          j        |          rt          j        | |          s9t	          j        | |           	 t          | |           dS # t          $ r Y dS w xY wdS )z{Copy a file and its modification times, if possible.

    Note: ``copyfile`` skips copying if the file has not been changedN)r   existsfilecmpcmpshutilcopyfilerH   r8   )r?   r@   s     r   rN   rN   S   s     ;t GK$=$= %%%	fd##### 	 	 	DD	 s    A 
A A z[^a-zA-Z0-9_-]z Documentation$stringc                 <    t                               d|           pdS )Nr   sphinx)no_fn_resub)rO   s    r   make_filenamerT   d   s    <<F##/x/r   projectc                 v    t          t                              d|                                                     S )Nr   )rT   project_suffix_rerS   lower)rU   s    r   make_filename_from_projectrY   h   s-    *..r7;;<<BBDDDr   startc                 h    	 t           j                            | |          S # t          $ r | 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
ValueError)r   rZ   s     r   r\   r\   l   sA    wtU+++   s   " 11pathdirc                 D   t           )t          | t                     r|                                 S t          j        |           } t          | t                    rF	 |                     t                    } n*# t          $ r}t          dt          z            |d }~ww xY w| S )NzAmultibyte filename not supported on this filesystem encoding (%r))Path
isinstanceabspathr   bytesdecodefs_encodingUnicodeDecodeError)r^   excs     r   rb   rb   }   s     Jw55    ,w''gu%% 	HH!..55% H H H( *02=*> ? ?DGHH s   A6 6
B BB
target_dir)NNNc              #      K   t          j                    }	 t          j        |            d V  t          j        |           d S # t          j        |           w xY wr   )r/   getcwdchdir)rh   cwds     r   cdrm      sR      
)++C

s   A Ac                   v    e Zd ZdZdeddfdZdeddfdZddZdd	Zd
e	e
         de
dedefdZdedef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   r   Nc                 "    || _         d | _        d S r   )_path_io)selfr   s     r   __init__zFileAvoidWrite.__init__   s    
'+r   datac                 n    | j         st                      | _         | j                             |           d S r   )rr   r   write)rs   ru   s     r   rw   zFileAvoidWrite.write   s1    x 	"zzDHtr   c                    | j         st          d          |                                 }| j                                          	 t	          | j        d          5 }|                                }||k    r	 ddd           dS 	 ddd           n# 1 swxY w Y   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)	rr   	Exceptiongetvaluecloseopenrq   readr8   rw   )rs   bufold_fold_contentfs        r   r}   zFileAvoidWrite.close   s   x 	LJKKKmmoo	dj7333 u#jjll#%                        	 	 	D	 $*cG444 	GGCLLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	sN   B B7B B BB BB 
B*)B*C''C+.C+c                     | S r    )rs   s    r   	__enter__zFileAvoidWrite.__enter__   s    r   exc_type	exc_value	tracebackc                 .    |                                   dS )NT)r}   )rs   r   r   r   s       r   __exit__zFileAvoidWrite.__exit__   s    

tr   namec                 X    | j         st          d          t          | j         |          S )Nz=Must write to FileAvoidWrite before other methods can be used)rr   r{   getattr)rs   r   s     r   __getattr__zFileAvoidWrite.__getattr__   s7    x 	3 2 3 3 3 tx&&&r   )r   N)r   ro   )__name__
__module____qualname____doc__strrt   rw   r}   r   r   r{   r   boolr   r   r   r   r   ro   ro      s        
 
,S ,T , , , ,# $    
   &   i Y SV [_    ' ' ' ' ' ' ' 'r   ro   c                     t           j                            |           rt          j        |            d S t          j        |            d S r   )r/   r   isdirrM   rmtreeremover   s    r   r   r      s?    	w}}T d
	$r   ).r   
contextlibrK   r/   rerM   sysior   r   typingr   r   r   r	   r
   r   sphinx.testing.pathr`   ImportErrorr   r   r   r   r,   r1   floatr>   rH   rN   compilerR   rW   rT   rY   curdirr\   safe_relpathgetfilesystemencodinggetdefaultencodingre   rb   contextmanagerrm   ro   r   r   r   r   <module>r      sl   < <      				 				  



             A A A A A A A A A A A A A A A A0000000   DDD 
03 03 0 0 0 0-3 -3 - - - -
7s 7 7 7 7 7 7.%C %D % % % %
d3i  %    3c 3 3 3 3 3 3
S 
 
 
 
 
 
 2:'((BJ011 0# 0# 0 0 0 0E E E E E E %'I 
 
# 
c 
# 
 
 
 
 'c'))E-CS-C-E-ES S     3 9%56    5' 5' 5' 5' 5' 5' 5' 5'p       s   ? A	A	