U
    ^»{jø  ã                   @   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)ÚUnionÚOptionalÚ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   |ˆ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©ÚfuncZ	undefined© úZ/var/www/html/bwave/python/venv/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                     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   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"   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   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ÚsuppressrB   Ú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   s    | �}t  |¡V  W 5 Q R X dS )zF
    Wrap tempfile.TemporaryDirectory to return a pathlib object.
    N)rF   rG   )rU   Úresultr   r   r   Ú
_temp_path·   s    rW   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)rQ   ÚAssertionErrorrW   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ÚiterdirrZ   Úwrite_bytesrK   )ÚtargetÚsourceÚchildÚitemr   r   r   rZ   Ë   s    rZ   )N)r<   )*rC   rF   r@   r   rO   r%   r(   r6   r
   r7   Útypingr   r   r   Úabcr   r   r&   ÚstrÚPackageZAnchorr   r   r   Úsingledispatchr   Úregisterr*   r,   r   ÚcontextmanagerÚremoverJ   rN   ÚboolrR   rT   rG   rY   rW   rS   rZ   r   r   r   r   Ú<module>   sT     þú



