o
    3Ih                     @   sd   d dl mZ d dlmZ ddlmZ G dd dZG dd dZdd
dZG dd dZ	dd Z
dS )    )suppress)TextIOWrapper   )abcc                   @   s(   e Zd ZdZdd fddZdd ZdS )	SpecLoaderAdapterz>
    Adapt a package spec to adapt the underlying loader.
    c                 C      | j S N)loaderspec r   ]/home/air/sanwanet/gpt-api/venv/lib/python3.10/site-packages/importlib_resources/_adapters.py<lambda>   s    zSpecLoaderAdapter.<lambda>c                 C   s   || _ ||| _d S r   )r   r	   )selfr   adapterr   r   r   __init__   s   zSpecLoaderAdapter.__init__c                 C      t | j|S r   )getattrr   r   namer   r   r   __getattr__      zSpecLoaderAdapter.__getattr__N)__name__
__module____qualname____doc__r   r   r   r   r   r   r      s    r   c                   @   s    e Zd ZdZdd Zdd ZdS )TraversableResourcesLoaderz9
    Adapt a loader to provide TraversableResources.
    c                 C   
   || _ d S r   r
   r   r   r   r   r   r         
z#TraversableResourcesLoader.__init__c                 C   s   t | j S r   )CompatibilityFilesr   _nativer   r   r   r   get_resource_reader      z.TraversableResourcesLoader.get_resource_readerN)r   r   r   r   r   r"   r   r   r   r   r      s    r   rc                 O   s:   |dkrt | g|R i |S |dkr| S td| d)Nr$   rbzInvalid mode value 'z"', only 'r' and 'rb' are supported)r   
ValueError)filemodeargskwargsr   r   r   _io_wrapper    s
   r+   c                   @   sr   e Zd ZdZG dd dejZG dd dejZG dd dejZdd	 Z	e
d
d Zdd Zdd Zdd ZdS )r    zj
    Adapter for an existing or non-existent resource reader
    to provide a compatibility .files().
    c                   @   J   e Zd ZdZdd Zdd Zdd ZeZdd	 Ze	d
d Z
dddZdS )zCompatibilityFiles.SpecPathzk
        Path tied to a module spec.
        Can be read and exposes the resource reader children.
        c                 C      || _ || _d S r   )_spec_reader)r   r   readerr   r   r   r   4      
z$CompatibilityFiles.SpecPath.__init__c                    s*    j stdS t fdd j  D S )Nr   c                 3   s    | ]
}t  j|V  qd S r   )r    	ChildPathr/   ).0pathr   r   r   	<genexpr>;   s
    
z6CompatibilityFiles.SpecPath.iterdir.<locals>.<genexpr>)r/   itercontentsr5   r   r5   r   iterdir8   s
   z#CompatibilityFiles.SpecPath.iterdirc                 C      dS NFr   r5   r   r   r   is_file@      z#CompatibilityFiles.SpecPath.is_filec                 C   s   | j st|S t| j |S r   )r/   r    
OrphanPathr2   r   otherr   r   r   joinpathE   s   
z$CompatibilityFiles.SpecPath.joinpathc                 C   s   | j jS r   )r.   r   r5   r   r   r   r   J   s   z CompatibilityFiles.SpecPath.namer$   c                 O   s    t | jd |g|R i |S r   )r+   r/   open_resourcer   r(   r)   r*   r   r   r   openN   s    z CompatibilityFiles.SpecPath.openNr$   r   r   r   r   r   r9   r<   is_dirrA   propertyr   rD   r   r   r   r   SpecPath.   s    
rI   c                   @   sN   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Ze	dd Z
dddZdS )zCompatibilityFiles.ChildPathzw
        Path tied to a resource reader child.
        Can be read but doesn't expose any meaningful children.
        c                 C   r-   r   )r/   _name)r   r0   r   r   r   r   r   W   r1   z%CompatibilityFiles.ChildPath.__init__c                 C      t dS Nr   r7   r5   r   r   r   r9   [      z$CompatibilityFiles.ChildPath.iterdirc                 C   s   | j | jS r   )r/   is_resourcer   r5   r   r   r   r<   ^   r#   z$CompatibilityFiles.ChildPath.is_filec                 C   s
   |    S r   )r<   r5   r   r   r   rG   a   r   z#CompatibilityFiles.ChildPath.is_dirc                 C   s   t | j|S r   )r    r>   r   r?   r   r   r   rA   d   r#   z%CompatibilityFiles.ChildPath.joinpathc                 C   r   r   )rJ   r5   r   r   r   r   g   s   z!CompatibilityFiles.ChildPath.namer$   c                 O   s"   t | j| j|g|R i |S r   )r+   r/   rB   r   rC   r   r   r   rD   k   s   z!CompatibilityFiles.ChildPath.openNrE   rF   r   r   r   r   r2   Q   s    
r2   c                   @   r,   )zCompatibilityFiles.OrphanPathz
        Orphan path, not tied to a module spec or resource reader.
        Can't be read and doesn't expose any meaningful children.
        c                 G   s   t |dk r
td|| _d S )Nr   z/Need at least one path part to construct a path)lenr&   _path)r   
path_partsr   r   r   r   v   s   
z&CompatibilityFiles.OrphanPath.__init__c                 C   rK   rL   rM   r5   r   r   r   r9   {   rN   z%CompatibilityFiles.OrphanPath.iterdirc                 C   r:   r;   r   r5   r   r   r   r<   ~   r=   z%CompatibilityFiles.OrphanPath.is_filec                 C   s   t jg | j|R  S r   )r    r>   rQ   r?   r   r   r   rA      s   z&CompatibilityFiles.OrphanPath.joinpathc                 C   s
   | j d S )N)rQ   r5   r   r   r   r      s   
z"CompatibilityFiles.OrphanPath.namer$   c                 O   s   t d)NzCan't open orphan path)FileNotFoundErrorrC   r   r   r   rD      rN   z"CompatibilityFiles.OrphanPath.openNrE   rF   r   r   r   r   r>   p   s    
r>   c                 C   r   r   r
   r   r   r   r   r      r   zCompatibilityFiles.__init__c                 C   s>   t t | jj| jjW  d    S 1 sw   Y  d S r   )r   AttributeErrorr   r	   r"   r   r5   r   r   r   r/      s   
$zCompatibilityFiles._readerc                 C   s   | j }t|dr
|S | S )zB
        Return the native reader if it supports files().
        files)r/   hasattr)r   r0   r   r   r   r!      s   zCompatibilityFiles._nativec                 C   r   r   )r   r/   )r   attrr   r   r   r      r   zCompatibilityFiles.__getattr__c                 C   s   t | j| jS r   )r    rI   r   r/   r5   r   r   r   rV      s   zCompatibilityFiles.filesN)r   r   r   r   r   TraversablerI   r2   r>   r   rH   r/   r!   r   rV   r   r   r   r   r    (   s    #
r    c                 C   s   t | jtS )z`
    Construct a package spec with traversable compatibility
    on the spec/loader/reader.
    )r   __spec__r   )packager   r   r   	wrap_spec   s   r\   NrE   )
contextlibr   ior    r   r   r   r+   r    r\   r   r   r   r   <module>   s    
{