Sample
python-multipart 0.0.32: parse multipart form data and form fields using MultipartParser
Verified sample for pypi python-multipart 0.0.32: parse multipart form data and form fields using MultipartParser. The contract ran on python 3.12 · linux…
sha256:20b955064f5ebd7b77d0f70d1c22f5da6b6404b71aa38b0737609296e1d43089
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 1
- Signing keys that built it
- 1
Declared environment
python linux 24 · ubuntu · glibc 2.39 x64 python python pip
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| python 3.12 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · python@1python:3.12-alpine@sha256:d09d15e60962… |
2026-08-27 |
Case
HOW- Goal
- parse multipart form data and form fields using MultipartParser
- Packages
- Symbols
-
- multipart.MultipartParser
- Environment
- python
- Created
- 2026-08-27T18:12:38Z
Contract
- MultipartParser parses streaming multipart/form-data payload chunk-by-chunk and dispatches lifecycle callbacks for parts, headers, and body segments.
- MultipartParser accurately captures headers and extracts payload for multiple parts including standard form fields and file attachments.
- MultipartParser raises MultipartParseError when max_header_count limit is exceeded.
- MultipartParser raises MultipartParseError when max_header_size limit is exceeded.
- MultipartParser raises MultipartParseError when given malformed multipart payloads or invalid boundary sequences.
Files
- NOTES.md
- PROMPT.md
- csx.json
- requirements.txt
- spec.json
- test/contract.py
Source
# python-multipart MultipartParser API
This sample pins `python-multipart` 0.0.32 and verifies streaming multipart/form-data parsing using `multipart.MultipartParser`.
The contract verifies:
- `MultipartParser` processes streamed chunks of multipart payload and triggers lifecycle callbacks (`on_part_begin`, `on_header_field`, `on_header_value`, `on_headers_finished`, `on_part_data`, `on_part_end`, `on_end`).
- Reassembly of header fields and values (such as `Content-Disposition` and `Content-Type`) across multiple multipart parts.
- Correct extraction and reassembly of multipart body payload for form fields and file attachments.
- Enforcement of `max_header_count` limit, raising `MultipartParseError` when exceeded.
- Enforcement of `max_header_size` limit, raising `MultipartParseError` when exceeded.
- Rejection of malformed boundaries and invalid multipart stream data with `MultipartParseError`.
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: parse multipart form data and form fields using MultipartParser
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:pypi/python-multipart@0.0.32
Demonstrate these symbols/APIs:
- multipart.MultipartParser
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.
{"case":{"caseId":"case:sha256:63c7db192c484ab54b33281d09f74bd0b633c2400bf98142a7358b9df4c256c1","contract":["MultipartParser parses streaming multipart/form-data payload chunk-by-chunk and dispatches lifecycle callbacks for parts, headers, and body segments.","MultipartParser accurately captures headers and extracts payload for multiple parts including standard form fields and file attachments.","MultipartParser raises MultipartParseError when max_header_count limit is exceeded.","MultipartParser raises MultipartParseError when max_header_size limit is exceeded.","MultipartParser raises MultipartParseError when given malformed multipart payloads or invalid boundary sequences."],"goal":"parse multipart form data and form fields using MultipartParser","kind":"HOW","packages":["pkg:pypi/python-multipart@0.0.32"],"schemaVersion":1,"symbols":["multipart.MultipartParser"]},"contractCommand":["python","test/contract.py"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"pypi","executionContext":"python","language":"python","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"pip","runtime":"python","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/python-multipart@0.0.32"],"schemaVersion":1,"subject":"pkg:pypi/python-multipart@0.0.32","symbols":["multipart.MultipartParser"],"verifierAdapter":"python@1"}
python-multipart==0.0.32
{
"schemaVersion": 1,
"goal": "parse multipart form data and form fields using MultipartParser",
"kind": "HOW",
"packages": [
"pkg:pypi/python-multipart@0.0.32"
],
"symbols": [
"multipart.MultipartParser"
]
}
import io
import multipart
from multipart.multipart import MultipartParser, MultipartParseError
# 1. Verify MultipartParser parses streaming multipart/form-data chunk-by-chunk and dispatches lifecycle callbacks
boundary = "----WebKitFormBoundaryXyZ123456"
field_payload = (
f"--{boundary}\r\n"
"Content-Disposition: form-data; name=\"username\"\r\n\r\n"
"antigravity_user\r\n"
f"--{boundary}--\r\n"
).encode("utf-8")
events = []
header_fields = []
header_values = []
part_datas = []
def on_header_field(data, start, end):
header_fields.append(data[start:end].decode("latin-1"))
def on_header_value(data, start, end):
header_values.append(data[start:end].decode("latin-1"))
def on_part_data(data, start, end):
part_datas.append(data[start:end].decode("utf-8"))
parser1 = MultipartParser(
boundary,
{
"on_part_begin": lambda: events.append("part_begin"),
"on_header_field": on_header_field,
"on_header_value": on_header_value,
"on_header_end": lambda: events.append("header_end"),
"on_headers_finished": lambda: events.append("headers_finished"),
"on_part_data": on_part_data,
"on_part_end": lambda: events.append("part_end"),
"on_end": lambda: events.append("end"),
},
)
chunk_size = 10
for i in range(0, len(field_payload), chunk_size):
parser1.write(field_payload[i : i + chunk_size])
parser1.finalize()
assert "part_begin" in events
assert "".join(header_fields) == "Content-Disposition"
assert "".join(header_values) == "form-data; name=\"username\""
assert "headers_finished" in events
assert "".join(part_datas) == "antigravity_user"
assert "part_end" in events
assert "end" in events
# 2. Verify MultipartParser captures multiple parts including headers and file uploads
multipart_body = (
f"--{boundary}\r\n"
"Content-Disposition: form-data; name=\"title\"\r\n\r\n"
"Sample Title\r\n"
f"--{boundary}\r\n"
"Content-Disposition: form-data; name=\"document\"; filename=\"test.txt\"\r\n"
"Content-Type: text/plain; charset=utf-8\r\n\r\n"
"File payload line 1\r\nFile payload line 2\r\n"
f"--{boundary}--\r\n"
).encode("utf-8")
parsed_parts = []
current_part = {}
current_header_name = None
def on_part_begin():
global current_part, current_header_name
current_part = {"headers": {}, "data": bytearray()}
current_header_name = None
def on_header_field(data, start, end):
global current_header_name
field_chunk = data[start:end].decode("latin-1")
if current_header_name is None:
current_header_name = field_chunk
else:
current_header_name += field_chunk
def on_header_value(data, start, end):
global current_header_name
val_chunk = data[start:end].decode("latin-1")
if current_header_name in current_part["headers"]:
current_part["headers"][current_header_name] += val_chunk
else:
current_part["headers"][current_header_name] = val_chunk
def on_header_end():
global current_header_name
current_header_name = None
def on_part_data(data, start, end):
current_part["data"].extend(data[start:end])
def on_part_end():
parsed_parts.append(current_part)
parser2 = MultipartParser(
boundary,
{
"on_part_begin": on_part_begin,
"on_header_field": on_header_field,
"on_header_value": on_header_value,
"on_header_end": on_header_end,
"on_part_data": on_part_data,
"on_part_end": on_part_end,
},
)
parser2.write(multipart_body)
parser2.finalize()
assert len(parsed_parts) == 2, f"Expected 2 parts, got {len(parsed_parts)}"
part1 = parsed_parts[0]
assert "name=\"title\"" in part1["headers"].get("Content-Disposition", "")
assert bytes(part1["data"]).decode("utf-8") == "Sample Title"
part2 = parsed_parts[1]
assert "name=\"document\"" in part2["headers"].get("Content-Disposition", "")
assert "filename=\"test.txt\"" in part2["headers"].get("Content-Disposition", "")
assert part2["headers"].get("Content-Type") == "text/plain; charset=utf-8"
assert bytes(part2["data"]).decode("utf-8") == "File payload line 1\r\nFile payload line 2"
# 3. Verify max_header_count limit enforcement raises MultipartParseError
header_overflow_body = (
f"--{boundary}\r\n"
"H1: v1\r\n"
"H2: v2\r\n"
"H3: v3\r\n"
"H4: v4\r\n\r\n"
"data\r\n"
f"--{boundary}--\r\n"
).encode("utf-8")
parser3 = MultipartParser(boundary, {}, max_header_count=3)
try:
parser3.write(header_overflow_body)
parser3.finalize()
raise AssertionError("Expected MultipartParseError for header count overflow")
except MultipartParseError:
pass
# 4. Verify max_header_size limit enforcement raises MultipartParseError
long_header_body = (
f"--{boundary}\r\n"
"X-Long-Header: " + ("B" * 200) + "\r\n\r\n"
"data\r\n"
f"--{boundary}--\r\n"
).encode("utf-8")
parser4 = MultipartParser(boundary, {}, max_header_size=64)
try:
parser4.write(long_header_body)
parser4.finalize()
raise AssertionError("Expected MultipartParseError for header size overflow")
except MultipartParseError:
pass
# 5. Verify malformed boundary or invalid multipart payload raises MultipartParseError
parser5 = MultipartParser("expected_boundary_1234", {})
try:
parser5.write(b"completely invalid content without proper boundary\r\n")
parser5.finalize()
raise AssertionError("Expected MultipartParseError on malformed stream")
except MultipartParseError:
pass
print("CONTRACT PASS: python-multipart MultipartParser verified offline")
Origin Seeder
anonymous