o Ec@sddlZddlmZmZmZmZmZddlmZm Z m Z ddl m Z er0ddlm Z ddlmZdZgdZGd d d ZGd d d eZdS) N) TYPE_CHECKINGBinaryIODictIteratorList) HashMismatch HashMissingInstallationError) read_chunks)_Hash)NoReturnsha256)r Zsha384Zsha512c@seZdZdZd$deeeefddfddZd%dd Ze de fd d Z d ed ede fddZ deeddfddZdeedfddfddZdeddfddZdeddfddZde fddZdede fd d!Zde fd"d#ZdS)&HasheszaA wrapper that builds multiple hashes at once and checks them against known-good values NhashesreturncCs4i}|dur|D] \}}t|||<q ||_dS)zo :param hashes: A dict of algorithm names pointing to lists of allowed hex digests N)itemssorted_allowed)selfrZallowedalgkeysrM/opt/alt/python310/lib/python3.10/site-packages/pip/_internal/utils/hashes.py__init__s  zHashes.__init__othercsbt|tstS|s Ss|Si}|jD]\}jvr qfdd|D|<qt|S)Ncsg|] }|jvr|qSr)r).0vrrrr ;sz"Hashes.__and__..) isinstancerNotImplementedrr)rrnewvaluesrrr__and__+s  zHashes.__and__cCstdd|jDS)Ncss|]}t|VqdSN)len)rZdigestsrrr @sz&Hashes.digest_count..)sumrr"rrrr digest_count>szHashes.digest_count hash_name hex_digestcCs||j|gvS)z/Return whether the given hex digest is allowed.)rget)rr*r+rrris_hash_allowedBszHashes.is_hash_allowedchunksc Csi}|jD]}z t|||<Wqttfy"td|w|D]}|D]}||q+q%| D]\}}| |j|vrHdSq8| |dS)zCheck good hashes against ones built from iterable of chunks of data. Raise HashMismatch if none match. zUnknown hash name: N) rrhashlibr! ValueError TypeErrorr r"updater hexdigest_raise)rr.gotsr*chunkhashZgotrrrcheck_against_chunksFs   zHashes.check_against_chunksr5r r cCs t|j|r$)rrrr5rrrr4]s z Hashes._raisefilecCs|t|S)zaCheck good hashes against a file-like object Raise HashMismatch if none match. )r8r )rr:rrrcheck_against_file`szHashes.check_against_filepathcCs8t|d }||WdS1swYdS)Nrb)openr;)rr<r:rrrcheck_against_pathhs $zHashes.check_against_pathcCs t|jS)z,Return whether I know any known-good hashes.)boolrr(rrr__bool__ls zHashes.__bool__cCst|tstS|j|jkSr$)rrr r)rrrrr__eq__ps  z Hashes.__eq__cCs"tdtdd|jDS)N,css,|]\}}|D] }d||fVqqdS):N)join)rrZ digest_listZdigestrrrr&xs z"Hashes.__hash__..)r7rErrrr(rrr__hash__uszHashes.__hash__r$)rrrr)__name__ __module__ __qualname____doc__rstrrrr#propertyintr)r@r-rbytesr8r4rr;r?rAobjectrBrFrrrrrs  rcs<eZdZdZd fdd Zdeedfddfd d ZZS) 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. rNcstjtgiddS)z!Don't offer the ``hashes`` kwarg.)rN)superr FAVORITE_HASHr( __class__rrrszMissingHashes.__init__r5r r cCst|tr$)rrRr3r9rrrr4szMissingHashes._raise)rN) rGrHrIrJrrrKr4 __classcell__rrrSrrPs"rP)r/typingrrrrrZpip._internal.exceptionsrrr Zpip._internal.utils.miscr r r rRZ STRONG_HASHESrrPrrrrs   h