Beispiel
charset-normalizer 3.4.7: from_bytes
Verifiziertes Beispiel für pypi charset-normalizer 3.4.7: from_bytes. Der Vertrag lief auf python 3.12 · linux alpine/x64 · docker und bestand.
sha256:1138b526fd037ae1e2e129c918b740d1eb018eb461a65a7c6c87eefcdcdfe826
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 1.2 x64 python 3.12 python pip
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@1 |
2026-08-20 |
Fall
HOW- Ziel
- verify pkg:pypi/charset-normalizer@3.4.7
- Pakete
- Symbole
-
- from_bytes
- Umgebung
- python 3.12
- Erstellt
- 2026-08-20T21:45:53Z
Contract
- charset_normalizer.from_bytes(data) detects encoding from raw byte sequences
- matches.best() returns the highest-scoring CharsetMatch object
- best.encoding provides the normalized encoding identifier
- str(best) provides the decoded unicode string
Dateien
- PROMPT.md
- csx.json
- requirements.txt
- spec.json
- src/detector.py
- 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/charset-normalizer@3.4.7
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:pypi/charset-normalizer@3.4.7
Demonstrate these symbols/APIs:
- from_bytes
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- 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:8cb79b13b8a0f08f2638c06fb4c6c250fc5c6aa17b8390fee3d027a2af2d894c","contract":["charset_normalizer.from_bytes(data) detects encoding from raw byte sequences","matches.best() returns the highest-scoring CharsetMatch object","best.encoding provides the normalized encoding identifier","str(best) provides the decoded unicode string"],"goal":"verify pkg:pypi/charset-normalizer@3.4.7","kind":"HOW","packages":["pkg:pypi/charset-normalizer@3.4.7"],"schemaVersion":1,"symbols":["from_bytes"]},"contractCommand":["python","test/contract.py"],"environment":{"arch":"x64","distro":"alpine","ecosystem":"pypi","language":"python","libc":"musl","libcVersion":"1.2","os":"linux","osVersionBucket":"24","packageManager":"pip","runtime":"python","runtimeVersion":"3.12","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/charset-normalizer@3.4.7"],"schemaVersion":1,"subject":"pkg:pypi/charset-normalizer@3.4.7","symbols":["from_bytes"],"verifierAdapter":"python@1"}
charset-normalizer==3.4.7
{
"schemaVersion": 1,
"goal": "verify pkg:pypi/charset-normalizer@3.4.7",
"kind": "HOW",
"packages": [
"pkg:pypi/charset-normalizer@3.4.7"
],
"symbols": [
"from_bytes"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"runtime": "node@22.23.2"
}
}
"""Charset detector demonstration using charset_normalizer."""
import charset_normalizer
def detect_charset(data: bytes) -> dict:
"""Detect character encoding and decode input byte sequence.
Args:
data: Raw byte string to detect encoding for.
Returns:
dict containing 'encoding', 'confidence', 'text', and 'chaos'.
"""
matches = charset_normalizer.from_bytes(data)
best = matches.best()
if best is None:
return {
"encoding": None,
"confidence": 0.0,
"text": "",
"chaos": 1.0,
}
return {
"encoding": best.encoding,
"confidence": 1.0 - best.chaos,
"text": str(best),
"chaos": best.chaos,
}
"""Contract verification test for charset_normalizer.from_bytes."""
import os
import sys
# Ensure repository root is on sys.path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import charset_normalizer
from src.detector import detect_charset
def test_from_bytes_utf8():
sample_text = "Bonjour le monde! Ça va bien? Café & thé."
raw_bytes = sample_text.encode("utf-8")
matches = charset_normalizer.from_bytes(raw_bytes)
assert len(matches) > 0, "Expected at least one match"
best = matches.best()
assert best is not None, "Expected a valid best match"
assert best.encoding == "utf_8", f"Expected utf_8, got {best.encoding}"
assert str(best) == sample_text, f"Decoded text mismatch: {str(best)}"
assert best.chaos == 0.0, f"Expected 0.0 chaos score, got {best.chaos}"
def test_from_bytes_ascii():
sample_text = "Simple ASCII text payload"
raw_bytes = sample_text.encode("ascii")
matches = charset_normalizer.from_bytes(raw_bytes)
assert len(matches) > 0, "Expected at least one match"
best = matches.best()
assert best is not None, "Expected a valid best match"
assert best.encoding == "ascii", f"Expected ascii, got {best.encoding}"
assert str(best) == sample_text, f"Decoded text mismatch: {str(best)}"
def test_detector_helper():
sample_text = "Guten Tag! Schönen Tag noch."
raw_bytes = sample_text.encode("utf-8")
result = detect_charset(raw_bytes)
assert result["encoding"] == "utf_8", f"Unexpected encoding: {result['encoding']}"
assert result["text"] == sample_text, f"Unexpected text: {result['text']}"
assert result["chaos"] == 0.0, f"Unexpected chaos score: {result['chaos']}"
def main():
test_from_bytes_utf8()
test_from_bytes_ascii()
test_detector_helper()
print("Contract tests passed successfully.")
return 0
if __name__ == "__main__":
sys.exit(main())
Ursprungs-Seeder
anonym