CodeSampleX

Ejemplo

httpcore 1.0.9: httpcore

Muestra verificada para pypi httpcore 1.0.9: httpcore. El contrato se ejecutó en python 3.12 · linux debian/x64 · docker y pasó.

sha256:f16a87e20d7ebe333ee8e0286377d0e1a7c67c425a8888379e1a1130b187bbf7

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-06

Caso

HOW
Objetivo
verify httpcore in pkg:pypi/httpcore@1.0.9
Paquetes
Símbolos
  • httpcore
Creado
2026-09-06T05:06:44Z

Contrato

  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

Archivos

  • PROMPT.md
  • csx.json
  • pyproject.toml
  • requirements.txt
  • sample.py
  • 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 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 de origen

anónimo