a
    ýÓEbË  ã                   @   sŽ   d dl Z d dlmZmZmZmZmZ d dlmZm	Z	m
Z
 d dlmZ er`d dl mZ d dlmZ dZg d¢ZG d	d
„ d
ƒZG dd„ deƒZdS )é    N)ÚTYPE_CHECKINGÚBinaryIOÚDictÚIteratorÚList)ÚHashMismatchÚHashMissingÚInstallationError)Úread_chunks)Ú_Hash)ÚNoReturnÚsha256)r   Úsha384Úsha512c                   @   sÚ   e Zd ZdZd#eeee f ddœdd„Zd d dœdd„Ze	e
d	œd
d„ƒZeeedœdd„Zee ddœdd„Zeedf ddœdd„Zeddœdd„Zeddœdd„Zed	œdd„Zeedœdd „Ze
d	œd!d"„ZdS )$ÚHasheszaA wrapper that builds multiple hashes at once and checks them against
    known-good values

    N)ÚhashesÚreturnc                 C   s4   i }|dur*|  ¡ D ]\}}t|ƒ||< q|| _dS )zo
        :param hashes: A dict of algorithm names pointing to lists of allowed
            hex digests
        N)ÚitemsÚsortedÚ_allowed)Úselfr   ÚallowedÚalgÚkeys© r   úZ/home/ja/django-apps/lartica_env/lib/python3.9/site-packages/pip/_internal/utils/hashes.pyÚ__init__   s
    zHashes.__init__)Úotherr   c                    sb   t |tƒstS |sˆS ˆs|S i }|j ¡ D ],\‰ }ˆ ˆjvr@q,‡ ‡fdd„|D ƒ|ˆ < q,t|ƒS )Nc                    s   g | ]}|ˆj ˆ  v r|‘qS r   )r   )Ú.0Úv©r   r   r   r   Ú
<listcomp>;   ó    z"Hashes.__and__.<locals>.<listcomp>)Ú
isinstancer   ÚNotImplementedr   r   )r   r   ÚnewÚvaluesr   r    r   Ú__and__+   s    

zHashes.__and__©r   c                 C   s   t dd„ | j ¡ D ƒƒS )Nc                 s   s   | ]}t |ƒV  qd S ©N)Úlen)r   Zdigestsr   r   r   Ú	<genexpr>@   r"   z&Hashes.digest_count.<locals>.<genexpr>)Úsumr   r&   ©r   r   r   r   Údigest_count>   s    zHashes.digest_count)Ú	hash_nameÚ
hex_digestr   c                 C   s   || j  |g ¡v S )z/Return whether the given hex digest is allowed.)r   Úget)r   r/   r0   r   r   r   Úis_hash_allowedB   s    zHashes.is_hash_allowed)Úchunksr   c              
   C   s¦   i }| j  ¡ D ]<}zt |¡||< W q ttfyH   td|› �ƒ‚Y q0 q|D ]}| ¡ D ]}| |¡ q\qP| 	¡ D ] \}}| 
¡ | j | v rv dS qv|  |¡ dS )z‚Check good hashes against ones built from iterable of chunks of
        data.

        Raise HashMismatch if none match.

        zUnknown hash name: N)r   r   Úhashlibr%   Ú
ValueErrorÚ	TypeErrorr	   r&   Úupdater   Ú	hexdigestÚ_raise)r   r3   Úgotsr/   ÚchunkÚhashZgotr   r   r   Úcheck_against_chunksF   s    zHashes.check_against_chunksr   r   ©r:   r   c                 C   s   t | j|ƒ‚d S r)   )r   r   ©r   r:   r   r   r   r9   ]   s    zHashes._raise)Úfiler   c                 C   s   |   t|ƒ¡S )zaCheck good hashes against a file-like object

        Raise HashMismatch if none match.

        )r=   r
   )r   r@   r   r   r   Úcheck_against_file`   s    zHashes.check_against_file)Úpathr   c                 C   s8   t |dƒ�}|  |¡W  d   ƒ S 1 s*0    Y  d S )NÚrb)ÚopenrA   )r   rB   r@   r   r   r   Úcheck_against_pathh   s    zHashes.check_against_pathc                 C   s
   t | jƒS )z,Return whether I know any known-good hashes.)Úboolr   r-   r   r   r   Ú__bool__l   s    zHashes.__bool__c                 C   s   t |tƒstS | j|jkS r)   )r#   r   r$   r   )r   r   r   r   r   Ú__eq__p   s    
zHashes.__eq__c                 C   s"   t d tdd„ | j ¡ D ƒƒ¡ƒS )Nú,c                 s   s*   | ]"\}}|D ]}d   ||f¡V  qqdS )ú:N)Újoin)r   r   Zdigest_listÚdigestr   r   r   r+   x   s   þz"Hashes.__hash__.<locals>.<genexpr>)r<   rK   r   r   r   r-   r   r   r   Ú__hash__u   s    þÿÿzHashes.__hash__)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ústrr   r   r'   ÚpropertyÚintr.   rF   r2   r   Úbytesr=   r9   r   rA   rE   rG   ÚobjectrH   rM   r   r   r   r   r      s   r   c                       s>   e Zd ZdZddœ‡ fdd„Zeedf ddœd	d
„Z‡  ZS )ÚMissingHasheszÀA workalike for Hashes used when we're missing a hash for a requirement

    It computes the actual hash of the requirement and raises a HashMissing
    exception showing it to the user.

    Nr(   c                    s   t ƒ jtg id� dS )z!Don't offer the ``hashes`` kwarg.)r   N)Úsuperr   ÚFAVORITE_HASHr-   ©Ú	__class__r   r   r   ‰   s    zMissingHashes.__init__r   r   r>   c                 C   s   t |t  ¡ ƒ‚d S r)   )r   rY   r8   r?   r   r   r   r9   �   s    zMissingHashes._raise)	rN   rO   rP   rQ   r   r   rR   r9   Ú__classcell__r   r   rZ   r   rW   �   s   rW   )r4   Útypingr   r   r   r   r   Úpip._internal.exceptionsr   r   r	   Úpip._internal.utils.miscr
   r   r   rY   ÚSTRONG_HASHESr   rW   r   r   r   r   Ú<module>   s   h