o
    ©„j°  ã                   @  sž   d dl mZ d dlZd dlmZ d dlmZmZmZ d dl	m
Z
mZmZ d dlmZ er8d 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 )é    )ÚannotationsN)ÚIterable)ÚTYPE_CHECKINGÚBinaryIOÚNoReturn)ÚHashMismatchÚHashMissingÚInstallationError)Úread_chunks)ÚMapping)Ú_HashÚsha256)r   Úsha384Úsha512c                   @  sŽ   e Zd ZdZd/d0dd„Zd1d
d„Zed2dd„ƒZd3dd„Zd4dd„Z	d5dd„Z
d6d d!„Zd7d#d$„Zd8d&d'„Zd9d(d)„Zd:d+d,„Zd2d-d.„ZdS );ÚHasheszaA wrapper that builds multiple hashes at once and checks them against
    known-good values

    NÚhashesúdict[str, list[str]] | NoneÚreturnÚNonec                 C  s>   i }|dur|  ¡ D ]\}}dd„ t|ƒD ƒ||< q
|| _dS )zo
        :param hashes: A dict of algorithm names pointing to lists of allowed
            hex digests
        Nc                 S  s   g | ]}|  ¡ ‘qS © )Úlower)Ú.0Úkr   r   úX/var/www/html/django_cbt/venv/lib/python3.10/site-packages/pip/_internal/utils/hashes.pyÚ
<listcomp>'   s    z#Hashes.__init__.<locals>.<listcomp>)ÚitemsÚsortedÚ_allowed)Úselfr   ÚallowedÚalgÚkeysr   r   r   Ú__init__   s
   
zHashes.__init__Úotherc                   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   )r   Úv©r    r   r   r   r   :   s    z"Hashes.__and__.<locals>.<listcomp>)Ú
isinstancer   ÚNotImplementedr   r   )r   r#   ÚnewÚvaluesr   r%   r   Ú__and__*   s   

zHashes.__and__Úintc                 C  s   t dd„ | j ¡ D ƒƒS )Nc                 s  s   � | ]}t |ƒV  qd S ©N)Úlen)r   Údigestsr   r   r   Ú	<genexpr>?   s   € z&Hashes.digest_count.<locals>.<genexpr>)Úsumr   r)   ©r   r   r   r   Údigest_count=   s   zHashes.digest_countÚ	hash_nameÚstrÚ
hex_digestÚboolc                 C  s   || j  |g ¡v S )z/Return whether the given hex digest is allowed.)r   Úget)r   r3   r5   r   r   r   Úis_hash_allowedA   s   zHashes.is_hash_allowedÚchunksúIterable[bytes]c              
   C  s    i }| j  ¡ D ]}z	t |¡||< W q ttfy"   td|› �ƒ‚w |D ]}| ¡ D ]}| |¡ q+q%| 	¡ D ]\}}| 
¡ | j | v rH dS q8|  |¡ 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   r9   Úgotsr3   ÚchunkÚhashÚgotr   r   r   Úcheck_against_chunksE   s    ÿÿÿzHashes.check_against_chunksrA   údict[str, _Hash]r   c                 C  s   t | j|ƒ‚r,   )r   r   ©r   rA   r   r   r   r@   \   s   zHashes._raiseÚfiler   c                 C  s   |   t|ƒ¡S )zaCheck good hashes against a file-like object

        Raise HashMismatch if none match.

        )rE   r
   )r   rH   r   r   r   Úcheck_against_file_   s   zHashes.check_against_fileÚpathc                 C  s8   t |dƒ�}|  |¡W  d   ƒ S 1 sw   Y  d S )NÚrb)ÚopenrI   )r   rJ   rH   r   r   r   Úcheck_against_pathg   s   $ÿzHashes.check_against_pathúMapping[str, str]c                 C  s(   |  ¡ D ]\}}|  ||¡r dS qdS )z3Return whether any of the given hashes are allowed.TF)r   r8   )r   r   r3   r5   r   r   r   Ú
has_one_ofk   s
   ÿzHashes.has_one_ofc                 C  s
   t | jƒS )z,Return whether I know any known-good hashes.)r6   r   r1   r   r   r   Ú__bool__r   s   
zHashes.__bool__Úobjectc                 C  s   t |tƒstS | j|jkS r,   )r&   r   r'   r   )r   r#   r   r   r   Ú__eq__v   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    Údigest_listÚdigestr   r   r   r/   ~   s   € ýþÿz"Hashes.__hash__.<locals>.<genexpr>)rC   rU   r   r   r   r1   r   r   r   Ú__hash__{   s   þÿÿzHashes.__hash__r,   )r   r   r   r   )r#   r   r   r   )r   r+   )r3   r4   r5   r4   r   r6   )r9   r:   r   r   ©rA   rF   r   r   )rH   r   r   r   )rJ   r4   r   r   )r   rN   r   r6   )r   r6   )r#   rQ   r   r6   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r"   r*   Úpropertyr2   r8   rE   r@   rI   rM   rO   rP   rR   rX   r   r   r   r   r      s    








r   c                      s,   e Zd ZdZd‡ fdd„Z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.

    r   r   c                   s   t ƒ jtg id� dS )z!Don't offer the ``hashes`` kwarg.)r   N)Úsuperr"   ÚFAVORITE_HASHr1   ©Ú	__class__r   r   r"   �   s   zMissingHashes.__init__rA   rF   r   c                 C  s   t |t  ¡ ƒ‚r,   )r   ra   r?   rG   r   r   r   r@   •   s   zMissingHashes._raise)r   r   rY   )rZ   r[   r\   r]   r"   r@   Ú__classcell__r   r   rb   r   r_   ‡   s    r_   )Ú
__future__r   r;   Úcollections.abcr   Útypingr   r   r   Úpip._internal.exceptionsr   r   r	   Úpip._internal.utils.miscr
   r   r   ra   ÚSTRONG_HASHESr   r_   r   r   r   r   Ú<module>   s    o