
    .Ph,                     ,   d Z ddlZddlZddlZddlZddlmZ ddlmZm	Z	m
Z
mZmZmZmZmZ ddlmZ ddlmZmZ ddlmZmZ eeeeef         eef         Zdd	gZ G d
 d          Z G d dee          Z G d dee          Z G d d	e          Z dS )z)Source of information about a wheel file.    N)contextmanager)BinaryIOClassVarIteratorListOptionalTupleTypecast)InstallerError)RecordEntryparse_record_file)canonicalize_nameparse_wheel_filenameWheelSource	WheelFilec                        e Zd ZU dZeZeee                  e	d<   de
de
ddf fdZed             Zed	             Zedee
         fd
            Zde
de
fdZddZdee         fdZ xZS )r   zyRepresents an installable wheel.

    This is an abstract class, whose methods have to be implemented by subclasses.
    validation_errordistributionversionreturnNc                 d    t                                                       || _        || _        dS )zInitialize a WheelSource object.

        :param distribution: distribution name (like ``urllib3``)
        :param version: version associated with the wheel
        N)super__init__r   r   )selfr   r   	__class__s      Q/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/installer/sources.pyr   zWheelSource.__init__   s.     	(    c                 &    | j          d| j         dS ) Name of the dist-info directory.-
.dist-infor   r   r   s    r   dist_info_dirzWheelSource.dist_info_dir&   s      #>>dl>>>>r   c                 &    | j          d| j         dS )zName of the data directory.r!   z.datar#   r$   s    r   data_dirzWheelSource.data_dir+   s      #99dl9999r   c                     t           )zGet names of all files in the dist-info directory.

        Sample usage/behaviour::

            >>> wheel_source.dist_info_filenames
            ['METADATA', 'WHEEL']
        NotImplementedErrorr$   s    r   dist_info_filenameszWheelSource.dist_info_filenames0   s
     "!r   filenamec                     t           )zGet contents, from ``filename`` in the dist-info directory.

        Sample usage/behaviour::

            >>> wheel_source.read_dist_info("METADATA")
            ...

        :param filename: name of the file
        r)   )r   r,   s     r   read_dist_infozWheelSource.read_dist_info;   s
     "!r   c                     t           )zValidate ``RECORD`` of the wheel.

        This method should be called before :py:func:`install <installer.install>`
        if validation is required.
        r)   r$   s    r   validate_recordzWheelSource.validate_recordG   s
     "!r   c                     t           )a  Sequential access to all contents of the wheel (including dist-info files).

        This method should return an iterable. Each value from the iterable must be a
        tuple containing 3 elements:

        - record: 3-value tuple, to pass to
          :py:meth:`RecordEntry.from_elements <installer.records.RecordEntry.from_elements>`.
        - stream: An :py:class:`io.BufferedReader` object, providing the contents of the
          file at the location provided by the first element (path).
        - is_executable: A boolean, representing whether the item has an executable bit.

        All paths must be relative to the root of the wheel.

        Sample usage/behaviour::

            >>> iterable = wheel_source.get_contents()
            >>> next(iterable)
            (('pkg/__init__.py', '', '0'), <...>, False)

        This method may be called multiple times. Each iterable returned must
        provide the same content upon reading from a specific file's stream.
        r)   r$   s    r   get_contentszWheelSource.get_contentsO   s
    . "!r   )r   N)__name__
__module____qualname____doc__
ValueErrorr   r   r
   	Exception__annotations__strr   propertyr%   r'   r   r+   r.   r0   r   WheelContentElementr2   __classcell__r   s   @r   r   r      s2         
 3=htI/<<<S 3 4       ? ? X? : : X: "T#Y " " " X"
"s 
"s 
" 
" 
" 
"" " " ""h':; " " " " " " " "r   c                   D     e Zd ZdZdee         ddf fdZdefdZ xZS )_WheelFileValidationErrorz*Raised when a wheel file fails validation.issuesr   Nc                 r    t                                          t          |                     || _        d S N)r   r   reprrA   )r   rA   r   s     r   r   z"_WheelFileValidationError.__init__l   s,    f&&&r   c                     d| j         dS )Nz WheelFileValidationError(issues=))rA   r$   s    r   __repr__z"_WheelFileValidationError.__repr__p   s    B$+BBBBr   )	r3   r4   r5   r6   r   r:   r   rG   r=   r>   s   @r   r@   r@   i   sy        44tCy T      C# C C C C C C C Cr   r@   c                   L     e Zd ZdZdedee         deddf fdZdefdZ xZS )	_WheelFileBadDistInfoz8Raised when a wheel file has issues around `.dist-info`.reasonr,   	dist_infor   Nc                t    t                                          |           || _        || _        || _        d S rC   )r   r   rJ   r,   rK   )r   rJ   r,   rK   r   s       r   r   z_WheelFileBadDistInfo.__init__w   s4        "r   c                 6    | j          d| j        d| j        dS )Nz (filename=z, dist_info=rF   rJ   r,   rK   r$   s    r   __str__z_WheelFileBadDistInfo.__str__}   s)    {WWt}WWDNWWW	
r   )	r3   r4   r5   r6   r:   r   r   rO   r=   r>   s   @r   rI   rI   t   s        BB## ## #3 #SW # # # # # #
 
 
 
 
 
 
 
 
r   rI   c                        e Zd ZdZeZdej        ddf fdZe	e
ddded          fd                        Zedefd	            Zedee         fd
            ZdedefdZdddeddfdZdee         fdZ xZS )r   zImplements `WheelSource`, for an existing file from the filesystem.

    Example usage::

        >>> with WheelFile.open("sampleproject-2.0.0-py3-none-any.whl") as source:
        ...     installer.install(source, destination)
    fr   Nc                     || _         |j        sJ t          j                            |j                  }t          |          }t                                          |j        |j	                   d| _
        dS )zInitialize a WheelFile object.

        :param f: An open zipfile, which will stay open as long as this object is used.
        )r   r   N)_zipfiler,   ospathbasenamer   r   r   r   r   _dist_info_dir)r   rQ   rV   parsed_namer   s       r   r   zWheelFile.__init__   s{    
 z7##AJ//*844'$1 	 	
 	
 	
 .2r   rU   zos.PathLike[str]c              #   ~   K   t          j        |          5 } | |          V  ddd           dS # 1 swxY w Y   dS )z%Create a wheelfile from a given path.N)zipfileZipFile)clsrU   rQ   s      r   openzWheelFile.open   s       _T"" 	a#a&&LLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   266c           
         | j         | j         S d | j                                        D             }d |D             }	 |\  }nE# t          $ r8 t	          d| j        j        t          t          |                              dw xY w|                    dd          d         }t          |          }t          | j
                  }||k    rt	          d	| j        j        |          || _         |S )
r    Nc                 F    h | ]}|                     d d          d         S )/   r   )split).0rU   s     r   	<setcomp>z*WheelFile.dist_info_dir.<locals>.<setcomp>   s8     !
 !
 !
&*DJJsAq!!
 !
 !
r   c                 <    g | ]}|                     d           |S )r"   )endswith)rc   names     r   
<listcomp>z+WheelFile.dist_info_dir.<locals>.<listcomp>   s9     
 
 
dmmL6Q6Q

 
 
r   z6Wheel doesn't contain exactly one .dist-info directoryrN   r!      r   z7Wheel .dist-info directory doesn't match wheel filename)rW   rS   namelistr7   rI   r,   r:   sortedrsplitr   r   )r   top_level_directories
dist_infosr%   di_dnamenorm_di_dnamenorm_file_dnames          r   r%   zWheelFile.dist_info_dir   s>    *&&!
 !
.2m.D.D.F.F!
 !
 !

 
2
 
 

	)]] 	 	 	'O/fZ0011   		 !''Q//2)(33+D,=>>O++'P/'    ,s   A ABc                 \    | j         fd| j                                        D             S )z2Get names of all files in the dist-info directory.c                     g | ]D}|d d         dk    r4t          j        |g          k    *|t                    dz   d         ES )Nr`   ra   )	posixpathcommonprefixlen)rc   rg   bases     r   rh   z1WheelFile.dist_info_filenames.<locals>.<listcomp>   se     
 
 
BCCyCy-tTl;;;; TQ! <;;r   )r%   rS   rj   )r   rx   s    @r   r+   zWheelFile.dist_info_filenames   sF     !
 
 
 
..00
 
 
 	
r   r,   c                     t          j        | j        |          }| j                            |                              d          S )z;Get contents, from ``filename`` in the dist-info directory.zutf-8)ru   joinr%   rS   readdecode)r   r,   rU   s      r   r.   zWheelFile.read_dist_info   s:    ~d0(;;}!!$''..w777r   T)validate_contentsr}   c                   	 |                      d                                          }d t          |          D             }n3# t          $ r&}t	          d| j        j         d|g          |d}~ww xY wg }| j                                        D ]}|j        dd         dk    r|                    |j        d          }| j	        t          j        | j	        |j        g          k    rP|j                            d          d         dv r.|+|                    d	| j        j         d
|j         d           |,|                    d	| j        j         d|j         d           t          j        | }|j        | j	         dk    r3|j        |j        #|                    d	| j        j         d           -|j        |j        +|                    d	| j        j         d|j         d           |rZ| j                            |          }	|                    |	          s+|                    d	| j        j         d|j         d           |rt	          |          dS )a  Validate ``RECORD`` of the wheel.

        This method should be called before :py:func:`install <installer.install>`
        if validation is required.

        File names will always be validated against ``RECORD``.

        If ``validate_contents`` is true, sizes and hashes of files
        will also be validated against ``RECORD``.

        :param validate_contents: Whether to validate content integrity.
        RECORDc                      i | ]}|d          |S r    rc   records     r   
<dictcomp>z-WheelFile.validate_record.<locals>.<dictcomp>   s+       &,q	6  r   z!Unable to retrieve `RECORD` from z: Nrt   r`   )z
RECORD.p7sz
RECORD.jwszIn z, digital signature file z$ is incorrectly contained in RECORD.z, z is not mentioned in RECORDz/RECORDz/, RECORD file incorrectly contains hash / size.z, hash / size of z is not included in RECORDz didn't match RECORD)r.   
splitlinesr   r8   r@   rS   r,   infolistpopr%   ru   rv   rb   appendr   from_elementshash_sizer{   validate)
r   r}   record_linesrecord_mappingexcrA   itemrecord_argsr   datas
             r   r0   zWheelFile.validate_record   s   	..x88CCEEL 0A,0O0O  NN  	 	 	+VT]5KVVsVVW 	
 M**,, +	 +	D}RSS!S(((,,T]DAAK!Y%;#T]3& &  -%%c**2.2NNN*MM Cdm4  C  Ct}  C  C  C   "^$-0^^DM^^^    .<F}4#5 > > >>><+v{/FMMedm4eee   |#v{':l$-0ll4=lll   ! }))$//t,, MMjdm4jjt}jjj    	4+F333	4 	4s   A A 
A3!A..A3c              #   *  K   |                      d                                          }t          |          }d |D             }| j                                        D ]}|j        dd         dk    r|                    |j        |j        ddf          }|j        dz	  }t          |ot          j
        |          o|dz            }| j                            |          5 }t          d	|          }	||	|fV  ddd           n# 1 swxY w Y   dS )
a  Sequential access to all contents of the wheel (including dist-info files).

        This implementation requires that every file that is a part of the wheel
        archive has a corresponding entry in RECORD. If they are not, an
        :any:`AssertionError` will be raised.
        r   c                      i | ]}|d          |S r   r   r   s     r   r   z*WheelFile.get_contents.<locals>.<dictcomp>-  s    BBB&)VBBBr   rt   Nr`       I   r   )r.   r   r   rS   r   r,   r   external_attrboolstatS_ISREGr]   r   )
r   r   recordsr   r   r   modeis_executablestreamstream_casteds
             r   r2   zWheelFile.get_contents#  sh      **844??AA#L11BB'BBBM**,, 	; 	;D}RSS!S(( $''r27NOOF %+D !M$,t*<*<!MNNM##D)) ;V $Z 8 8m]::::; ; ; ; ; ; ; ; ; ; ; ; ; ; ;	; 	;s   #DD	D	)r3   r4   r5   r6   r@   r   rZ   r[   r   classmethodr   r   r]   r;   r:   r%   r   r+   r.   r   r0   r<   r2   r=   r>   s   @r   r   r      sn         12'/ 2d 2 2 2 2 2 2  * x/D    ^ [
 "s " " " X"H 
T#Y 
 
 
 X
8s 8s 8 8 8 8
 <@ G4 G4 G4D G4D G4 G4 G4 G4R;h':; ; ; ; ; ; ; ; ;r   )!r6   rT   ru   r   rZ   
contextlibr   typingr   r   r   r   r   r	   r
   r   installer.exceptionsr   installer.recordsr   r   installer.utilsr   r   r:   r   r<   __all__r   r7   r@   rI   r   r   r   r   <module>r      s   / / 				       % % % % % % R R R R R R R R R R R R R R R R R R R R / / / / / / < < < < < < < < C C C C C C C CE#sC-0(D@A  +
&R" R" R" R" R" R" R" R"jC C C C C
N C C C
 
 
 
 
J 
 
 
z; z; z; z; z; z; z; z; z; z;r   