U
    ½mœdQ  ã                   @   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 ddl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)ÚUnionÚOptionalÚcasté   )ÚResourceReaderÚTraversable)Ú	wrap_specc                    s(   t ƒ ‰t ˆ ¡ˆˆf‡ ‡fd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                    sH   |ˆk	r2| ˆk	rˆ | |ƒS t jdtdd� ˆ |ƒS | ˆkr@ˆ ƒ S ˆ | ƒS )Nz/First parameter to files is renamed to 'anchor'é   )Ú
stacklevel)ÚwarningsÚwarnÚDeprecationWarning)ÚanchorÚpackage©ÚfuncÚ	undefined© úT/home/sam/Atlas/atlas_env/lib/python3.8/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k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                  C   s6   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   s
   | j tkS r'   )ÚfilenameÚ__file__©Ú
frame_infor   r   r   Úis_this_file_   s    z#_infer_caller.<locals>.is_this_filec                 S   s
   | j dkS )Nr   )Úfunctionr3   r   r   r   Ú
is_wrapperb   s    z!_infer_caller.<locals>.is_wrapper)Ú	itertoolsÚfilterfalseÚinspectÚstackÚnextÚframe)r5   r7   Znot_this_fileÚcallersr   r   r   r/   Z   s
    r/   )r   c                 C   s   t | ƒ}|j |j¡}| ¡ S )z=
    Return a Traversable object for the given package.

    )r   r!   r   r"   r   r#   r   r   r   r   k   s    r   Ú )Ú
_os_removec                c   sl   t j|d�\}}z2zt || ƒ ¡ W 5 t |¡ X ~ t |¡V  W 5 z||ƒ W n tk
rd   Y nX X d S ©N)Úsuffix)ÚtempfileÚmkstempÚFileNotFoundErrorÚosÚcloseÚwriteÚpathlibÚPath)r%   rB   r@   ÚfdÚraw_pathr   r   r   Ú	_tempfileu   s    rM   c                 C   s   t | j| jd�S rA   )rM   Ú
read_bytesr"   ©Úpathr   r   r   Ú
_temp_file�   s    rQ   )rP   r   c              
   C   s*   t  t¡� |  ¡ W  5 Q R £ S Q R X 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.
    F)Ú
contextlibÚsuppressrE   Úis_dirrO   r   r   r   Ú_is_present_dir”   s    rU   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.
    )rU   Ú	_temp_dirrQ   rO   r   r   r   Úas_file¡   s    rW   c                 c   s
   | V  dS )z7
    Degenerate behavior for pathlib.Path objects.
    Nr   rO   r   r   r   r-   ª   s    )Údirc              	   c   s    | �}t  |¡V  W 5 Q R X dS )zD
    Wrap tempfile.TemporyDirectory to return a pathlib object.
    N)rI   rJ   )rX   Úresultr   r   r   Ú
_temp_path³   s    rZ   c              	   c   s4   |   ¡ st‚tt ¡ ƒ�}t|| ƒV  W 5 Q R X dS )zt
    Given a traversable dir, recursively replicate the whole tree
    to the file system in a context manager.
    N)rT   ÚAssertionErrorrZ   rC   ÚTemporaryDirectoryÚ_write_contents)rP   Útemp_dirr   r   r   rV   ¼   s    rV   c                 C   sH   |   |j¡}| ¡ r6| ¡  | ¡ D ]}t||ƒ q$n| | ¡ ¡ |S r'   )Újoinpathr"   rT   ÚmkdirÚiterdirr]   Úwrite_bytesrN   )ÚtargetÚsourceÚchildÚitemr   r   r   r]   Ç   s    r]   )N)r?   ),rF   rI   rC   r   rR   r(   r+   r:   r   r8   Útypingr   r   r   Úabcr   r   Z_compatr   r)   ÚstrÚPackageZAnchorr   r   r   Úsingledispatchr   Úregisterr-   r/   r   ÚcontextmanagerÚremoverM   rQ   ÚboolrU   rW   rJ   r\   rZ   rV   r]   r   r   r   r   Ú<module>   sV   
 þú



