3 ig@s0dZddlZddlmZddlmZddlmZmZddl m Z m Z ddl m Z ddlmZmZdd lmZdd lmZd$ZejeZGd d d eZe eeedddZe eeeefdddZe eedddZe eedddZe eedddZ eee!dfddd Z"ee!dfedd!d"d#Z#dS)%z0Support functions for working with wheel files. N)Message)Parser)DictTuple) BadZipFileZipFile)canonicalize_name)DistInfoDistribution Distribution)UnsupportedWheel) DictMetadatacsFeZdZdZeeefeddfdd Zeedfdd ZZ S) WheelMetadatazaMetadata provider that maps metadata decoding exceptions to our internal exception type. N)metadata wheel_namereturncstj|||_dS)N)super__init__ _wheel_name)selfrr) __class__8/tmp/pip-build-88gy_88q/pip/pip/_internal/utils/wheel.pyrs zWheelMetadata.__init__)namercsJy tj|Stk rD}ztd|jd|WYdd}~XnXdS)NzError decoding metadata for z: )r get_metadataUnicodeDecodeErrorr r)rre)rrrrs  zWheelMetadata.get_metadata) __name__ __module__ __qualname____doc__rstrbytesrr __classcell__rr)rrrsr) wheel_ziprlocationrc st||\}fdd|jD}i}xf|D]^}|jdd\}}yt||||<Wq.tk r}ztdj|t|WYdd}~Xq.Xq.Wt||} t|| |dS)zaGet a pkg_resources distribution given a wheel. :raises UnsupportedWheel: on any errors cs g|]}|jdr|qS)/) startswith).0p)info_dirrr 2sz8pkg_resources_distribution_for_wheel..r&r z{} has an invalid wheel, {}N)r%r project_name) parse_wheelnamelistsplitread_wheel_metadata_filer formatr!rr ) r$rr%_Zmetadata_filesZ metadata_textpath metadata_namerrr)r*r$pkg_resources_distribution_for_wheel)s * r5)r$rrcCsjy t||}t||}t|}Wn6tk rV}ztdj|t|WYdd}~XnXt||||fS)zExtract information from the provided wheel, ensuring it meets basic standards. Returns the name of the .dist-info directory and the parsed WHEEL metadata. z{} has an invalid wheel, {}N)wheel_dist_info_dirwheel_metadata wheel_versionr r1r!check_compatibility)r$rr*rversionrrrrr-Bs   & r-)sourcerrcCsdd|jD}dd|D}|s,tdt|dkrLtdjdj||d }t|}t|}|j|s~td j|||S) zReturns the name of the contained .dist-info directory. Raises AssertionError or UnsupportedWheel if not found, >1 found, or it doesn't match the provided name. cSsh|]}|jdddqS)r&r r)r/)r(r)rrr [sz&wheel_dist_info_dir..cSsg|]}|jdr|qS)z .dist-info)endswith)r(srrrr+]sz'wheel_dist_info_dir..z.dist-info directory not foundr z)multiple .dist-info directories found: {}z, rz2.dist-info directory {!r} does not start with {!r})r.r lenr1joinrr')r;rsubdirsZ info_dirsr*Z info_dir_namecanonical_namerrrr6Ts   r6)r;r3rcCsLy |j|Stttfk rF}ztd|d|WYdd}~XnXdS)Nzcould not read z file: )readrKeyError RuntimeErrorr )r;r3rrrrr0us r0)r; dist_info_dirrcCsd|d}t||}y |j}Wn6tk rV}ztd|d|WYdd}~XnXtj|S)ziReturn the WHEEL metadata of an extracted wheel, if possible. Otherwise, raise UnsupportedWheel. z/WHEELzerror decoding z: N)r0decoderr rparsestr)r;rFr3Zwheel_contentsZ wheel_textrrrrr7~s   &r7.) wheel_datarc Cs\|d}|dkrtd|j}yttt|jdStk rVtd|YnXdS)zbGiven WHEEL metadata, return the parsed Wheel-Version. Otherwise, raise UnsupportedWheel. z Wheel-VersionNzWHEEL is missing Wheel-Version.zinvalid Wheel-Version: )r striptuplemapintr/ ValueError)rIZ version_textr:rrrr8sr8)r:rrcCsR|dtdkr.tdj|djtt|n |tkrNtjddjtt|dS)aRaises errors or warns if called with an incompatible Wheel-Version. pip should refuse to install a Wheel-Version that's a major series ahead of what it's compatible with (e.g 2.0 > 1.1); and warn when installing a version only minor version ahead (e.g 1.2 > 1.1). version: a 2-tuple representing a Wheel-Version (Major, Minor) name: name of wheel or package to raise exception about :raises UnsupportedWheel: when an incompatible Wheel-Version is given rzB{}'s Wheel-Version ({}) is not compatible with this version of piprJz*Installing from a newer Wheel-Version (%s)N)VERSION_COMPATIBLEr r1r@rMr!loggerwarning)r:rrrrr9s r9)r r)$r logging email.messager email.parserrZtypingrrzipfilerrpip._vendor.packaging.utilsrZpip._vendor.pkg_resourcesr r Zpip._internal.exceptionsr Z!pip._internal.utils.pkg_resourcesr rP getLoggerrrQrr!r5r-r6r"r0r7rNr8r9rrrrs(      !