U cf @sdZddlmZddlZddlmZddlZddlZddlZddl m Z m Z ddl m Z mZmZddlmZdd lmZmZdd lmZmZeeZGd d d e ZGd dde ZGddde ZGddde ZdddgZdZ dZ!e"dZ#e"dZ$dZ%dZ&dZ'dZ(dZ)dZ*d Z+e*d!Z,d"Z-d#Z.e,e.Z/e0Z1e12e%e12e&e12e(e12e*e12e,e12e/e"d$Z3d%d&Z4d'd(Z5d)d*e1DZ6d+d*e67DZ8d,Z9d-Z:d.Z;d/Zd2Z?e@ZAe"d3ZBd=d5d6ZCGd7d8d8e@ZDd9ZEd:ZFd;ZGGdzzImplementation of the Metadata for Python packages PEPs. Supports all metadata formats (1.0, 1.1, 1.2, 1.3/2.1 and 2.2). )unicode_literalsN)message_from_file)DistlibException __version__)StringIO string_types text_type) interpret)extract_by_key get_extras) get_schemePEP440_VERSION_REc@seZdZdZdS)MetadataMissingErrorzA required metadata is missingN__name__ __module__ __qualname____doc__rrJ/opt/hc_python/lib/python3.8/site-packages/pip/_vendor/distlib/metadata.pyrsrc@seZdZdZdS)MetadataConflictErrorz>Attempt to read or write metadata fields that are conflictual.Nrrrrrr src@seZdZdZdS) MetadataUnrecognizedVersionErrorz Unknown metadata version number.Nrrrrrr$src@seZdZdZdS)MetadataInvalidErrorzA metadata value is invalidNrrrrrr(srMetadataPKG_INFO_ENCODINGPKG_INFO_PREFERRED_VERSIONutf-81.1z \| ) Metadata-VersionNameVersionPlatformSummary DescriptionKeywords Home-pageAuthor Author-emailLicense)r r!r"r#Supported-Platformr$r%r&r'r(r)r* Classifier Download-URL ObsoletesProvidesRequires)r.r/r0r,r-)r r!r"r#r+r$r%r&r'r(r) MaintainerMaintainer-emailr*r,r-Obsoletes-Dist Project-URL Provides-Dist Requires-DistRequires-PythonRequires-External)r5r6r7r3r8r1r2r4)r r!r"r#r+r$r%r&r'r(r)r1r2r*r,r-r3r4r5r6r7r8Private-Version Obsoleted-BySetup-Requires-Dist ExtensionProvides-Extra)r9r=r:r;r<)Description-Content-Typer0r/r.)r>)Dynamic License-Filez"extra\s*==\s*("([^"]+)"|'([^']+)')cCsl|dkr tS|dkrtS|dkr$tS|dkrBttddtDS|dkrTtdn |d kr`tSt|dS) N1.0r1.2)1.32.1css|]}|tkr|VqdSN) _345_FIELDS).0frrr sz%_version2fieldlist..2.0z+Metadata 2.0 is withdrawn and not supported2.2) _241_FIELDS _314_FIELDSrFtuple _566_FIELDS ValueError _643_FIELDSr)versionrrr_version2fieldlistvs rSc Csdd}dd|D}ddddd d g}|D]}|tkrXd|krX|dtd ||tkr~d|kr~|dtd ||tkrd|kr|dtd ||tkrd|kr|dtd||tkrd |kr|dkr|d td||tkr.d |kr.|d td|q.t |dkr6|dSt |dkrXtd|t dd|koj||t }d|ko~||t }d |ko||t }d |ko||t}t|t|t|t|dkrt d|s|s|s|st|krtS|rdS|rdS|rd Sd S)z5Detect the best version depending on the fields used.cstfdd|DS)Nc3s|]}|kVqdSrEr)rGmarkerkeysrrrIsz5_best_version.._has_marker..)any)rVmarkersrrUr _has_markersz"_best_version.._has_markercSs"g|]\}}|gddfkr|qS)UNKNOWNNr)rGkeyvaluerrr sz!_best_version..rArrBrCrDrKzRemoved 1.0 due to %szRemoved 1.1 due to %szRemoved 1.2 due to %szRemoved 1.3 due to %sr%zRemoved 2.1 due to %szRemoved 2.2 due to %srrz)Out of options - unknown metadata set: %szUnknown metadata setz,You used incompatible 1.1/1.2/2.1/2.2 fields)itemsrLremoveloggerdebugrMrFrOrQlenr _314_MARKERS _345_MARKERS _566_MARKERS _643_MARKERSintr) fieldsrYrVZpossible_versionsr[Zis_1_1Zis_1_2Zis_2_1Zis_2_2rrr _best_versionsX            & ricCsi|]}|dd|qS)-_)lowerreplace)rGnamerrr srocCsi|]\}}||qSrr)rGattrfieldrrrros)r6r3r5)r7)r")r#r,r.r0r/r3r5r6r8r4r+r;r=r<r@)r4)r&)r(r1r$r%z[^A-Za-z0-9.]+FcCs0|r$td|}td|dd}d||fS)zhReturn the distribution name with version. If for_filename is true, return a filename-escaped form.rj .z%s-%s) _FILESAFEsubrm)rnrRZ for_filenamerrr_get_name_and_versions rvc@s eZdZdZd?ddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZd@ddZddZdd Zd!d"Zd#d$ZdAd%d&ZdBd'd(ZdCd)d*Zd+d,Zefd-d.ZdDd/d0ZdEd1d2Zd3d4Zd5d6Zd7d8Zd9d:Zd;d<Z d=d>Z!dS)FLegacyMetadataaoThe legacy metadata of a release. Supports versions 1.0, 1.1, 1.2, 2.0 and 1.3/2.1 (auto-detected). You can instantiate the class with one of these arguments (or none): - *path*, the path to a metadata file - *fileobj* give a file-like object with metadata as content - *mapping* is a dict-like object - *scheme* is a version scheme name NdefaultcCsz|||gddkrtdi|_g|_d|_||_|dk rH||n.|dk r\||n|dk rv||| dS)N'path, fileobj and mapping are exclusive) count TypeError_fieldsZrequires_filesZ _dependenciesschemeread read_fileupdateset_metadata_version)selfpathfileobjmappingr~rrr__init__s   zLegacyMetadata.__init__cCst|j|jd<dSNr )rir}rrrrrsz#LegacyMetadata.set_metadata_versioncCs|d||fdS)Nz%s: %s )write)rrrnr\rrr _write_fieldszLegacyMetadata._write_fieldcCs ||SrE)getrrnrrr __getitem__szLegacyMetadata.__getitem__cCs |||SrE)set)rrnr\rrr __setitem__szLegacyMetadata.__setitem__cCs8||}z |j|=Wntk r2t|YnXdSrE) _convert_namer}KeyError)rrn field_namerrr __delitem__s   zLegacyMetadata.__delitem__cCs||jkp|||jkSrE)r}rrrrr __contains__$s zLegacyMetadata.__contains__cCs(|tkr |S|dd}t||S)Nrjrk) _ALL_FIELDSrmrl _ATTR2FIELDrrrrrr(szLegacyMetadata._convert_namecCs|tks|tkrgSdS)NrZ) _LISTFIELDS_ELEMENTSFIELDrrrr_default_value.szLegacyMetadata._default_valuecCs&|jdkrtd|Std|SdS)NrAr )metadata_version_LINE_PREFIX_PRE_1_2ru_LINE_PREFIX_1_2rr\rrr_remove_line_prefix3s  z"LegacyMetadata._remove_line_prefixcCs|tkr||St|dSrE)rAttributeErrorrrrr __getattr__9szLegacyMetadata.__getattr__FcCst|d|d|S)zhReturn the distribution name with version. If filesafe is true, return a filename-escaped form.r!r")rv)rZfilesaferrr get_fullnameDszLegacyMetadata.get_fullnamecCs||}|tkS)z+return True if name is a valid metadata key)rrrrrris_fieldJs zLegacyMetadata.is_fieldcCs||}|tkSrE)rrrrrris_multi_fieldOs zLegacyMetadata.is_multi_fieldcCs.tj|ddd}z||W5|XdS)z*Read the metadata values from a file path.rrencodingN)codecsopencloser)rfilepathfprrrrSszLegacyMetadata.readcCst|}|d|jd<tD]p}||kr(q|tkrf||}|tkrX|dk rXdd|D}|||q||}|dk r|dkr|||q|}|r|n|d|d<dS)z,Read the metadata values from a file object.zmetadata-versionr NcSsg|]}t|dqS,)rNsplitrGr\rrrr]hsz,LegacyMetadata.read_file..rZr%)rr}rrget_all_LISTTUPLEFIELDSr get_payload)rZfileobmsgrqvaluesr\bodyrrrr[s zLegacyMetadata.read_filecCs0tj|ddd}z|||W5|XdS)z&Write the metadata fields to filepath.wrrN)rrr write_file)rr skip_unknownrrrrrwszLegacyMetadata.writecCs|t|dD]}||}|r8|dgdgfkr8q|tkrV|||d|q|tkr|dkr|jdkr~|dd}n |dd}|g}|t krd d |D}|D]}||||qqd S) z0Write the PKG-INFO format data to a file object.r rZrr%rrrz |cSsg|]}d|qSrjoinrrrrr]sz-LegacyMetadata.write_file..N) rrSrrrrrrrmr)r fileobjectrrqrr\rrrrs$   zLegacyMetadata.write_filec svfdd}|sn@t|dr:|D]}||||q$n|D]\}}|||q>|rr|D]\}}|||q^dS)aSet metadata values from the given iterable `other` and kwargs. Behavior is like `dict.update`: If `other` has a ``keys`` method, they are looped over and ``self[key]`` is assigned ``other[key]``. Else, ``other`` is an iterable of ``(key, value)`` iterables. Keys that don't match a metadata field or that have an empty value are dropped. cs"|tkr|r||dSrE)rrr)r[r\rrr_sets z#LegacyMetadata.update.._setrVN)hasattrrVr^)rotherkwargsrkvrrrrs     zLegacyMetadata.updatecCsh||}|tks|dkrNt|ttfsNt|trHdd|dD}qzg}n,|tkrzt|ttfszt|trv|g}ng}t t j r<|d}t |j }|tkr|dk r|D](}||ddstd |||qnb|tkr |dk r ||s.rr!N;rz$'%s': '%s' is not valid (field '%s')z.'%s': '%s' is not a valid version (field '%s')r%)rr isinstancelistrNrrrr` isEnabledForloggingWARNINGr r~_PREDICATE_FIELDSis_valid_matcherwarning_VERSIONS_FIELDSis_valid_constraint_list_VERSION_FIELDSis_valid_version_UNICODEFIELDSrr})rrnr\ project_namer~rrrrrsV           zLegacyMetadata.setcCs||}||jkr*|tkr&||}|S|tkr@|j|}|S|tkr|j|}|dkr^gSg}|D].}|tkr~||qf||d|dfqf|S|tkr|j|}t |t r| dS|j|S)zGet a metadata field.Nrrr) rr}_MISSINGrrrrappendrrrr)rrnrxr\resvalrrrrs.         zLegacyMetadata.getc s|gg}}dD]}||kr||q|rP|gkrPdd|}t|dD]}||krT||qT|ddkr||fSt|jfdd}t|ftjft j ffD]@\}}|D]2} | | d } | d k r|| s|d | | fqq||fS) zkCheck if the metadata is compliant. If strict is True then raise if no Name or Version are provided)r!r"zmissing required metadata: %s, )r'r(r rBcs(|D]}|ddsdSqdS)NrrFT)rr)r\rr~rrare_valid_constraintssz3LegacyMetadata.check..are_valid_constraintsNzWrong value for '%s': %s) rrrrr r~rrrrrr) rstrictmissingwarningsrprrrh controllerrqr\rrrchecks8         zLegacyMetadata.checkcCsh|t|d}i}|D]F}|r.||jkrt|}|dkrL||||<qdd||D||<q|S)aReturn fields as a dict. Field names will be converted to use the underscore-lowercase style instead of hyphen-mixed case (i.e. home_page instead of Home-page). This is as per https://www.python.org/dev/peps/pep-0566/#id17. r project_urlcSsg|]}d|qSrr)rGurrrr]<sz)LegacyMetadata.todict..)rrSr} _FIELD2ATTR)rZ skip_missingrhdatarr[rrrtodict)s zLegacyMetadata.todictcCs8|ddkr$dD]}||kr||=q|d|7<dS)Nr r)r.r0r/r6r)r requirementsrqrrradd_requirements@s  zLegacyMetadata.add_requirementscCstt|dSr)rrSrrrrrVKszLegacyMetadata.keysccs|D] }|VqdSrErU)rr[rrr__iter__Ns zLegacyMetadata.__iter__csfddDS)Ncsg|] }|qSrrrGr[rrrr]Ssz)LegacyMetadata.values..rUrrrrrRszLegacyMetadata.valuescsfddDS)Ncsg|]}||fqSrrrrrrr]Vsz(LegacyMetadata.items..rUrrrrr^UszLegacyMetadata.itemscCsd|jj|j|jfS)Nz <%s %s %s>) __class__rrnrRrrrr__repr__Xs zLegacyMetadata.__repr__)NNNrx)F)F)F)N)F)F)"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrVrrr^rrrrrrws@      ,  ,  rwz pydist.jsonz metadata.jsonMETADATAc@seZdZdZedZedejZedejZ e Z edZ dZ deZddd d Zd Zd Zedfed fe d fe d fe d fd ZdZdIddZedZdefZdefZdefdefeeedefeeeedefddd Z[[ddZdJddZdd Ze d!d"Z!e d#d$Z"e"j#d%d$Z"dKd&d'Z$e d(d)Z%e d*d+Z&e&j#d,d+Z&d-d.Z'd/d0Z(d1d2Z)d3d4Z*d5d6d7d8d9d:d;d Z+d?d@Z,dLdCdDZ-dEdFZ.dGdHZ/dS)Mrz The metadata of a release. This implementation uses 2.1 metadata where possible. If not possible, it wraps a LegacyMetadata instance which handles the key-value metadata format. z ^\d+(\.\d+)*$z!^[0-9A-Z]([0-9A-Z_.-]*[0-9A-Z])?$z^[A-Z]([0-9A-Z-]*[0-9A-Z])?$z .{1,2047}rJz distlib (%s)r)legacy)rnrRsummaryzqname version license summary description author author_email keywords platform home_page classifiers download_urlzwextras run_requires test_requires build_requires dev_requires provides meta_requires obsoleted_by supports_environments)rrnrRrZdynamic)_legacy_datar~Nrxc Cs0|||gddkrtdd|_d|_||_|dk rzz|||||_Wn*tk rvt||d|_|YnXnd}|rt |d}| }W5QRXn |r| }|dkr|j |j d|_ndt |ts|d}zt||_||j|Wn0tk r*tt||d|_|YnXdS)Nryrz)rr~rbr generatorr)rr~)r{r|rrr~_validate_mappingrrwvalidaterrMETADATA_VERSION GENERATORrr decodejsonloadsrPr)rrrrr~rrHrrrrs@       zMetadata.__init__)rnrRlicensekeywordsrr6r;r=r,)r-N)r N) run_requiresbuild_requires dev_requiresZ test_requires meta_requiresextrasmodules namespacesexportscommands classifiers source_urlrc CsXt|d}t|d}||kr||\}}|jr^|dkrP|dkrHdn|}n |j|}n|dkrjdn|}|dkr|j||}nt}|}|jd} | r |dkr| d|}nP|dkr| d} | r| ||}n,| d } | s|jd } | r | ||}||krT|}n:||kr2t||}n"|jrH|j|}n |j|}|S) N common_keys mapped_keysrrrrr extensionsrpython.commandsrpython.detailspython.exports)object__getattribute__rrr) rr[commonmappedlkmakerresultr\sentineldrrrrsD            zMetadata.__getattribute__cCsH||jkrD|j|\}}|p |j|krD||}|sDtd||fdS)Nz.'%s' is an invalid value for the '%s' property)SYNTAX_VALIDATORSr~matchr)rr[r\r~pattern exclusionsmrrr_validate_values  zMetadata._validate_valuecCs*|||t|d}t|d}||kr||\}}|jrV|dkrJt||j|<nf|dkrj||j|<nR|jdi}|dkr||d<n2|dkr|di}|||<n|d i}|||<nh||krt|||nP|d krt|t r| }|r| }ng}|jr||j|<n ||j|<dS) Nrr r r rr rr rr) rrrrNotImplementedErrorr setdefault __setattr__rrrr)rr[r\rrrrkrrrrr s<               zMetadata.__setattr__cCst|j|jdSNT)rvrnrRrrrrname_and_version/szMetadata.name_and_versioncCsF|jr|jd}n|jdg}d|j|jf}||krB|||S)Nr5providesz%s (%s))rrrrnrRr)rrsrrrr#3s  zMetadata.providescCs |jr||jd<n ||jd<dS)Nr5r#)rrrrrrr#>s c Cs|jr |}ng}t|pg|j}|D]d}d|kr>d|kr>d}n8d|krLd}n|d|k}|rv|d}|rvt||}|r$||dq$dD]F}d|} | |kr|| |jd|g}||j|||dq|S) a Base method to get dependencies, given a set of extras to satisfy and an optional environment context. :param reqts: A list of sometimes-wanted dependencies, perhaps dependent on extras and environment. :param extras: A list of optional components being requested. :param env: An optional environment for marker evaluation. extra environmentTrequires)builddevtestz:%s:z %s_requires)renv) rr rrr extendr_rget_requirements) rreqtsrr+rrincluderTr[errrr-Es2      zMetadata.get_requirementscCs|jr|S|jSrE)r _from_legacyrrrrr dictionaryoszMetadata.dictionarycCs|jr tnt|j|jSdSrE)rrr rDEPENDENCY_KEYSrrrr dependenciesuszMetadata.dependenciescCs|jr tn |j|dSrE)rrrrrrrrr4|sc Cs|d|jkrtg}|jD]"\}}||kr$||kr$||q$|rbdd|}t||D]\}}||||qjdS)NrzMissing metadata items: %sr) rrrMANDATORY_KEYSr^rrrr) rrr~rr[rrrrrrrrs zMetadata._validate_mappingcCsB|jr.|jd\}}|s|r>td||n||j|jdS)NTz#Metadata: missing: %s, warnings: %s)rrr`rrrr~)rrrrrrrszMetadata.validatecCs(|jr|jdSt|j|j}|SdSr!)rrr r INDEX_KEYS)rrrrrrs zMetadata.todictc Cs|jr |jrt|j|jd}|jd}dD]*}||kr.|dkrHd}n|}||||<q.|dg}|dgkrtg}||d<d }|D]*\}}||kr||rd ||ig||<q|j|d <i}i} |S) NrT)rnrRrr description classifierr8rr&r))Z requires_distr)Zsetup_requires_distrr'r#)rrAssertionErrorrrrrr#) rrZlmdrnkkwrVokauthor maintainerrrrr1s.     zMetadata._from_legacyr!r"r*r$r%r'r(r)r-) rnrR)r r rrr7)r python.projectZ project_urlsZHome)r r@contactsrrn)r r@rAremailr)r r rc Csdd}|jr|jrtt}|j}|jD]v\}}t|tsV||kr||||<q.|}d}|D]4}z ||}Wqbtt fk rd}YqYqbXqb|r.|||<q.||j |j } ||j |j } |jrt|j|d<t| |d<t| |d<|S)NcSst}|D]|}|d}|d}|d}|D]V}|sF|sF||q.d}|rVd|}|rp|rld||f}n|}|d||fq.q |S)Nr%r&r'r9z extra == "%s"z (%s) and %sr)rraddr)entriesr.r0r%r+ZrlistrrTrrrprocess_entriess"   z,Metadata._to_legacy..process_entriesTFr=r6r;)rrr:rwLEGACY_MAPPINGr^rrNr IndexErrorrrrrrsorted) rrErZnmdr;r=rfoundrr1r2rrr _to_legacys2     zMetadata._to_legacyFTc Cs||gddkrtd||r`|jr4|j}n|}|rP|j||dq|j||dn^|jrp|}n|j}|rt j ||ddddn.t |dd}t j ||ddddW5QRXdS) Nrz)Exactly one of path and fileobj is needed)rTry) ensure_asciiindent sort_keysrr) r{rPrrrLrrr1rrdumprr)rrrrrZ legacy_mdrrHrrrrs*   zMetadata.writecCs|jr|j|nr|jdg}d}|D]}d|kr*d|kr*|}qHq*|dkrfd|i}|d|n t|dt|B}t||d<dS)Nrr&r%r'r)rrrrinsertrrH)rrralwaysentryZrsetrrrrszMetadata.add_requirementscCs*|jpd}|jpd}d|jj|j||fS)Nz (no name)z no versionz<%s %s %s (%s)>)rnrRrrr)rrnrRrrrr(s  zMetadata.__repr__)NNNrx)N)NN)NNFT)0rrrrrecompileZMETADATA_VERSION_MATCHERIZ NAME_MATCHERZFIELDNAME_MATCHERrZVERSION_MATCHERZSUMMARY_MATCHERrrrr5r6r3r __slots__rrrrZ none_listdictZ none_dictr rrr propertyr"r#setterr-r2r4rrrr1rFrLrrrrrrrrbs   -+ '    *     2 )F)Ir __future__rrrBrrrrTr9rrcompatrrr rXr utilr r rRr r getLoggerrr`rrrr__all__rrrUrrrLrMrcrFrdZ _426_FIELDSZ _426_MARKERSrOrerfrQrrrZEXTRA_RErSrirr^rrrrrrrrrrrtrvrwZMETADATA_FILENAMEZWHEEL_METADATA_FILENAMEZLEGACY_METADATA_FILENAMErrrrrs~               H  j