3 (\ @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)_hashsha256sha384sha512c@sJeZdZdZdddZddZddZd d Zd d Zd dZ 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)selfhashesrm/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-build-k1a8l1r5/pip/pip/_internal/utils/hashes.py__init__'szHashes.__init__c Csi}xJt|jD]<}ytj|||<Wqttfk rJtd|YqXqWx(|D] }xt|D]}|j|qdWqVWx*t |D]\}}|j |j|krdSqW|j |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)rchunksgots hash_namechunkhashgotrrrcheck_against_chunks/s zHashes.check_against_chunkscCst|j|dS)N)rr)rr%rrrr#Gsz Hashes._raisecCs|jt|S)zaCheck good hashes against a file-like object Raise HashMismatch if none match. )r*r )rfilerrrcheck_against_fileKszHashes.check_against_filec Cs t|d }|j|SQRXdS)Nrb)openr,)rpathr+rrrcheck_against_pathTs zHashes.check_against_pathcCs t|jS)z,Return whether I know any known-good hashes.)boolr)rrrr __nonzero__YszHashes.__nonzero__cCs|jS)N)r2)rrrr__bool__^szHashes.__bool__)N) __name__ __module__ __qualname____doc__rr*r#r,r0r2r3rrrrr"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)superr8r FAVORITE_HASH)r) __class__rrrjszMissingHashes.__init__cCst|tjdS)N)rr:r")rr%rrrr#qszMissingHashes._raise)r4r5r6r7rr# __classcell__rr)r;rr8cs r8) __future__rrpip._vendor.sixrrrZpip._internal.exceptionsrrrZpip._internal.utils.miscr Zpip._internal.utils.typingr Ztypingr r r rrrrrr: STRONG_HASHESobjectrr8rrrrs      A