CodeSampleX

Beispiel

urllib3 2.7.0: exceptions.URLSchemeUnknown

Verifiziertes Beispiel für pypi urllib3 2.7.0: exceptions.URLSchemeUnknown. Der Vertrag lief auf python 3.12 · linux debian/x64 · docker und bestand.

sha256:5fbd9caacb21de3e2bbfae278c52f7de787ab8d59ff7a97ad019d2d03491c1f3

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 linux 24 · ubuntu · glibc 2.39 x64 pip

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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

Fall

HOW
Ziel
verify urllib3.exceptions.URLSchemeUnknown in pkg:pypi/urllib3@2.7.0
Pakete
Symbole
  • urllib3.exceptions.URLSchemeUnknown
Erstellt
2026-09-06T00:39:28Z

Contract

  1. assert URLSchemeUnknown inherits from LocationValueError, ValueError, and HTTPError
  2. assert URLSchemeUnknown stores the unsupported scheme string in its scheme attribute
  3. assert URLSchemeUnknown string representation formats as Not supported URL scheme followed by scheme
  4. assert PoolManager.connection_from_url raises URLSchemeUnknown when given an unsupported scheme
  5. assert PoolManager.connection_from_context raises URLSchemeUnknown when request context contains an unsupported scheme
  6. assert urllib3.request raises URLSchemeUnknown when called with an unsupported scheme URL

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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 urllib3.exceptions.URLSchemeUnknown in pkg:pypi/urllib3@2.7.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:pypi/urllib3@2.7.0
Demonstrate these symbols/APIs:
  - urllib3.exceptions.URLSchemeUnknown

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:083f2e6905da0dfd5e1d814f65dc0e09b34f2b6f6b9acd4603721dba76436b18","contract":["assert URLSchemeUnknown inherits from LocationValueError, ValueError, and HTTPError","assert URLSchemeUnknown stores the unsupported scheme string in its scheme attribute","assert URLSchemeUnknown string representation formats as Not supported URL scheme followed by scheme","assert PoolManager.connection_from_url raises URLSchemeUnknown when given an unsupported scheme","assert PoolManager.connection_from_context raises URLSchemeUnknown when request context contains an unsupported scheme","assert urllib3.request raises URLSchemeUnknown when called with an unsupported scheme URL"],"goal":"verify urllib3.exceptions.URLSchemeUnknown in pkg:pypi/urllib3@2.7.0","kind":"HOW","packages":["pkg:pypi/urllib3@2.7.0"],"schemaVersion":1,"symbols":["urllib3.exceptions.URLSchemeUnknown"]},"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/urllib3@2.7.0"],"schemaVersion":1,"subject":"pkg:pypi/urllib3@2.7.0","symbols":["urllib3.exceptions.URLSchemeUnknown"],"verifierAdapter":"python@1"}
pyproject.toml
[project]
name = "verify-urllib3-urlschemeunknown"
version = "0.1.0"
dependencies = [
    "urllib3==2.7.0",
]
requirements.txt
urllib3==2.7.0
sample.py
"""Demonstration of urllib3 URL scheme validation and URLSchemeUnknown exception handling."""

from typing import Any, Dict, Optional
import urllib3
from urllib3.exceptions import HTTPError, LocationValueError, URLSchemeUnknown


def get_connection_pool_for_url(
    pool_manager: urllib3.PoolManager,
    url: str,
) -> urllib3.connectionpool.HTTPConnectionPool:
    """Acquire a connection pool from PoolManager for the specified URL.

    Raises URLSchemeUnknown if the URL has an unsupported scheme.
    """
    return pool_manager.connection_from_url(url)


def get_connection_pool_for_context(
    pool_manager: urllib3.PoolManager,
    request_context: Dict[str, Any],
) -> urllib3.connectionpool.HTTPConnectionPool:
    """Acquire a connection pool based on request context dictionary.

    Raises URLSchemeUnknown if the scheme in request_context is not supported.
    """
    return pool_manager.connection_from_context(request_context)


def dispatch_request(method: str, url: str) -> Optional[urllib3.response.BaseHTTPResponse]:
    """Dispatch an HTTP request via urllib3.request.

    Raises URLSchemeUnknown if the target URL has an unsupported scheme.
    """
    return urllib3.request(method, url)


def is_url_scheme_unknown_error(exc: Exception) -> bool:
    """Check if an exception is an instance of URLSchemeUnknown and its expected base classes."""
    return (
        isinstance(exc, URLSchemeUnknown)
        and isinstance(exc, LocationValueError)
        and isinstance(exc, ValueError)
        and isinstance(exc, HTTPError)
    )
spec.json
{
  "schemaVersion": 1,
  "goal": "verify urllib3.exceptions.URLSchemeUnknown in pkg:pypi/urllib3@2.7.0",
  "kind": "HOW",
  "packages": [
    "pkg:pypi/urllib3@2.7.0"
  ],
  "symbols": [
    "urllib3.exceptions.URLSchemeUnknown"
  ]
}
test/contract.py
"""Contract verification test for urllib3.exceptions.URLSchemeUnknown in pkg:pypi/urllib3@2.7.0."""

import os
import sys

# Ensure project root is on sys.path for local module imports
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

import urllib3
from urllib3.exceptions import HTTPError, LocationValueError, URLSchemeUnknown
from sample import (
    dispatch_request,
    get_connection_pool_for_context,
    get_connection_pool_for_url,
    is_url_scheme_unknown_error,
)


def test_inheritance_hierarchy() -> None:
    """Assertion 1: assert URLSchemeUnknown inherits from LocationValueError, ValueError, and HTTPError."""
    assert issubclass(URLSchemeUnknown, LocationValueError), "URLSchemeUnknown must inherit from LocationValueError"
    assert issubclass(URLSchemeUnknown, ValueError), "URLSchemeUnknown must inherit from ValueError"
    assert issubclass(URLSchemeUnknown, HTTPError), "URLSchemeUnknown must inherit from HTTPError"


def test_scheme_attribute() -> None:
    """Assertion 2: assert URLSchemeUnknown stores the unsupported scheme string in its scheme attribute."""
    unsupported_scheme = "custom"
    err = URLSchemeUnknown(unsupported_scheme)
    assert err.scheme == unsupported_scheme, f"Expected scheme '{unsupported_scheme}', got '{err.scheme}'"
    assert is_url_scheme_unknown_error(err), "err must be recognized by hierarchy check"


def test_string_representation() -> None:
    """Assertion 3: assert URLSchemeUnknown string representation formats as Not supported URL scheme followed by scheme."""
    unsupported_scheme = "ftp"
    err = URLSchemeUnknown(unsupported_scheme)
    expected_message = f"Not supported URL scheme {unsupported_scheme}"
    assert str(err) == expected_message, f"Expected '{expected_message}', got '{str(err)}'"


def test_pool_manager_connection_from_url() -> None:
    """Assertion 4: assert PoolManager.connection_from_url raises URLSchemeUnknown when given an unsupported scheme."""
    pm = urllib3.PoolManager()
    unsupported_url = "ftp://example.com/resource"
    raised = False
    try:
        get_connection_pool_for_url(pm, unsupported_url)
    except URLSchemeUnknown as exc:
        raised = True
        assert exc.scheme == "ftp", f"Expected scheme 'ftp', got '{exc.scheme}'"
        assert is_url_scheme_unknown_error(exc), "Exception must satisfy inheritance checks"

    assert raised, "PoolManager.connection_from_url should have raised URLSchemeUnknown"


def test_pool_manager_connection_from_context() -> None:
    """Assertion 5: assert PoolManager.connection_from_context raises URLSchemeUnknown when request context contains an unsupported scheme."""
    pm = urllib3.PoolManager()
    context = {"scheme": "gopher", "host": "example.com"}
    raised = False
    try:
        get_connection_pool_for_context(pm, context)
    except URLSchemeUnknown as exc:
        raised = True
        assert exc.scheme == "gopher", f"Expected scheme 'gopher', got '{exc.scheme}'"
        assert is_url_scheme_unknown_error(exc), "Exception must satisfy inheritance checks"

    assert raised, "PoolManager.connection_from_context should have raised URLSchemeUnknown"


def test_urllib3_request_unsupported_scheme() -> None:
    """Assertion 6: assert urllib3.request raises URLSchemeUnknown when called with an unsupported scheme URL."""
    unsupported_url = "ssh://example.com/target"
    raised = False
    try:
        dispatch_request("GET", unsupported_url)
    except URLSchemeUnknown as exc:
        raised = True
        assert exc.scheme == "ssh", f"Expected scheme 'ssh', got '{exc.scheme}'"
        assert is_url_scheme_unknown_error(exc), "Exception must satisfy inheritance checks"

    assert raised, "urllib3.request should have raised URLSchemeUnknown"


def main() -> None:
    test_inheritance_hierarchy()
    test_scheme_attribute()
    test_string_representation()
    test_pool_manager_connection_from_url()
    test_pool_manager_connection_from_context()
    test_urllib3_request_unsupported_scheme()
    print("All contract assertions passed.")


if __name__ == "__main__":
    main()

Ursprungs-Seeder

anonym