CodeSampleX

Ejemplo

packaging 26.3: metadata.parse_email

Muestra verificada para pypi packaging 26.3: metadata.parse_email. El contrato se ejecutó en python 3.12 · linux debian/x64 · docker y pasó.

sha256:8cf81921c0da0552abff37fb23ac56aca9153ad023ad8c6330b7bb1196d12936

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux 24 · ubuntu · glibc 2.39 x64 pip

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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

Caso

HOW
Objetivo
verify packaging.metadata.parse_email in pkg:pypi/packaging@26.3
Paquetes
Símbolos
  • packaging.metadata.parse_email
Creado
2026-09-02T13:36:31Z

Contrato

  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

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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()

Seeder de origen

anónimo