U jaO@sdZddlZddlmZddlmZddlmZmZddl m Z m Z ddl m Z ddlmZmZdd lmZdd lmZd ZeeZGd d d eZddZddZddZddZddZddZddZ dS)z0Support functions for working with wheel files. N)Message)Parser)DictTuple) BadZipFileZipFile)canonicalize_name)DistInfoDistribution Distribution)UnsupportedWheel) DictMetadata)rcs,eZdZdZfddZfddZZS) WheelMetadatazaMetadata provider that maps metadata decoding exceptions to our internal exception type. cst|||_dS)N)super__init__ _wheel_name)selfmetadata wheel_name __class__q/private/var/folders/k6/_7fsz4ts3b78x3b3xwrxjh_c8s8xv7/T/pip-unpacked-wheel-bug3gbve/pip/_internal/utils/wheel.pyrs zWheelMetadata.__init__c sLzt|WStk rF}ztd|jd|W5d}~XYnXdS)NzError decoding metadata for : )r get_metadataUnicodeDecodeErrorr r)rnameerrrr s zWheelMetadata.get_metadata)__name__ __module__ __qualname____doc__rr __classcell__rrrrrs rc st||\}fdd|D}i}|D]^}|dd\}}zt||||<Wq,tk r}ztd|t|W5d}~XYq,Xq,t||} t|| |dS)zaGet a pkg_resources distribution given a wheel. :raises UnsupportedWheel: on any errors cs g|]}|dr|qS)/) startswith.0pinfo_dirrr 3sz8pkg_resources_distribution_for_wheel..r#r {} has an invalid wheel, {}N)locationr project_name) parse_wheelnamelistsplitread_wheel_metadata_filer formatstrrr ) wheel_ziprr,_metadata_files metadata_textpath metadata_namerrrr(r$pkg_resources_distribution_for_wheel+s( r:c Csjz t||}t||}t|}Wn6tk rV}ztd|t|W5d}~XYnXt||||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. r+N)wheel_dist_info_dirwheel_metadata wheel_versionr r2r3check_compatibility)r4rr)rversionrrrrr.Cs   & r.cCsdd|D}dd|D}|s,tdt|dkrLtdd||d }t|}t|}||s~td |||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|]}|dddqS)r#r r)r0r%rrr ^sz&wheel_dist_info_dir..cSsg|]}|dr|qS)z .dist-info)endswith)r&srrrr*`s z'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 lenr2joinrr$)sourcersubdirs info_dirsr) info_dir_namecanonical_namerrrr;Vs&  r;c CsNz ||WStttfk rH}ztd|d|W5d}~XYnXdS)Nzcould not read z file: )readrKeyError RuntimeErrorr )rEr8rrrrr1xs r1c Csd|d}t||}z |}Wn6tk rV}ztd|d|W5d}~XYnXt|S)ziReturn the WHEEL metadata of an extracted wheel, if possible. Otherwise, raise UnsupportedWheel. z/WHEELzerror decoding rN)r1decoderr rparsestr)rE dist_info_dirr8wheel_contents wheel_textrrrrr<s   &r<cCs^|d}|dkrtd|}zttt|dWStk rXtd|YnXdS)zbGiven WHEEL metadata, return the parsed Wheel-Version. Otherwise, raise UnsupportedWheel. z Wheel-VersionNzWHEEL is missing Wheel-Version.zinvalid Wheel-Version: )r striptuplemapintr0 ValueError) wheel_data version_textr?rrrr=sr=c CsR|dtdkr.td|dtt|n |tkrNtddtt|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 piprRz*Installing from a newer Wheel-Version (%s)N)VERSION_COMPATIBLEr r2rDrUr3loggerwarning)r?rrrrr>s r>)!r!logging email.messager email.parserrtypingrrzipfilerrpip._vendor.packaging.utilsrZpip._vendor.pkg_resourcesr r pip._internal.exceptionsr !pip._internal.utils.pkg_resourcesr rZ getLoggerrr[rr:r.r;r1r<r=r>rrrrs&      "