CodeSampleX

Beispiel

packaging 26.3: metadata.parse_email

Verifiziertes Beispiel für pypi packaging 26.3: metadata.parse_email. Der Vertrag lief auf python 3.12 · linux debian/x64 · docker und bestand.

sha256:8cf81921c0da0552abff37fb23ac56aca9153ad023ad8c6330b7bb1196d12936

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux 24 · ubuntu · glibc 2.39 x64 pip

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
python 3.12 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · python@1python:3.12-slim@sha256:09f7da3bc104…
2026-09-02

Fall

HOW
Ziel
verify packaging.metadata.parse_email in pkg:pypi/packaging@26.3
Pakete
Symbole
  • packaging.metadata.parse_email
Erstellt
2026-09-02T13:36:31Z

Contract

  1. parse_email parses standard string distribution metadata headers and payload description into RawMetadata
  2. parse_email parses distribution metadata from raw bytes input
  3. parse_email structures multi-use metadata fields like classifiers and requires_dist as lists
  4. parse_email parses Project-URL headers into a dictionary mapping labels to URLs
  5. parse_email places unrecognized headers and duplicate single-value fields into the unparsed dictionary

Dateien

  • PROMPT.md
  • csx.json
  • pyproject.toml
  • requirements.txt
  • spec.json
  • test/contract.py

Quellartefakt herunterladen (tar.gz)

Quelltext

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify packaging.metadata.parse_email in pkg:pypi/packaging@26.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:pypi/packaging@26.3
Demonstrate these symbols/APIs:
  - packaging.metadata.parse_email

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:f0bad6d94017f89d724a558406de6acde8c93ea3bef3e9d1890c44ccf661bc6f","contract":["parse_email parses standard string distribution metadata headers and payload description into RawMetadata","parse_email parses distribution metadata from raw bytes input","parse_email structures multi-use metadata fields like classifiers and requires_dist as lists","parse_email parses Project-URL headers into a dictionary mapping labels to URLs","parse_email places unrecognized headers and duplicate single-value fields into the unparsed dictionary"],"goal":"verify packaging.metadata.parse_email in pkg:pypi/packaging@26.3","kind":"HOW","packages":["pkg:pypi/packaging@26.3"],"schemaVersion":1,"symbols":["packaging.metadata.parse_email"]},"contractCommand":["python","test/contract.py"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"pypi","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"pip","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/packaging@26.3"],"schemaVersion":1,"subject":"pkg:pypi/packaging@26.3","symbols":["packaging.metadata.parse_email"],"verifierAdapter":"python@1"}
pyproject.toml
[project]
name = "verify-packaging-parse-email"
version = "0.1.0"
dependencies = [
    "packaging==26.3",
]
requirements.txt
packaging==26.3
spec.json
{
  "schemaVersion": 1,
  "goal": "verify packaging.metadata.parse_email in pkg:pypi/packaging@26.3",
  "kind": "HOW",
  "packages": [
    "pkg:pypi/packaging@26.3"
  ],
  "symbols": [
    "packaging.metadata.parse_email"
  ]
}
test/contract.py
from packaging.metadata import parse_email


def test_parse_email_string_metadata():
    # Assertion 1: parse_email parses standard string distribution metadata headers and payload description into RawMetadata
    metadata_text = """Metadata-Version: 2.3
Name: demo-pkg
Version: 1.0.0
Summary: A lightweight demo package
Author-email: Developer <dev@example.com>
Description-Content-Type: text/markdown

# Demo Package
Detailed description content.
"""
    raw_metadata, unparsed = parse_email(metadata_text)
    assert raw_metadata["metadata_version"] == "2.3"
    assert raw_metadata["name"] == "demo-pkg"
    assert raw_metadata["version"] == "1.0.0"
    assert raw_metadata["summary"] == "A lightweight demo package"
    assert raw_metadata["author_email"] == "Developer <dev@example.com>"
    assert raw_metadata["description_content_type"] == "text/markdown"
    assert raw_metadata["description"] == "# Demo Package\nDetailed description content.\n"
    assert unparsed == {}


def test_parse_email_bytes_input():
    # Assertion 2: parse_email parses distribution metadata from raw bytes input
    metadata_bytes = b"Metadata-Version: 2.2\nName: binary-metadata-pkg\nVersion: 2.1.0\n"
    raw_metadata, unparsed = parse_email(metadata_bytes)
    assert raw_metadata["metadata_version"] == "2.2"
    assert raw_metadata["name"] == "binary-metadata-pkg"
    assert raw_metadata["version"] == "2.1.0"
    assert unparsed == {}


def test_parse_email_multi_use_fields():
    # Assertion 3: parse_email structures multi-use metadata fields like classifiers and requires_dist as lists
    metadata_text = """Metadata-Version: 2.1
Name: multi-field-pkg
Version: 0.5.0
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Requires-Dist: packaging >= 20.0
Requires-Dist: urllib3 < 3.0; extra == "http"
Dynamic: dependencies
Dynamic: classifiers
"""
    raw_metadata, unparsed = parse_email(metadata_text)
    assert raw_metadata["classifiers"] == [
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
    ]
    assert raw_metadata["requires_dist"] == [
        "packaging >= 20.0",
        'urllib3 < 3.0; extra == "http"',
    ]
    assert raw_metadata["dynamic"] == ["dependencies", "classifiers"]
    assert unparsed == {}


def test_parse_email_project_urls():
    # Assertion 4: parse_email parses Project-URL headers into a dictionary mapping labels to URLs
    metadata_text = """Metadata-Version: 2.1
Name: url-pkg
Version: 1.0.0
Project-URL: Homepage, https://example.com/project
Project-URL: Documentation, https://example.com/docs
Project-URL: Repository, https://example.com/repo
"""
    raw_metadata, unparsed = parse_email(metadata_text)
    assert raw_metadata["project_urls"] == {
        "Homepage": "https://example.com/project",
        "Documentation": "https://example.com/docs",
        "Repository": "https://example.com/repo",
    }
    assert unparsed == {}


def test_parse_email_unrecognized_and_duplicate_fields():
    # Assertion 5: parse_email places unrecognized headers and duplicate single-value fields into the unparsed dictionary
    metadata_text = """Metadata-Version: 2.1
Name: duplicate-test-pkg
Name: second-name-value
Version: 1.0.0
X-Custom-Header: custom-val-1
X-Custom-Header: custom-val-2
"""
    raw_metadata, unparsed = parse_email(metadata_text)
    assert raw_metadata["version"] == "1.0.0"
    assert "name" not in raw_metadata
    assert unparsed["name"] == ["duplicate-test-pkg", "second-name-value"]
    assert unparsed["x-custom-header"] == ["custom-val-1", "custom-val-2"]


def main():
    test_parse_email_string_metadata()
    test_parse_email_bytes_input()
    test_parse_email_multi_use_fields()
    test_parse_email_project_urls()
    test_parse_email_unrecognized_and_duplicate_fields()
    print("All contract assertions passed.")


if __name__ == "__main__":
    main()

Ursprungs-Seeder

anonym