a Re@sddlZddlmZmZmZmZmZddlmZm Z m Z ddl m Z er`ddlm Z ddlmZdZgdZGd d d ZGd d d eZdS) N) TYPE_CHECKINGBinaryIODictIteratorList) HashMismatch HashMissingInstallationError) read_chunks)_Hash)NoReturnsha256)r sha384sha512c@seZdZdZd#eeeefddddZdddddZe e d d d Z eee d d dZ eeddddZeedfddddZeddddZeddddZe d ddZee ddd Ze d d!d"ZdS)$HasheszaA wrapper that builds multiple hashes at once and checks them against known-good values N)hashesreturncCs4i}|dur*|D]\}}t|||<q||_dS)zo :param hashes: A dict of algorithm names pointing to lists of allowed hex digests N)itemssorted_allowed)selfrallowedalgkeysr/builddir/build/BUILDROOT/alt-python39-pip-21.3.1-2.el8.x86_64/opt/alt/python39/lib/python3.9/site-packages/pip/_internal/utils/hashes.py__init__s zHashes.__init__)otherrcsbt|tstS|sSs|Si}|jD],\}jvr@q,fdd|D|<q,t|S)Ncsg|]}|jvr|qSr)r).0vrrrr ;z"Hashes.__and__..) isinstancerNotImplementedrr)rrnewvaluesrr r__and__+s  zHashes.__and__rcCstdd|jDS)Ncss|]}t|VqdSN)len)rdigestsrrr @r"z&Hashes.digest_count..)sumrr&rrrr digest_count>szHashes.digest_count) hash_name hex_digestrcCs||j|gvS)z/Return whether the given hex digest is allowed.)rget)rr0r1rrris_hash_allowedBszHashes.is_hash_allowed)chunksrc Csi}|jD]<}zt|||<WqttfyHtd|Yq0q|D]}|D]}||q\qP| D] \}}| |j|vrvdSqv| |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)rr4gotsr0chunkhashgotrrrcheck_against_chunksFs zHashes.check_against_chunksr r r;rcCst|j|dSr))rrrr;rrrr:]sz Hashes._raise)filercCs|t|S)zaCheck good hashes against a file-like object Raise HashMismatch if none match. )r?r )rrBrrrcheck_against_file`szHashes.check_against_file)pathrcCs8t|d}||WdS1s*0YdS)Nrb)openrC)rrDrBrrrcheck_against_pathhs zHashes.check_against_pathcCs t|jS)z,Return whether I know any known-good hashes.)boolrr.rrr__bool__lszHashes.__bool__cCst|tstS|j|jkSr))r#rr$r)rrrrr__eq__ps z Hashes.__eq__cCs"tdtdd|jDS)N,css*|]"\}}|D]}d||fVqqdS):N)join)rr digest_listdigestrrrr,xsz"Hashes.__hash__..)r=rMrrrr.rrr__hash__uszHashes.__hash__)N)__name__ __module__ __qualname____doc__rstrrrr'propertyintr/rHr3rbytesr?r:rrCrGrIobjectrJrPrrrrrs rcs>eZdZdZddfdd Zeedfddd 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. Nr(cstjtgiddS)z!Don't offer the ``hashes`` kwarg.)rN)superr FAVORITE_HASHr. __class__rrrszMissingHashes.__init__r r r@cCst|tdSr))rr\r9rArrrr:szMissingHashes._raise) rQrRrSrTrrrUr: __classcell__rrr]rrZsrZ)r5typingrrrrrpip._internal.exceptionsrrr pip._internal.utils.miscr r r r\ STRONG_HASHESrrZrrrrs   h