3 ]2 @szddlmZddlZddlmZmZmZddlmZddl m Z m Z m Z dZ dddgZGd d d eZGd d d eZdS) )absolute_importN) HashMismatch HashMissingInstallationError) read_chunks) iteritemsiterkeys itervaluessha256sha384sha512c@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)selfhashesr//tmp/pip-build-8jg9gmni/pip/pip/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 TypeErrorrr updater hexdigest_raise)rchunksgots hash_namechunkhashgotrrrcheck_against_chunks s zHashes.check_against_chunkscCst|j|dS)N)rr)rrrrrr7sz Hashes._raisecCs|jt|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 }|j|SQRXdS)Nrb)openr#)rpathr"rrrcheck_against_pathBs zHashes.check_against_pathcCs t|jS)z,Return whether I know any known-good hashes.)boolr)rrrr __nonzero__FszHashes.__nonzero__cCs|jS)N)r))rrrr__bool__JszHashes.__bool__)N) __name__ __module__ __qualname____doc__rr!rr#r'r)r*rrrrr s r cs(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_HASH)r) __class__rrrUszMissingHashes.__init__cCst|tjdS)N)rr1r)rrrrrr[szMissingHashes._raise)r+r,r-r.rr __classcell__rr)r2rr/Ns r/) __future__rrpip.exceptionsrrr pip.utilsrZpip._vendor.sixrrr r1 STRONG_HASHESobjectr r/rrrrs   :