Beispiel
orjson 3.11.9: dumps, loads, Fragment
Verifiziertes Beispiel für pypi orjson 3.11.9: dumps, loads, Fragment. Der Vertrag lief auf python 3.12 · linux alpine/x64 · docker und bestand.
sha256:f8344bc2f01f1dee17eb5cb282749b666f9c5af36338fe03921933d31be3be70
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
python 3.12 linux 24 · alpine · musl x64 python 3.12 python pip 24
Umgebungen der Verifizierungsläufe
| Umgebung | Contract | Stufen | Lauf |
|---|---|---|---|
| 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-28 |
Fall
HOW- Ziel
- verify pkg:pypi/orjson@3.11.9
- Pakete
- Symbole
-
- orjson.dumps
- orjson.loads
- orjson.Fragment
- orjson.OPT_APPEND_NEWLINE
- orjson.OPT_INDENT_2
- orjson.OPT_NAIVE_UTC
- orjson.OPT_NON_STR_KEYS
- orjson.OPT_OMIT_MICROSECONDS
- orjson.OPT_PASSTHROUGH_DATACLASS
- orjson.OPT_PASSTHROUGH_SUBCLASS
- orjson.OPT_STRICT_INTEGER
- orjson.OPT_UTC_Z
- orjson.JSONDecodeError
- orjson.JSONEncodeError
- Umgebung
- python 3.12
- Erstellt
- 2026-08-28T06:42:15Z
Contract
- assert orjson.dumps serializes @dataclass instances natively and respects OPT_PASSTHROUGH_DATACLASS for custom default serialization
- assert orjson.dumps with OPT_PASSTHROUGH_SUBCLASS delegates dict and list subclasses to default callable
- assert orjson.dumps with OPT_STRICT_INTEGER rejects integers outside 53-bit range [-(2**53-1), 2**53-1] with JSONEncodeError
- assert orjson.dumps supports OPT_APPEND_NEWLINE, OPT_NAIVE_UTC, OPT_OMIT_MICROSECONDS, and OPT_UTC_Z option bitmasks
- assert orjson.Fragment embeds raw pre-serialized JSON bytes directly into dumps output
- assert orjson.loads parses bytes, bytearray, memoryview, and str inputs while rejecting UTF-8 BOM and invalid UTF-8 with JSONDecodeError
Dateien
- PROMPT.md
- csx.json
- pyproject.toml
- requirements.txt
- spec.json
- test/contract.py
Quelltext
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 pkg:pypi/orjson@3.11.9
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:pypi/orjson@3.11.9
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
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:f5352e07bf2fec1867e589080e488b309750210a8d8277ecf90215fc137f6c81","constraints":{"executionContext":"python"},"contract":["assert orjson.dumps serializes @dataclass instances natively and respects OPT_PASSTHROUGH_DATACLASS for custom default serialization","assert orjson.dumps with OPT_PASSTHROUGH_SUBCLASS delegates dict and list subclasses to default callable","assert orjson.dumps with OPT_STRICT_INTEGER rejects integers outside 53-bit range [-(2**53-1), 2**53-1] with JSONEncodeError","assert orjson.dumps supports OPT_APPEND_NEWLINE, OPT_NAIVE_UTC, OPT_OMIT_MICROSECONDS, and OPT_UTC_Z option bitmasks","assert orjson.Fragment embeds raw pre-serialized JSON bytes directly into dumps output","assert orjson.loads parses bytes, bytearray, memoryview, and str inputs while rejecting UTF-8 BOM and invalid UTF-8 with JSONDecodeError"],"goal":"verify pkg:pypi/orjson@3.11.9","kind":"HOW","packages":["pkg:pypi/orjson@3.11.9"],"schemaVersion":1,"symbols":["orjson.dumps","orjson.loads","orjson.Fragment","orjson.OPT_APPEND_NEWLINE","orjson.OPT_INDENT_2","orjson.OPT_NAIVE_UTC","orjson.OPT_NON_STR_KEYS","orjson.OPT_OMIT_MICROSECONDS","orjson.OPT_PASSTHROUGH_DATACLASS","orjson.OPT_PASSTHROUGH_SUBCLASS","orjson.OPT_STRICT_INTEGER","orjson.OPT_UTC_Z","orjson.JSONDecodeError","orjson.JSONEncodeError"]},"contractCommand":["python3","test/contract.py"],"environment":{"arch":"x64","distro":"alpine","ecosystem":"pypi","executionContext":"python","language":"python","libc":"musl","moduleSystem":"standard","os":"linux","osVersionBucket":"24","packageManager":"pip","packageManagerVersion":"24.0","runtime":"python","runtimeVersion":"3.12","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/orjson@3.11.9"],"schemaVersion":1,"subject":"pkg:pypi/orjson@3.11.9","symbols":["orjson.dumps","orjson.loads","orjson.Fragment","orjson.OPT_APPEND_NEWLINE","orjson.OPT_INDENT_2","orjson.OPT_NAIVE_UTC","orjson.OPT_NON_STR_KEYS","orjson.OPT_OMIT_MICROSECONDS","orjson.OPT_PASSTHROUGH_DATACLASS","orjson.OPT_PASSTHROUGH_SUBCLASS","orjson.OPT_STRICT_INTEGER","orjson.OPT_UTC_Z","orjson.JSONDecodeError","orjson.JSONEncodeError"],"verifierAdapter":"python@1"}
[project]
name = "verify-orjson"
version = "0.1.0"
dependencies = [
"orjson==3.11.9",
]
orjson==3.11.9
{
"schemaVersion": 1,
"goal": "verify pkg:pypi/orjson@3.11.9",
"kind": "HOW",
"packages": [
"pkg:pypi/orjson@3.11.9"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
import dataclasses
import datetime as dt
import json
import uuid
import orjson
def test_dataclass_serialization_and_passthrough():
@dataclasses.dataclass
class Item:
id: int
name: str
item = Item(id=42, name="Widget")
assert orjson.dumps(item) == b'{"id":42,"name":"Widget"}'
def custom_default(obj):
if isinstance(obj, Item):
return {"item_id": obj.id, "title": obj.name.upper()}
raise TypeError
custom_output = orjson.dumps(
item,
default=custom_default,
option=orjson.OPT_PASSTHROUGH_DATACLASS,
)
assert custom_output == b'{"item_id":42,"title":"WIDGET"}'
def test_subclass_passthrough():
class TaggedDict(dict):
pass
class TaggedList(list):
pass
td = TaggedDict({"k": "v"})
tl = TaggedList([1, 2, 3])
# Default behavior serializes as regular dict / list
assert orjson.dumps(td) == b'{"k":"v"}'
assert orjson.dumps(tl) == b'[1,2,3]'
def subclass_default(obj):
if isinstance(obj, TaggedDict):
return {"__type__": "TaggedDict", "content": dict(obj)}
if isinstance(obj, TaggedList):
return {"__type__": "TaggedList", "items": list(obj)}
raise TypeError
res = orjson.dumps(
{"dict": td, "list": tl},
default=subclass_default,
option=orjson.OPT_PASSTHROUGH_SUBCLASS,
)
assert res == b'{"dict":{"__type__":"TaggedDict","content":{"k":"v"}},"list":{"__type__":"TaggedList","items":[1,2,3]}}'
def test_strict_integer():
max_safe = (1 << 53) - 1
min_safe = -((1 << 53) - 1)
assert orjson.dumps(max_safe, option=orjson.OPT_STRICT_INTEGER) == str(max_safe).encode()
assert orjson.dumps(min_safe, option=orjson.OPT_STRICT_INTEGER) == str(min_safe).encode()
try:
orjson.dumps(max_safe + 1, option=orjson.OPT_STRICT_INTEGER)
assert False, "Should have raised JSONEncodeError for integer > 2^53 - 1"
except (orjson.JSONEncodeError, TypeError) as exc:
assert isinstance(exc, TypeError)
try:
orjson.dumps(min_safe - 1, option=orjson.OPT_STRICT_INTEGER)
assert False, "Should have raised JSONEncodeError for integer < -(2^53 - 1)"
except (orjson.JSONEncodeError, TypeError) as exc:
assert isinstance(exc, TypeError)
def test_option_bitmasks():
# OPT_APPEND_NEWLINE
assert orjson.dumps({"msg": "hello"}, option=orjson.OPT_APPEND_NEWLINE) == b'{"msg":"hello"}\n'
# OPT_NAIVE_UTC & OPT_OMIT_MICROSECONDS & OPT_UTC_Z
naive_moment = dt.datetime(2026, 8, 28, 14, 30, 0, 123456)
assert orjson.dumps(naive_moment) == b'"2026-08-28T14:30:00.123456"'
assert orjson.dumps(naive_moment, option=orjson.OPT_NAIVE_UTC) == b'"2026-08-28T14:30:00.123456+00:00"'
assert orjson.dumps(naive_moment, option=orjson.OPT_NAIVE_UTC | orjson.OPT_UTC_Z) == b'"2026-08-28T14:30:00.123456Z"'
assert orjson.dumps(naive_moment, option=orjson.OPT_OMIT_MICROSECONDS) == b'"2026-08-28T14:30:00"'
assert (
orjson.dumps(
naive_moment,
option=orjson.OPT_NAIVE_UTC | orjson.OPT_OMIT_MICROSECONDS | orjson.OPT_UTC_Z,
)
== b'"2026-08-28T14:30:00Z"'
)
def test_fragment_raw_json():
assert hasattr(orjson, "Fragment")
raw_payload = b'{"nested_status":"ok","code":200}'
frag = orjson.Fragment(raw_payload)
output = orjson.dumps({"status": "active", "detail": frag})
assert output == b'{"status":"active","detail":{"nested_status":"ok","code":200}}'
def test_loads_buffer_types_and_rejections():
data = {"status": "ok", "value": 100}
json_bytes = b'{"status":"ok","value":100}'
assert orjson.loads(json_bytes) == data
assert orjson.loads(bytearray(json_bytes)) == data
assert orjson.loads(memoryview(json_bytes)) == data
assert orjson.loads(json_bytes.decode("utf-8")) == data
# Rejection of UTF-8 BOM
bom_data = b"\xef\xbb\xbf" + json_bytes
try:
orjson.loads(bom_data)
assert False, "orjson.loads should reject UTF-8 BOM"
except (orjson.JSONDecodeError, ValueError) as exc:
assert isinstance(exc, ValueError)
assert issubclass(orjson.JSONDecodeError, json.JSONDecodeError)
# Rejection of invalid UTF-8
invalid_utf8 = b'{"bad": \xff}'
try:
orjson.loads(invalid_utf8)
assert False, "orjson.loads should reject invalid UTF-8 bytes"
except (orjson.JSONDecodeError, ValueError) as exc:
assert isinstance(exc, ValueError)
def main():
test_dataclass_serialization_and_passthrough()
test_subclass_passthrough()
test_strict_integer()
test_option_bitmasks()
test_fragment_raw_json()
test_loads_buffer_types_and_rejections()
print("All orjson contract assertions passed.")
if __name__ == "__main__":
main()
Ursprungs-Seeder
anonym