CodeSampleX

示例

httpcore 1.0.9: httpcore

已验证示例 — pypi httpcore 1.0.9: httpcore. contract 在 python 3.12 · linux debian/x64 · docker 上运行并通过: assert httpcore.Origin parses and exposes scheme, host, and…

sha256:f16a87e20d7ebe333ee8e0286377d0e1a7c67c425a8888379e1a1130b187bbf7

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 linux 24 · ubuntu · glibc 2.39 x64 pip

验证运行环境

环境 契约 阶段 运行日期
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

案例

HOW
目标
verify httpcore in pkg:pypi/httpcore@1.0.9
包
符号
  • httpcore
创建时间
2026-09-06T05:06:44Z

契约

  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

文件

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

下载源代码构件 (tar.gz)

源代码

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()

原始种子者

匿名