HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/pip/_internal/utils/__pycache__/hashes.cpython-310.pyc
o

@%Ne��@s�ddlZddlmZmZmZmZmZddlmZm	Z	m
Z
ddlmZer0ddlm
Z
ddlmZdZgd�ZGd	d
�d
�ZGdd�de�ZdS)
�N)�
TYPE_CHECKING�BinaryIO�Dict�Iterator�List)�HashMismatch�HashMissing�InstallationError)�read_chunks)�_Hash)�NoReturn�sha256)r
�sha384�sha512c@s�eZdZdZd$deeeefddfdd�Zd%dd	�Ze	de
fd
d��Zded
edefdd�Z
deeddfdd�Zdeedfddfdd�Zdeddfdd�Zdeddfdd�Zdefdd�Zdedefd d!�Zde
fd"d#�ZdS)&�HasheszaA wrapper that builds multiple hashes at once and checks them against
    known-good values

    N�hashes�returncCs4i}|dur|��D]
\}}t|�||<q
||_dS)zo
        :param hashes: A dict of algorithm names pointing to lists of allowed
            hex digests
        N)�items�sorted�_allowed)�selfr�allowed�alg�keys�r�</usr/lib/python3/dist-packages/pip/_internal/utils/hashes.py�__init__s

zHashes.__init__�othercsbt|t�stS|s�S�s|Si}|j��D]\�}��jvr q��fdd�|D�|�<qt|�S)Ncsg|]}|�j�vr|�qSr)r)�.0�v�rrrr�
<listcomp>;sz"Hashes.__and__.<locals>.<listcomp>)�
isinstancer�NotImplementedrr)rr�new�valuesrr r�__and__+s

zHashes.__and__cCstdd�|j��D��S)Ncss�|]}t|�VqdS�N)�len)r�digestsrrr�	<genexpr>@s�z&Hashes.digest_count.<locals>.<genexpr>)�sumrr%�rrrr�digest_count>szHashes.digest_count�	hash_name�
hex_digestcCs||j�|g�vS)z/Return whether the given hex digest is allowed.)r�get)rr.r/rrr�is_hash_allowedBszHashes.is_hash_allowed�chunksc
Cs�i}|j��D]}z	t�|�||<Wqttfy"td|����w|D]}|��D]}|�|�q+q%|�	�D]\}}|�
�|j|vrHdSq8|�|�dS)z�Check good hashes against ones built from iterable of chunks of
        data.

        Raise HashMismatch if none match.

        zUnknown hash name: N)rr�hashlibr$�
ValueError�	TypeErrorr	r%�updater�	hexdigest�_raise)rr2�gotsr.�chunk�hash�gotrrr�check_against_chunksFs ���zHashes.check_against_chunksr9rrcCst|j|��r')rr�rr9rrrr8]sz
Hashes._raise�filecCs|�t|��S)zaCheck good hashes against a file-like object

        Raise HashMismatch if none match.

        )r=r
)rr?rrr�check_against_file`szHashes.check_against_file�pathcCs8t|d��
}|�|�Wd�S1swYdS)N�rb)�openr@)rrAr?rrr�check_against_pathhs$�zHashes.check_against_pathcCs
t|j�S)z,Return whether I know any known-good hashes.)�boolrr,rrr�__bool__ls
zHashes.__bool__cCst|t�stS|j|jkSr')r"rr#r)rrrrr�__eq__ps
z
Hashes.__eq__cCs"td�tdd�|j��D����S)N�,css,�|]\}}|D]
}d�||f�VqqdS)�:N)�join)rr�digest_list�digestrrrr*xs����z"Hashes.__hash__.<locals>.<genexpr>)r;rJrrrr,rrr�__hash__us���zHashes.__hash__r')rrrr)�__name__�
__module__�__qualname__�__doc__r�strrrr&�property�intr-rEr1r�bytesr=r8rr@rDrF�objectrGrMrrrrrs 
rcs<eZdZdZd�fdd�Zdeedfddfd	d
�Z�ZS)�
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.

    rNcst�jtgid�dS)z!Don't offer the ``hashes`` kwarg.)rN)�superr�
FAVORITE_HASHr,��	__class__rrr�szMissingHashes.__init__r9rrcCst|t����r')rrYr7r>rrrr8�szMissingHashes._raise)rN)	rNrOrPrQrrrRr8�
__classcell__rrrZrrW�s"rW)r3�typingrrrrr�pip._internal.exceptionsrrr	�pip._internal.utils.miscr
rrrY�
STRONG_HASHESrrWrrrr�<module>sh