U .e@sddlmZddlZddlmZmZmZddlmZm Z m Z ddl m Z ddl mZerddlmZmZmZmZmZddlmZerdd lmZn dd lmZd Zd d d gZGdddeZGdddeZdS))absolute_importN) iteritemsiterkeys itervalues) HashMismatch HashMissingInstallationError) read_chunks)MYPY_CHECK_RUNNING)DictListBinaryIONoReturnIterator)PY3)_Hash)_hashZsha256Zsha384Zsha512c@s^eZdZdZdddZeddZddZd d Zd d Z d dZ ddZ ddZ ddZ dS)HasheszaA wrapper that builds multiple hashes at once and checks them against known-good values NcCs|dkr in||_dS)zo :param hashes: A dict of algorithm names pointing to lists of allowed hex digests N)_allowed)selfhashesr>/usr/lib/python3.8/site-packages/pip/_internal/utils/hashes.py__init__,szHashes.__init__cCstdd|jDS)Ncss|]}t|VqdSN)len).0Zdigestsrrr 7sz&Hashes.digest_count..)sumrvaluesrrrr digest_count4szHashes.digest_countcCs||j|gkS)z/Return whether the given hex digest is allowed.)rget)r hash_nameZ hex_digestrrris_hash_allowed9szHashes.is_hash_allowedc Csi}t|jD]<}zt|||<Wqttfk rHtd|YqXq|D]}t|D]}||q\qPt |D] \}}| |j|krvdSqv| |dS)zCheck good hashes against ones built from iterable of chunks of data. Raise HashMismatch if none match. zUnknown hash name: %sN) rrhashlibnew ValueError TypeErrorrrupdater hexdigest_raise)rZchunksgotsr#chunkhashZgotrrrcheck_against_chunksAs zHashes.check_against_chunkscCst|j|dSr)rrrr,rrrr+Ysz Hashes._raisecCs|t|S)zaCheck good hashes against a file-like object Raise HashMismatch if none match. )r/r )rfilerrrcheck_against_file]szHashes.check_against_filec Cs,t|d}||W5QRSQRXdS)Nrb)openr2)rpathr1rrrcheck_against_pathfs zHashes.check_against_pathcCs t|jS)z,Return whether I know any known-good hashes.)boolrr rrr __nonzero__kszHashes.__nonzero__cCs|Sr)r8r rrr__bool__pszHashes.__bool__)N)__name__ __module__ __qualname____doc__rpropertyr!r$r/r+r2r6r8r9rrrrr's   rcs(eZdZdZfddZddZZS) MissingHasheszA 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. cstt|jtgiddS)z!Don't offer the ``hashes`` kwarg.)rN)superr?r FAVORITE_HASHr  __class__rrr|szMissingHashes.__init__cCst|tdSr)rrAr*r0rrrr+szMissingHashes._raise)r:r;r<r=rr+ __classcell__rrrBrr?us r?)Z __future__rr%Zpip._vendor.sixrrrZpip._internal.exceptionsrrrZpip._internal.utils.miscr Zpip._internal.utils.typingr typingr r r rrrrrrAZ STRONG_HASHESobjectrr?rrrrs      N