MCPcopy Index your code
hub / github.com/nodejs/node / from_email

Method from_email

tools/gyp/pylib/packaging/metadata.py:707–734  ·  view source on GitHub ↗

Parse 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`.

(
        cls, data: Union[bytes, str], *, validate: bool = True
    )

Source from the content-addressed store, hash-verified

705
706 @classmethod
707 def from_email(
708 cls, data: Union[bytes, str], *, validate: bool = True
709 ) -> "Metadata":
710 """Parse metadata from email headers.
711
712 If *validate* is true, the metadata will be validated. All exceptions
713 related to validation will be gathered and raised as an :class:`ExceptionGroup`.
714 """
715 raw, unparsed = parse_email(data)
716
717 if validate:
718 exceptions: list[Exception] = []
719 for unparsed_key in unparsed:
720 if unparsed_key in _EMAIL_TO_RAW_MAPPING:
721 message = f"{unparsed_key!r} has invalid data"
722 else:
723 message = f"unrecognized field: {unparsed_key!r}"
724 exceptions.append(InvalidMetadata(unparsed_key, message))
725
726 if exceptions:
727 raise ExceptionGroup("unparsed", exceptions)
728
729 try:
730 return cls.from_raw(raw, validate=validate)
731 except ExceptionGroup as exc_group:
732 raise ExceptionGroup(
733 "invalid or unparsed metadata", exc_group.exceptions
734 ) from None
735
736 metadata_version: _Validator[_MetadataVersion] = _Validator()
737 """:external:ref:`core-metadata-metadata-version`

Callers

nothing calls this directly

Calls 5

parse_emailFunction · 0.85
InvalidMetadataClass · 0.85
ExceptionGroupClass · 0.85
from_rawMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected