o knh@s ddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z m Z m Z mZmZmZddlmZmZmZmZddlmZddlmZe dZe jd kr[eZnGd d d eZGd d d eZGdddeddZ hdZ!hdZ"dhZ#dVddZ$dWddZ%dXd"d#Z&id$d$d%d&d'd(d)d)d*d+d,d-d.d.d/d0d1d1d2d2d3d4d5d6d7d7d8d9d:d;dd?dd@dAdBdCdDdEdFdGdHdIdJ Z'dKdLe'(DZ)dYdNdOZ*e+Z,gdPZ-edPZ.e/gdQZ0GdRdSdSe eZ1GdTdUdUZ2dS)Z) annotationsN)AnyCallableGenericLiteral TypedDictcast)licenses requirements specifiersutils)version)NormalizedLicenseExpressionT) c@s6eZdZUdZded<ded<d dd Zdd d Zd S)ExceptionGroupzA minimal implementation of :external:exc:`ExceptionGroup` from Python 3.11. If :external:exc:`ExceptionGroup` is already defined by Python itself, that version is used instead. strmessagelist[Exception] exceptionsreturnNonecCs||_||_dSN)rr)selfrrr=/usr/local/lib/python3.10/dist-packages/packaging/metadata.py__init__)s zExceptionGroup.__init__cCs|jjd|jd|jdS)N(z, )) __class____name__rr)rrrr__repr__-szExceptionGroup.__repr__N)rrrrrr)rr)r" __module__ __qualname____doc____annotations__rr#rrrrrs  rcs.eZdZUdZded< d fdd ZZS) InvalidMetadataz'A metadata field contains invalid data.rfieldrrrcs||_t|dSr)r)superr)rr)rr!rrr7szInvalidMetadata.__init__)r)rrrrr)r"r$r%r&r'r __classcell__rrr+rr(1s r(c@seZdZUdZded<ded<ded<ded<ded<ded <ded <ded <ded <ded <ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded <ded!<ded"<d#S)$ RawMetadataaA dictionary of raw core metadata. Each field in core metadata maps to a key of this dictionary (when data is provided). The key is lower-case and underscores are used instead of dashes compared to the equivalent core metadata field. Any core metadata field that can be specified multiple times or can hold multiple values in a single field have a key with a plural name. See :class:`Metadata` whose attributes match the keys of this dictionary. Core metadata fields that can be specified multiple times are stored as a list or dict depending on which is appropriate for the field. Any fields which hold multiple values in a single field are stored as a list. rmetadata_versionnamer list[str] platformssummary descriptionkeywords home_pageauthor author_emaillicensesupported_platforms download_url classifiersrequiresprovides obsoletes maintainermaintainer_email requires_dist provides_distobsoletes_distrequires_pythonrequires_externaldict[str, str] project_urlsdescription_content_typeprovides_extradynamiclicense_expression license_filesN)r"r$r%r&r'rrrrr-@s@   r-F)total>r/r6r8r2rr5r?r3r7r:rDr@r.rKrH> rJr=r<r>r1r;rLrBrArCrIrEr9rGdatarrr0cCsdd|dDS)zCSplit a string of comma-separated keywords into a list of keywords.cSg|]}|qSrstrip).0krrr z#_parse_keywords..,)split)rNrrr_parse_keywordssrXrFc Csfi}|D],}dd|ddD}|dgtddt||\}}||vr,td|||<q|S) z?Parse a list of label/URL string pairings separated by a comma.cSrOrrP)rRprrrrTrUz'_parse_project_urls..rVr rz duplicate labels in project urls)rWextendmaxlenKeyError)rNurlspairpartslabelurlrrr_parse_project_urlss remsgemail.message.Messagesource bytes | strc Cspt|tr|}t|tsJ|S|jdd}t|tsJz|ddWSty7}ztd|d}~ww)zGet the body of the message.Tdecodeutf8strictzpayload in an invalid encodingN) isinstancer get_payloadbytesrkUnicodeDecodeError ValueError)rfrhpayloadbpayloadexcrrr _get_payloads   rvr6z author-emailr7 classifierr;r3zdescription-content-typerHz download-urlr:rJz home-pager5r4r8zlicense-expressionrKz license-filerLr?zmaintainer-emailr@metadata-versionr.r/r>rCr1r=rBrIr<rArErDr2r9r) zobsoletes-distplatformz project-urlr=z provides-distzprovides-extrar<z requires-distzrequires-externalzrequires-pythonr2zsupported-platformrcCsi|]\}}||qSrr)rRemailrawrrr sr|(tuple[RawMetadata, dict[str, list[str]]]c Csi}i}t|trtjjtjjd|}n tjjtjjd |}t | D]}| }| |p4g}g}d}|D]Q}t|tjjtfsHJt|tjjrg} tj|D]#\} } z| ddWn typd} d}Ynwd} | | | fqW|ttj| q;||q;|s|||<q(t|} | dur|||<q(| tvrt|dkr|d || <q(| tvr||| <q(| d krt|dkrt|d || <q(| d krzt||| <Wq(ty|||<Yq(w|||<q(zt||} Wnty|d g|j t|t!d Yn.w| r=d |vr,t"t|#d }|d g$|| gnd |vr9|d | n| |d <t"t%||fS)a Parse a distribution's metadata stored as email headers (e.g. from ``METADATA``). This function returns a two-item tuple of dicts. The first dict is of recognized fields from the core metadata specification. Fields that can be parsed and translated into Python's built-in types are converted appropriately. All other fields are left as-is. Fields that are allowed to appear multiple times are stored as lists. The second dict contains all other fields from the metadata. This includes any unrecognized fields. It also includes any fields which are expected to be parsed into a built-in type but were not formatted appropriately. Finally, any fields that are expected to appear only once but are repeated are included in this dict. )policyTrlrmlatin1FNr rr4rGr3rj)&rnrrzparserParserr~compat32parsestr BytesParser parsebytes frozensetkeyslowerget_allheaderHeader decode_headerrkrqappend make_header_EMAIL_TO_RAW_MAPPINGget_STRING_FIELDSr^ _LIST_FIELDSrXrer_rvrr setdefaultrorprpopr\r-)rNr{unparsedparsedr/headersvaluevalid_encodinghchunksbinencodingraw_namersdescription_headerrrr parse_emails|                r)1.01.11.22.12.2z2.32.4)r.r/rc@seZdZUdZded<ded<ded<ddd:d d Zd;ddZdddZd?ddZ d@d d!Z dAd#d$Z d@d%d&Z d@d'd(Z dBd*d+ZdCd-d.ZdDd0d1ZdEd3d4ZdFd6d7ZdBd8d9ZdS)G _ValidatoravValidate a metadata field. All _process_*() methods correspond to a core metadata field. The method is called with the field's raw value. If the raw value is valid it is returned in its "enriched" form (e.g. ``version.Version`` for the ``Version`` field). If the raw value is invalid, :exc:`InvalidMetadata` is raised (with a cause as appropriate). rr/r_MetadataVersionaddedrrrrcCs ||_dSrr)rrrrrrs z_Validator.__init___ownerMetadatacCs||_t||_dSr)r/_RAW_TO_EMAIL_MAPPINGr)rrr/rrr __set_name__sz_Validator.__set_name__instancetype[Metadata]rcCs|j}|j|j}|jtvs|dur,z t|d|j}Wn ty'Ynw||}|||j<z|j|j=Wn tyAYnwtt |S)N _process_) __dict___rawrr/_REQUIRED_ATTRSgetattrAttributeErrorr_rr)rrrcacher converterrrr__get__s     z_Validator.__get__NrfcauseException | Noner(cCs&t|j|dt|ji}||_|S)Nr))r(r format_maprepr __cause__)rrfrrurrr_invalid_metadata s z_Validator._invalid_metadatarcCs"|tvr ||dtt|S)Nz is not a valid metadata version)_VALID_METADATA_VERSIONSrrrrrrrr_process_metadata_versions z$_Validator._process_metadata_versionc CsT|s|dz tj|ddW|Stjy)}z |j|d|d|d}~ww)N{field} is a required fieldTvalidate is invalid for {field}r)rr canonicalize_name InvalidNamerrrurrr _process_names  z_Validator._process_nameversion_module.Versionc CsL|s|dzt|WStjy%}z |j|d|d|d}~ww)Nrrr)rversion_moduleparseInvalidVersionrrrr_process_version(s   z_Validator._process_versioncCsd|vr |d|S)z%Check the field contains no newlines. z{field} must be a single line)rrrrr_process_summary2s z_Validator._process_summaryc Cshd}tj}||d<||dj}}||vs#||vr0|dt|d||dd}|dkrD|dt|dd h}|d d}|d krc||vrc|d t|d||S) N> text/plain text/x-rst text/markdownz content-typez{field} must be one of , not charsetzUTF-8z0{field} can only specify the UTF-8 charset, not GFM CommonMarkvariantrz(valid Markdown variants for {field} are ) rzr EmailMessageget_content_typerparamsrlistr) rr content_typesr content_type parametersrmarkdown_variantsrrrr!_process_description_content_type8s0      z,_Validator._process_description_content_typer0cCsRttj|D]}|dvr||d|tvr ||dqtttj|S)N>r/rrxz" is not allowed as a dynamic fieldz is not a valid dynamic field)maprrrrr)rr dynamic_fieldrrr_process_dynamicXsz_Validator._process_dynamiclist[utils.NormalizedName]c CsZg}z|D] }|tj|ddqW|Stjy,}z |j|d|d|d}~ww)NTrrr)rr rrr)rrnormalized_namesr/rurrr_process_provides_extrads z"_Validator._process_provides_extraspecifiers.SpecifierSetc Cs>zt|WStjy}z |j|d|d|d}~wwNrr)r SpecifierSetInvalidSpecifierrrrrr_process_requires_pythonss  z#_Validator._process_requires_pythonlist[requirements.Requirement]c CsVg}z|D] }|t|qW|Stjy*}z |j|d|d|d}~wwr)rr RequirementInvalidRequirementr)rrreqsreqrurrr_process_requires_dist{s z!_Validator._process_requires_dist"NormalizedLicenseExpression | Nonec Cs<zt|WSty}z |j|d|d|d}~wwr)r canonicalize_license_expressionrrrrrrr_process_license_expressions  z&_Validator._process_license_expressioncCsg}|D]F}d|vr||dd|vr||dt|s,t|r4||dt||krE||d||q|S)Nz..zD is invalid for {field}, parent directory indicators are not allowed*z/ is invalid for {field}, paths must be resolvedz/ is invalid for {field}, paths must be relativez5 is invalid for {field}, paths must use '/' delimiter)rpathlib PurePosixPath is_absolutePureWindowsPathas_posixr)rrpathspathrrr_process_license_filess.   z!_Validator._process_license_files)rrrr)rrr/rrr)rrrrrrr)rfrrrrr()rrrr)rrrr)rrrr)rr0rr0)rr0rr)rrrr)rr0rr)rrrr)r"r$r%r&r'rrrrrrrrrrrrrrrrrrrrs,          rc@sleZdZUdZded<eddd>d d Zeddd?d dZeZ ded< eZ ded< eZ ded< eddZ ded< eZ ded< eddZded< eZded< eZded< eddZded < eZded!< eZded"< eddZded#< eZded$< eZded%< ed&dZded'< ed&dZded(< eZded)< ed*dZd+ed,< ed*dZded-< eddZded.< ed&dZd/ed0< ed&dZd1ed2< ed&dZded3< ed&dZ d4ed5< eddZ!d6ed7< ed&dZ"ded8< ed&dZ#ded9< eddZ$ded:< eddZ%ded;< eddZ&ded<<d=S)@raJRepresentation of distribution metadata. Compared to :class:`RawMetadata`, this class provides objects representing metadata fields instead of only using built-in types. Any invalid metadata will cause :exc:`InvalidMetadata` to be raised (with a :py:attr:`~BaseException.__cause__` attribute as appropriate). r-rTrrNrboolrc CsV|}||_|rg}z |j}t|}Wnty/}z ||d}WYd}~nd}~wwt|jtB}|dh8}|D]c} zJ|rz|j | j } Wnt ybt| d| } || YWq>wt| } | |krt | } t| | d| d|} || Wq>t || Wq>ty} z || WYd} ~ q>d} ~ ww|rtd||S)zCreate an instance from :class:`RawMetadata`. If *validate* is true, all metadata will be validated. All exceptions related to validation will be gathered and raised as an :class:`ExceptionGroup`. Nr.unrecognized field: z introduced in metadata version rzinvalid metadata)copyrr.rindexr(rrrrrr_rrr)clsrNrinsrr. metadata_agemetadata_version_excfields_to_checkkeyfield_metadata_versionru field_ager)rrrfrom_raws^       zMetadata.from_rawric Cst|\}}|r-g}|D]}|tvr|d}nd|}|t||q |r-td|z|j||dWStyH}ztd|jdd}~ww)zParse metadata from email headers. If *validate* is true, the metadata will be validated. All exceptions related to validation will be gathered and raised as an :class:`ExceptionGroup`. z has invalid datarrrzinvalid or unparsed metadataN)rrrr(rr r) rrNrr{rr unparsed_keyr exc_grouprrr from_emails(    zMetadata.from_emailz_Validator[_MetadataVersion]r.z_Validator[str]r/z"_Validator[version_module.Version]rrrz_Validator[list[str] | None]rJr1rr9z_Validator[str | None]r2r3rrHr4r5r:r6r7rr?r@r8rz._Validator[NormalizedLicenseExpression | None]rKrLr;z1_Validator[list[requirements.Requirement] | None]rAz*_Validator[specifiers.SpecifierSet | None]rDrEz!_Validator[dict[str, str] | None]rGz-_Validator[list[utils.NormalizedName] | None]rIrBrCr<r=r>N)rNr-rrrr)rNrirrrr)'r"r$r%r&r' classmethodr rrr.r/rrJr1r9r2r3rHr4r5r:r6r7r?r@r8rKrLr;rArDrErGrIrBrCr<r=r>rrrrrs 8r)rNrrr0)rNr0rrF)rfrgrhrirr)rNrirr})3 __future__remail.feedparserrz email.header email.message email.parser email.policyrsystypingrrrrrrrZr r r r rrrTypeVarr version_infor Exceptionrrr(r-rr _DICT_FIELDSrXrervritemsrrobject _NOT_FOUNDrrrrrrrrrrs      H   (      1 X