U kf @sddlmZddlZddlZddlZddlZddlZddlZddl m Z m Z ddl m Z mZmZddlmZmZmZddlmZddlmZmZmZerddl mZmZmZdd lmZeeej efZ!Gd d d eeeZ"e#d ej$Z%d Z&dddddZ'GdddeZ(dS)) annotationsN)StringIO TextIOWrapper)IO TYPE_CHECKINGLiteral) ZIP_DEFLATEDZipFileZipInfo) WheelError)logurlsafe_b64decodeurlsafe_b64encode)ProtocolSizedUnion)Bufferc@s eZdZdS) SizedBufferN)__name__ __module__ __qualname__rr=/opt/hc_python/lib/python3.8/site-packages/wheel/wheelfile.pyrsrz^(?P(?P[^\s-]+?)-(?P[^\s-]+?))(-(?P\d[^\s-]*))? -(?P[^\s-]+?)-(?P[^\s-]+?)-(?P\S+)\.whl$iz float | None timestampcCs6ttjd|pt}t|t}t|ddS)NSOURCE_DATE_EPOCHr)intosenvirongettimemaxMINIMUM_TIMESTAMPgmtimerrrrget_zipinfo_datetime$s r%c@seZdZdZejZdefddddddZd!d d d d dddZ ddddZ d"dddddddZ d#d dddddZ dd Z d S)$ WheelFilezA ZipFile derivative class that also reads SHA-256 hashes from .dist-info/RECORD and checks any read files against those. rStrPathzLiteral[('r', 'w', 'x', 'a')]r)filemode compressionc Cstj|}t||_|dr,|jdkr:td|tj ||||ddd |j d|_ |j d|_ i|_i|_|dkrd |j|j <d |j|j d <d |j|j d <z||j }Wn(tk rtd |j d dYnX|tt|dddD]}|\}}} |sq|d\} }zt| Wn&tk r^td| dYnX| dkr~td| d| t|df|j|<qW5QRXdS)Nz.whlzBad wheel filename T)r+ allowZip64z {}.dist-infoZnameverz/RECORDr')NNz.jwsz.p7szMissing z fileutf-8)newlineencoding=zUnsupported hash algorithm: >md5sha1zWeak hash algorithm (z) is not permitted by PEP 427ascii)rpathbasename WHEEL_INFO_REmatchZparsed_filenameendswithr r __init__formatgroupZdist_info_path record_path _file_hashes _file_sizesopenKeyErrorcsvreaderrsplithashlibnew ValueErrorlowerr encode) selfr)r*r+r6recordliner5Zhash_sumsize algorithmrrrr:3sT          zWheelFile.__init__Nz str | ZipInfozLiteral[('r', 'w')]z bytes | Nonez IO[bytes]) name_or_infor*pwdreturncsdddfdd }t|tr,|jn||dkr\ds\|jkr\tdd t|||||dkrds|j\}dk rt |j |_ S) NbytesNone)newdatarQcs<j}|||r8kr8tdddS)NzHash mismatch for file '')_eofupdatedigestr )rTeofZefZef_nameZ expected_hashZ running_hashZupdate_crc_origrr _update_crcss  z#WheelFile.open.._update_crcr'/zNo hash found for file 'rU) isinstancer filenamer9r>r r r@rErFr[)rJrOr*rPr[rNrrZrr@ms" zWheelFile.openstr)base_dirc Cstd|jd|dg}t|D]\}}}|t|D]r}tjtj ||}tj |rBtj || tjj d}||jkrqB|dr|||fqB|||qBq(||D]\}}|||qdS)Nz creating 'z' and adding 'z' to itr\z .dist-info)r infor^rwalksortsortedr5normpathjoinisfilerelpathreplacesepr=r9appendwrite) rJr`deferredrootdirnames filenamesnamer5arcnamerrr write_filess      zWheelFile.write_filesz str | Nonez int | NonerS)r^rr compress_typerQc Cs~t|d}t|}|}W5QRXt|p4|t|jd}t |j t |j Bd>|_ |ph|j |_||||dS)Nrb date_time)r@rfstatfilenoreadr r%st_mtimestatS_IMODEst_modeS_IFMT external_attrr+rtwritestr)rJr^rrrtfstdatazinforrrrls  zWheelFile.writezSizedBuffer | str)zinfo_or_arcnamerrtcCst|tr0t|td}|j|_dtjBd>|_t|trD| d}t ||||t|trd|j n|}t d|d||jkr||}|jt|df|j|<t||j|<dS)Nrvirxr.zadding 'rUr4)r]r_r r%r+rtr}S_IFREGrrIr rr^r rar=_default_algorithmrqrrXdecoder>lenr?)rJrrrtfnamehash_rrrrs*      zWheelFile.writestrcsjdk rxjdkrxjrxt}tj|dddd}|fddjD|t j ddf j | t dS) Nw," ) delimiter quotecharlineterminatorc3s.|]&\}\}}||d|j|fVqdS)r1N)r?).0rrNrrJrr s z"WheelFile.close..r-)fpr*r>rrBwriter writerowsitemswriterowr;r=rgetvaluer close)rJrrrrrrs zWheelFile.close)r'N)NN)N)rrr__doc__rEsha256rrr:r@rsrlrrrrrrr&,s="r&)N)) __future__rrBrEos.pathrrer}r!iorrtypingrrrzipfilerr r Z wheel.clir Z wheel.utilr r rrrrtyping_extensionsrr_PathLiker(rcompileVERBOSEr7r#r%r&rrrrs.