a
    ij                     @   s  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 eejef ZeZdd Zed+ee eddd	Zejee d
ddZejee ejdddZejeejdddZejdejdddZdd ZejdddZe jd,ejdddZ dd Z!ee"ddd Z#ejd!d" Z$e$ej%e jd#d Ze jej&d$d%d&Z'e jd'd( Z(d)d* Z)dS )-    N)OptionalUnioncast   )ResourceReaderTraversablec                    s(   t  t f fdd	}|S )a1  
    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

    Remove this compatibility in Python 3.14.
    c                    sH   |ur2| ur | |S t jdtdd  |S | u r@  S  | S )Nz/First parameter to files is renamed to 'anchor'   )
stacklevel)warningswarnDeprecationWarning)anchorpackagefuncZ	undefined Y/home/ghrups/robot-bench/.venv/lib/python3.9/site-packages/importlib_resources/_common.pywrapper!   s    
z"package_to_anchor.<locals>.wrapper)object	functoolswraps)r   r   r   r   r   package_to_anchor   s    r   )r   returnc                 C   s   t t| S )z3
    Get a Traversable resource for an anchor.
    )from_packageresolve)r   r   r   r   files3   s    r   )r   r   c                 C   s*   | j }t|jdd}|du r dS ||jS )z?
    Return the package's loader if it's a ResourceReader.
    get_resource_readerN)__spec__getattrloadername)r   specreaderr   r   r   r   ;   s
    	r   )candr   c                 C   s   t tj| S N)r   types
ModuleTyper#   r   r   r   r   K   s    r   c                 C   s
   t | S r$   )	importlibimport_moduler'   r   r   r   _P   s    r*   c                 C   s   t t jd S )N__name__)r   _infer_caller	f_globalsr'   r   r   r   r*   U   s    c                     s>    fdd} dd }t   t|  }t||}t|jS )zS
    Walk the stack and find the frame of the first caller not in this module.
    c                    s   | j  d j kS )Nr   )filename
frame_infostackr   r   is_this_file_   s    z#_infer_caller.<locals>.is_this_filec                 S   s
   | j dkS )Nr   )functionr/   r   r   r   
is_wrapperb   s    z!_infer_caller.<locals>.is_wrapper)inspectr2   	itertoolsfilterfalsenextframe)r3   r5   Znot_this_fileZcallersr   r1   r   r,   Z   s    r,   )r   c                 C   s*   ddl m} || }|j|j}| S )z=
    Return a Traversable object for the given package.

    r   )	wrap_spec)Zfuture.adaptersr;   r   r   r    r   )r   r;   r!   r"   r   r   r   r   l   s    r    )
_os_removec                c   s   t j|d\}}z\zt||   W t| nt| 0 ~ t|V  W z|| W q tyj   Y q0 n"z|| W n ty   Y n0 0 d S N)suffix)tempfilemkstemposwriteclosepathlibPathFileNotFoundError)r"   r?   r=   fdraw_pathr   r   r   	_tempfiley   s    rJ   c                 C   s   t | j| jdS r>   )rJ   
read_bytesr    pathr   r   r   
_temp_file   s    rN   )rM   r   c                 C   s6   t t |  W  d   S 1 s(0    Y  dS )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suppressrG   is_dirrL   r   r   r   _is_present_dir   s    &rR   c                 C   s   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.
    )rR   	_temp_dirrN   rL   r   r   r   as_file   s    rT   c                 c   s
   | V  dS )z7
    Degenerate behavior for pathlib.Path objects.
    Nr   rL   r   r   r   r*      s    )dirc                 c   s4   | }t |V  W d   n1 s&0    Y  dS )zF
    Wrap tempfile.TemporaryDirectory to return a pathlib object.
    N)rE   rF   )rU   resultr   r   r   
_temp_path   s    rW   c                 c   sH   |   sJ tt }t|| V  W d   n1 s:0    Y  dS )zt
    Given a traversable dir, recursively replicate the whole tree
    to the file system in a context manager.
    N)rQ   rW   r@   TemporaryDirectory_write_contents)rM   temp_dirr   r   r   rS      s    rS   c                 C   sH   |  |j}| r6|  | D ]}t|| q$n||  |S r$   )joinpathr    rQ   mkdiriterdirrY   write_bytesrK   )targetsourcechilditemr   r   r   rY      s    rY   )N)r<   )*rO   r   r(   r6   r7   rB   rE   r@   r%   r
   typingr   r   r   abcr   r   r&   strPackageZAnchorr   r   r   singledispatchr   registerr*   r,   r   contextmanagerremoverJ   rN   boolrR   rT   rF   rX   rW   rS   rY   r   r   r   r   <module>   sT     



