
    h                         d dl mZ d dlmZ ddlmZ  G d d          Z G d d          Zdd
Z G d d          Z	d Z
dS )    )suppress)TextIOWrapper   )abcc                   $    e Zd ZdZd fdZd ZdS )SpecLoaderAdapterz>
    Adapt a package spec to adapt the underlying loader.
    c                     | j         S N)loaderspecs    4/usr/lib/python3.11/importlib/resources/_adapters.py<lambda>zSpecLoaderAdapter.<lambda>   s    $+     c                 4    || _          ||          | _        d S r
   )r   r   )selfr   adapters      r   __init__zSpecLoaderAdapter.__init__   s    	gdmmr   c                 ,    t          | j        |          S r
   )getattrr   r   names     r   __getattr__zSpecLoaderAdapter.__getattr__   s    ty$'''r   N)__name__
__module____qualname____doc__r   r    r   r   r   r      sI          &>%= $ $ $ $( ( ( ( (r   r   c                       e Zd ZdZd Zd ZdS )TraversableResourcesLoaderz9
    Adapt a loader to provide TraversableResources.
    c                     || _         d S r
   r   r   r   s     r   r   z#TraversableResourcesLoader.__init__       			r   c                 N    t          | j                                                  S r
   )CompatibilityFilesr   _nativer   s     r   get_resource_readerz.TraversableResourcesLoader.get_resource_reader   s    !$),,44666r   N)r   r   r   r   r   r'   r   r   r   r    r       s<           7 7 7 7 7r   r    rc                     |dk    rt          | g|R i |S |dk    r| S t          d                    |                    )Nr(   rbz8Invalid mode value '{}', only 'r' and 'rb' are supported)r   
ValueErrorformat)filemodeargskwargss       r   _io_wrapperr1       sZ    s{{T3D333F333	
BII$OO  r   c                       e Zd ZdZ G d dej                  Z G d dej                  Z G d dej                  Zd Z	e
d	             Zd
 Zd Zd ZdS )r%   zj
    Adapter for an existing or non-existent resource reader
    to provide a compatibility .files().
    c                   L    e Zd ZdZd Zd Zd ZeZd Ze	d             Z
d
dZd	S )CompatibilityFiles.SpecPathzk
        Path tied to a module spec.
        Can be read and exposes the resource reader children.
        c                 "    || _         || _        d S r
   )_spec_reader)r   r   readers      r   r   z$CompatibilityFiles.SpecPath.__init__6   s    DJ!DLLLr   c                       j         st          d          S t           fd j                                         D                       S )Nr   c              3   X   K   | ]$}t                               j        |          V  %d S r
   )r%   	ChildPathr7   ).0pathr   s     r   	<genexpr>z6CompatibilityFiles.SpecPath.iterdir.<locals>.<genexpr>=   sI         #,,T\4@@     r   )r7   itercontentsr   s   `r   iterdirz#CompatibilityFiles.SpecPath.iterdir:   s^    <  Bxx     L1133     r   c                     dS NFr   rA   s    r   is_filez#CompatibilityFiles.SpecPath.is_fileB       5r   c                     | j         st                              |          S t                              | j         |          S r
   )r7   r%   
OrphanPathr;   r   others     r   joinpathz$CompatibilityFiles.SpecPath.joinpathG   s8    < <)44U;;;%//eDDDr   c                     | j         j        S r
   )r6   r   rA   s    r   r   z CompatibilityFiles.SpecPath.nameL   s    :?"r   r(   c                 T    t          | j                            d           |g|R i |S r
   )r1   r7   open_resourcer   r.   r/   r0   s       r   openz CompatibilityFiles.SpecPath.openP   s3    t|99$??WWWWPVWWWr   Nr(   r   r   r   r   r   rB   rE   is_dirrK   propertyr   rP   r   r   r   SpecPathr4   0   s        	 	
	" 	" 	"	 	 		 	 	 	E 	E 	E
 
	# 	# 
	#	X 	X 	X 	X 	X 	Xr   rU   c                   N    e Zd ZdZd Zd Zd Zd Zd Ze	d             Z
dd	Zd
S )CompatibilityFiles.ChildPathzw
        Path tied to a resource reader child.
        Can be read but doesn't expose any meaningful children.
        c                 "    || _         || _        d S r
   )r7   _name)r   r8   r   s      r   r   z%CompatibilityFiles.ChildPath.__init__Y   s    !DLDJJJr   c                      t          d          S Nr   r?   rA   s    r   rB   z$CompatibilityFiles.ChildPath.iterdir]       88Or   c                 @    | j                             | j                  S r
   )r7   is_resourcer   rA   s    r   rE   z$CompatibilityFiles.ChildPath.is_file`   s    <++DI666r   c                 ,    |                                   S r
   )rE   rA   s    r   rS   z#CompatibilityFiles.ChildPath.is_dirc   s    ||~~%%r   c                 B    t                               | j        |          S r
   )r%   rH   r   rI   s     r   rK   z%CompatibilityFiles.ChildPath.joinpathf   s    %00EBBBr   c                     | j         S r
   )rY   rA   s    r   r   z!CompatibilityFiles.ChildPath.namei   s
    :r   r(   c                 ^    t          | j                            | j                  |g|R i |S r
   )r1   r7   rN   r   rO   s       r   rP   z!CompatibilityFiles.ChildPath.openm   sE    **4955t>B  FL  r   NrQ   rR   r   r   r   r;   rW   S   s        	 	
	 	 		 	 		7 	7 	7	& 	& 	&	C 	C 	C 
	 	 
		 	 	 	 	 	r   r;   c                   L    e Zd ZdZd Zd Zd ZeZd Ze	d             Z
d
dZd	S )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                 X    t          |          dk     rt          d          || _        d S )Nr   z/Need at least one path part to construct a path)lenr+   _path)r   
path_partss     r   r   z&CompatibilityFiles.OrphanPath.__init__x   s-    :"" !RSSS#DJJJr   c                      t          d          S r[   r\   rA   s    r   rB   z%CompatibilityFiles.OrphanPath.iterdir}   r]   r   c                     dS rD   r   rA   s    r   rE   z%CompatibilityFiles.OrphanPath.is_file   rF   r   c                 2    t          j        g | j        |R  S r
   )r%   rH   rh   rI   s     r   rK   z&CompatibilityFiles.OrphanPath.joinpath   s     %0D$*DeDDDDr   c                     | j         d         S )N)rh   rA   s    r   r   z"CompatibilityFiles.OrphanPath.name   s    :b>!r   r(   c                      t          d          )NzCan't open orphan path)FileNotFoundErrorrO   s       r   rP   z"CompatibilityFiles.OrphanPath.open   s    #$<===r   NrQ   rR   r   r   r   rH   re   r   s        	 	
	$ 	$ 	$
	 	 		 	 	 	E 	E 	E 
	" 	" 
	"	> 	> 	> 	> 	> 	>r   rH   c                     || _         d S r
   r   r"   s     r   r   zCompatibilityFiles.__init__   r#   r   c                     t          t                    5  | j        j                            | j        j                  cd d d            S # 1 swxY w Y   d S r
   )r   AttributeErrorr   r   r'   r   rA   s    r   r7   zCompatibilityFiles._reader   s    n%% 	H 	H9#77	GG	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	Hs   )AAAc                 8    | j         }t          |d          r|n| S )zB
        Return the native reader if it supports files().
        files)r7   hasattr)r   r8   s     r   r&   zCompatibilityFiles._native   s$      11;vvt;r   c                 ,    t          | j        |          S r
   )r   r7   )r   attrs     r   r   zCompatibilityFiles.__getattr__   s    t|T***r   c                 L    t                               | j        | j                  S r
   )r%   rU   r   r7   rA   s    r   ru   zCompatibilityFiles.files   s    !**49dlCCCr   N)r   r   r   r   r   TraversablerU   r;   rH   r   rT   r7   r&   r   ru   r   r   r   r%   r%   *   s
        
!X !X !X !X !X3? !X !X !XF    CO   >> > > > >S_ > > >:   H H XH< < <+ + +D D D D Dr   r%   c                 6    t          | j        t                    S )z`
    Construct a package spec with traversable compatibility
    on the spec/loader/reader.
    )r   __spec__r    )packages    r   	wrap_specr~      s    
 W-/IJJJr   NrQ   )
contextlibr   ior    r   r   r    r1   r%   r~   r   r   r   <module>r      s                     
( 
( 
( 
( 
( 
( 
( 
(	7 	7 	7 	7 	7 	7 	7 	7   xD xD xD xD xD xD xD xDvK K K K Kr   