CodeSampleX

Exemple

httpcore 1.0.9: httpcore

Échantillon vérifié pour pypi httpcore 1.0.9: httpcore. Le contrat s'est exécuté sur python 3.12 · linux debian/x64 · docker et a réussi.

sha256:f16a87e20d7ebe333ee8e0286377d0e1a7c67c425a8888379e1a1130b187bbf7

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 pip

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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-06

Cas

HOW
Objectif
verify httpcore in pkg:pypi/httpcore@1.0.9
Paquets
Symboles
  • httpcore
Créé
2026-09-06T05:06:44Z

Contrat

  1. assert httpcore.Origin parses and exposes scheme, host, and port components
  2. assert httpcore.HTTPProxy executes HTTP requests through a proxy using httpcore.MockBackend offline
  3. assert httpcore.HTTPProxy supports proxy authentication credentials
  4. assert httpcore.default_ssl_context returns an SSLContext instance
  5. assert httpcore.ProxyError and httpcore.ConnectionNotAvailable inherit from Exception
  6. assert httpcore.PoolTimeout and httpcore.ConnectTimeout inherit from httpcore.TimeoutException

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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 httpcore in pkg:pypi/httpcore@1.0.9
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:pypi/httpcore@1.0.9
Demonstrate these symbols/APIs:
  - httpcore

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:587ca446dce1e3230e888a4af0e54bf14af1590e3f1a395943b7b5eb50fea192","contract":["assert httpcore.Origin parses and exposes scheme, host, and port components","assert httpcore.HTTPProxy executes HTTP requests through a proxy using httpcore.MockBackend offline","assert httpcore.HTTPProxy supports proxy authentication credentials","assert httpcore.default_ssl_context returns an SSLContext instance","assert httpcore.ProxyError and httpcore.ConnectionNotAvailable inherit from Exception","assert httpcore.PoolTimeout and httpcore.ConnectTimeout inherit from httpcore.TimeoutException"],"goal":"verify httpcore in pkg:pypi/httpcore@1.0.9","kind":"HOW","packages":["pkg:pypi/httpcore@1.0.9"],"schemaVersion":1,"symbols":["httpcore"]},"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/httpcore@1.0.9"],"schemaVersion":1,"subject":"pkg:pypi/httpcore@1.0.9","symbols":["httpcore"],"verifierAdapter":"python@1"}
pyproject.toml
[project]
name = "verify-httpcore"
version = "0.1.0"
dependencies = [
    "httpcore==1.0.9",
    "certifi",
    "h11",
]
requirements.txt
httpcore==1.0.9
certifi
h11
sample.py
"""Sample demonstrating httpcore proxy, origin, ssl context, and exception handling."""

import ssl
import httpcore


def create_origin(scheme: bytes, host: bytes, port: int) -> httpcore.Origin:
    """Construct a network origin."""
    return httpcore.Origin(scheme, host, port)


def make_proxy_request(
    proxy_url: str,
    target_url: str,
    response_data: bytes,
    proxy_auth: tuple[str, str] | None = None,
) -> tuple[int, bytes]:
    """Send a request through HTTPProxy using a mock backend offline."""
    mock_backend = httpcore.MockBackend(
        buffer=[
            b"HTTP/1.1 200 OK\r\n",
            b"Content-Type: text/plain\r\n",
            f"Content-Length: {len(response_data)}\r\n".encode("ascii"),
            b"\r\n",
            response_data,
        ]
    )
    with httpcore.HTTPProxy(
        proxy_url=proxy_url,
        proxy_auth=proxy_auth,
        network_backend=mock_backend,
    ) as proxy:
        resp = proxy.request("GET", target_url)
        return resp.status, resp.read()


def get_default_ssl_context() -> ssl.SSLContext:
    """Obtain default SSL context from httpcore."""
    return httpcore.default_ssl_context()
spec.json
{
  "schemaVersion": 1,
  "goal": "verify httpcore in pkg:pypi/httpcore@1.0.9",
  "kind": "HOW",
  "packages": [
    "pkg:pypi/httpcore@1.0.9"
  ],
  "symbols": [
    "httpcore"
  ]
}
test/contract.py
"""Contract verification test for httpcore in pkg:pypi/httpcore@1.0.9."""

import os
import ssl
import sys

# Ensure sample root directory is in sys.path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

import httpcore
import sample


def test_origin_components() -> None:
    """Assertion: assert httpcore.Origin parses and exposes scheme, host, and port components."""
    origin = sample.create_origin(b"https", b"example.com", 443)
    assert origin.scheme == b"https"
    assert origin.host == b"example.com"
    assert origin.port == 443


def test_http_proxy_mock_backend() -> None:
    """Assertion: assert httpcore.HTTPProxy executes HTTP requests through a proxy using httpcore.MockBackend offline."""
    status, body = sample.make_proxy_request(
        proxy_url="http://proxy.example.com:8080",
        target_url="http://target.example.com/data",
        response_data=b"proxy-ok",
    )
    assert status == 200
    assert body == b"proxy-ok"


def test_http_proxy_authentication() -> None:
    """Assertion: assert httpcore.HTTPProxy supports proxy authentication credentials."""
    status, body = sample.make_proxy_request(
        proxy_url="http://proxy.example.com:8080",
        target_url="http://target.example.com/secure",
        response_data=b"authenticated",
        proxy_auth=("proxyuser", "secretpass"),
    )
    assert status == 200
    assert body == b"authenticated"


def test_default_ssl_context() -> None:
    """Assertion: assert httpcore.default_ssl_context returns an SSLContext instance."""
    ctx = sample.get_default_ssl_context()
    assert isinstance(ctx, ssl.SSLContext)


def test_exception_hierarchy() -> None:
    """Assertion: assert httpcore.ProxyError and httpcore.ConnectionNotAvailable inherit from Exception."""
    assert issubclass(httpcore.ProxyError, Exception)
    assert issubclass(httpcore.ConnectionNotAvailable, Exception)
    assert issubclass(httpcore.PoolTimeout, httpcore.TimeoutException)
    assert issubclass(httpcore.ConnectTimeout, httpcore.TimeoutException)
    assert issubclass(httpcore.RemoteProtocolError, httpcore.ProtocolError)
    assert issubclass(httpcore.LocalProtocolError, httpcore.ProtocolError)


def main() -> None:
    test_origin_components()
    test_http_proxy_mock_backend()
    test_http_proxy_authentication()
    test_default_ssl_context()
    test_exception_hierarchy()
    print("All httpcore contract assertions passed.")


if __name__ == "__main__":
    main()

Seeder d'origine

anonyme