
    5bhn                     2   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Zd dl	Z	d dl
mZmZmZ ddlmZmZ ddlmZ eej&                  ef   ZeZd Zeddee   defd	       Zd
ej&                  dee   fdZej4                  dee   dej&                  fd       Zej8                  dedej&                  fd       Zej8                  dddej&                  fd       Zd Zd
ej&                  fdZej@                  	 de jB                  dd       Z"d Z#dede$fdZ%ej4                  d        Z&e&j9                  ejN                        ej@                  d               Zej@                  dejP                  fd       Z)ej@                  d        Z*d Z+y)    N)UnionOptionalcast   )ResourceReaderTraversable)	wrap_specc                 `     t               t        j                         f fd	       }|S )a  
    Replace 'package' parameter as 'anchor' and warn about the change.

    Other errors should fall through.

    >>> files('a', 'b')
    Traceback (most recent call last):
    TypeError: files() takes from 0 to 1 positional arguments but 2 were given
    c                     |ur1| ur	 | |      S t        j                  dt        d        |      S | u r        S  |       S )Nz/First parameter to files is renamed to 'anchor'   )
stacklevel)warningswarnDeprecationWarning)anchorpackagefunc	undefineds     E/opt/python-3.12.12/usr/lib/python3.12/importlib/resources/_common.pywrapperz"package_to_anchor.<locals>.wrapper!   sZ    )#Y&FG,,MMA"
 = y 6MF|    )object	functoolswraps)r   r   r   s   ` @r   package_to_anchorr      s3     I__T )   Nr   r   returnc                 *    t        t        |             S )z3
    Get a Traversable resource for an anchor.
    )from_packageresolve)r   s    r   filesr    3   s    
 ((r   r   c                 r    | j                   }t        |j                  dd      }|y ||j                        S )z?
    Return the package's loader if it's a ResourceReader.
    get_resource_readerN)__spec__getattrloadernamer   specreaders      r   r"   r"   ;   s9     DT[["7>F~$))r   candc                 6    t        t        j                  |       S N)r   types
ModuleTyper*   s    r   r   r   K   s      $''r   c                 ,    t        j                  |       S r,   )	importlibimport_moduler/   s    r   _r3   P   s    ""4((r   c                 B    t        t               j                  d         S )N__name__)r   _infer_caller	f_globalsr/   s    r   r3   r3   U   s    =?,,Z899r   c                      fd} d }t        j                         t        j                  |       }t        j                  ||      }t	        |      j
                  S )zS
    Walk the stack and find the frame of the first caller not in this module.
    c                 <    | j                   d   j                   k(  S )Nr   )filename)
frame_infostacks    r   is_this_filez#_infer_caller.<locals>.is_this_file_   s    ""eAh&7&777r   c                      | j                   dk(  S )Nr   )function)r;   s    r   
is_wrapperz!_infer_caller.<locals>.is_wrapperb   s    ""i//r   )inspectr<   	itertoolsfilterfalsenextframe)r=   r@   not_this_filecallersr<   s       @r   r6   r6   Z   sN    
80 MMOE)),>M##J>G=r   c                     t        |       }|j                  j                  |j                        }|j	                         S )z=
    Return a Traversable object for the given package.

    )r	   r%   r"   r&   r    r'   s      r   r   r   l   s2    
 WD[[,,TYY7F<<>r   )
_os_removec             #   p  K   t        j                  |      \  }}	 	 t        j                  | |               t        j                  |       ~ t        j                  |       	  ||       y # t        j                  |       w xY w# t        $ r Y y w xY w# 	  ||       w # t        $ r Y w w xY wxY wwN)suffix)tempfilemkstemposwriteclosepathlibPathFileNotFoundError)r)   rL   rI   fdraw_paths        r   	_tempfilerW   v   s      ##62LB	HHR"HHRLll8$$	x  HHRL ! 			x   		so   B6A0 -B 'B
 /B60BB 
	BB6BB6B3B$#B3$	B0-B3/B00B33B6c                 D    t        | j                  | j                        S rK   )rW   
read_bytesr&   paths    r   
_temp_filer\      s    T__TYY77r   r[   c                     t        j                  t              5  | j                         cddd       S # 1 sw Y   yxY w)a  
    Some Traversables implement ``is_dir()`` to raise an
    exception (i.e. ``FileNotFoundError``) when the
    directory doesn't exist. This function wraps that call
    to always return a boolean and only return True
    if there's a dir and it exists.
    NF)
contextlibsuppressrT   is_dirrZ   s    r   _is_present_dirra      s+     
		.	/{{} 
0	/	/s   4=c                 D    t        |       rt        |       S t        |       S )zu
    Given a Traversable object, return that object as a
    path on the local file system in a context manager.
    )ra   	_temp_dirr\   rZ   s    r   as_filerd      s     .d39T?ID9IIr   c              #      K   |  yw)z7
    Degenerate behavior for pathlib.Path objects.
    N rZ   s    r   r3   r3      s      Js   dirc              #   h   K   | 5 }t        j                  |       ddd       y# 1 sw Y   yxY ww)zD
    Wrap tempfile.TemporyDirectory to return a pathlib object.
    N)rR   rS   )rg   results     r   
_temp_pathrj      s%     
 
ll6"" 
s   2&	2/2c              #      K   | j                         sJ t        t        j                               5 }t	        ||        ddd       y# 1 sw Y   yxY ww)zt
    Given a traversable dir, recursively replicate the whole tree
    to the file system in a context manager.
    N)r`   rj   rM   TemporaryDirectory_write_contents)r[   temp_dirs     r   rc   rc      sA      ;;==	H//1	2hh-- 
3	2	2s   0AA
	A
AAc                     | j                  |j                        }|j                         r3|j                          |j	                         D ]  }t        ||        |S |j                  |j                                |S r,   )joinpathr&   r`   mkdiriterdirrm   write_bytesrY   )targetsourcechilditems       r   rm   rm      sf    OOFKK(E}}NN$DE4( % L 	&++-.Lr   r,   ) ),rO   rR   rM   r   r^   r-   r1   rA   r   rB   typingr   r   r   abcr   r   	_adaptersr	   r.   strPackageAnchorr   r    r"   singledispatchr   registerr3   r6   r   contextmanagerremoverW   r\   boolra   rd   rS   rl   rj   rc   rm   rf   r   r   <module>r      s   	          ( ( ,  
  #%
&	< )(6" )k ) )!1!1 h~6N   ((6" (u'7'7 ( ( 	)C )E$$ ) ) 	:D :U%% : :$%**    yy 48
+ 
$ 
 J J 	',,    #H// # # . .r   