CodeSampleX

Exemplo

urllib3 2.7.0: util.Url

Amostra verificada para pypi urllib3 2.7.0: util.Url. O contrato rodou em python 3.12 · linux debian/x64 · docker e passou: Url NamedTuple stores scheme…

sha256:3b1e6d58f27c576a6b35052128a9070efcedba49b1713d9dfade7e42f88d59ec

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado python linux 24 · ubuntu · glibc 2.39 x64 python python pip

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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-05

Caso

HOW
Objetivo
verify urllib3.util.Url in pkg:pypi/urllib3@2.7.0
Pacotes
Símbolos
  • urllib3.util.Url
Ambiente
python
Criado
2026-09-05T23:33:07Z

Contrato

  1. Url NamedTuple stores scheme, auth, host, port, path, query, and fragment fields, normalizing scheme to lowercase and path to begin with a leading slash.
  2. url property and __str__() reconstruct the full RFC-compliant URL string from components.
  3. authority, netloc, and hostname properties correctly extract host, port, and authentication components.
  4. request_uri property returns the combined path and query string, defaulting to '/' when path is absent.
  5. Url instances are immutable namedtuples that support _replace() and can be hashed and compared for equality.

Arquivos

  • NOTES.md
  • PROMPT.md
  • csx.json
  • requirements.txt
  • spec.json
  • test/contract.py

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

NOTES.md
# urllib3 Url API

This sample pins `urllib3` 2.7.0 and verifies `urllib3.util.Url` for URL data representation, component extraction, and string reconstruction.

The contract verifies:
- `Url` NamedTuple stores `scheme`, `auth`, `host`, `port`, `path`, `query`, and `fragment` fields, normalizing scheme to lowercase and path to begin with a leading slash.
- `url` property and `__str__()` reconstruct the full RFC-compliant URL string from components.
- `authority`, `netloc`, and `hostname` properties correctly extract host, port, and authentication components.
- `request_uri` property returns the combined path and query string, defaulting to `'/'` when path is absent.
- `Url` instances are immutable namedtuples that support `_replace()` and can be hashed and compared for equality.
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.util.Url 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.util.Url

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:bf98bcb58d34ae175afc5ef77a5be673ee52d578f68f369a5b942925d724a147","contract":["Url NamedTuple stores scheme, auth, host, port, path, query, and fragment fields, normalizing scheme to lowercase and path to begin with a leading slash.","url property and __str__() reconstruct the full RFC-compliant URL string from components.","authority, netloc, and hostname properties correctly extract host, port, and authentication components.","request_uri property returns the combined path and query string, defaulting to '/' when path is absent.","Url instances are immutable namedtuples that support _replace() and can be hashed and compared for equality."],"goal":"verify urllib3.util.Url in pkg:pypi/urllib3@2.7.0","kind":"HOW","packages":["pkg:pypi/urllib3@2.7.0"],"schemaVersion":1,"symbols":["urllib3.util.Url"]},"contractCommand":["python","test/contract.py"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"pypi","executionContext":"python","language":"python","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"pip","runtime":"python","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/urllib3@2.7.0"],"schemaVersion":1,"subject":"pkg:pypi/urllib3@2.7.0","symbols":["urllib3.util.Url"],"verifierAdapter":"python@1"}
requirements.txt
urllib3==2.7.0
spec.json
{
  "schemaVersion": 1,
  "goal": "verify urllib3.util.Url in pkg:pypi/urllib3@2.7.0",
  "kind": "HOW",
  "packages": [
    "pkg:pypi/urllib3@2.7.0"
  ],
  "symbols": [
    "urllib3.util.Url"
  ]
}
test/contract.py
import urllib3
from urllib3.util import Url, parse_url

# 1. Url NamedTuple stores scheme, auth, host, port, path, query, and fragment fields,
#    normalizing scheme to lowercase and path to begin with a leading slash.
u = Url(
    scheme="HTTPS",
    auth="user:pass",
    host="example.com",
    port=8443,
    path="api/v1/resource",
    query="filter=active&limit=10",
    fragment="section2",
)
assert u.scheme == "https", f"Expected scheme lowercased to https, got {u.scheme}"
assert u.auth == "user:pass"
assert u.host == "example.com"
assert u.port == 8443
assert u.path == "/api/v1/resource", f"Expected path with leading slash, got {u.path}"
assert u.query == "filter=active&limit=10"
assert u.fragment == "section2"

# 2. url property and __str__() reconstruct the full RFC-compliant URL string from components.
u_clean = Url(
    scheme="HTTPS",
    host="example.com",
    port=8443,
    path="api/v1/resource",
    query="filter=active&limit=10",
    fragment="section2",
)
clean_url = "https://example.com:8443/api/v1/resource?filter=active&limit=10#section2"
assert u_clean.url == clean_url
assert str(u_clean) == clean_url

# Ensure auth component is included when reconstructing URL with authentication
assert u.url.startswith("https://")
assert f"{u.auth}@" in u.url
assert u.url.endswith("example.com:8443/api/v1/resource?filter=active&limit=10#section2")

# 3. authority, netloc, and hostname properties correctly extract host, port, and authentication components.
assert u.netloc == "example.com:8443"
assert u.authority == "user:pass@example.com:8443"
assert u.hostname == "example.com"

u_no_auth = Url(scheme="http", host="example.com", port=80)
assert u_no_auth.netloc == "example.com:80"
assert u_no_auth.authority == "example.com:80"

u_no_port = Url(scheme="http", host="example.com")
assert u_no_port.netloc == "example.com"
assert u_no_port.authority == "example.com"
assert Url(path="/relative").hostname is None

# 4. request_uri property returns the combined path and query string, defaulting to '/' when path is absent.
assert u.request_uri == "/api/v1/resource?filter=active&limit=10"
assert Url(scheme="http", host="example.com").request_uri == "/"
assert Url(path="/index.html").request_uri == "/index.html"
assert Url(path="/search", query="q=test").request_uri == "/search?q=test"

# 5. Url instances are immutable namedtuples that support _replace() and can be hashed and compared for equality.
try:
    u.host = "localhost"
    raise AssertionError("Url instance should be immutable")
except AttributeError:
    pass

u_replaced = u_clean._replace(path="/api/v2/items", port=443)
assert u_replaced.path == "/api/v2/items"
assert u_replaced.port == 443
assert u_replaced.host == "example.com"
assert u_replaced.url == "https://example.com:443/api/v2/items?filter=active&limit=10#section2"

u_identical = Url(
    scheme="https",
    auth="user:pass",
    host="example.com",
    port=8443,
    path="/api/v1/resource",
    query="filter=active&limit=10",
    fragment="section2",
)
assert u == u_identical
assert hash(u) == hash(u_identical)
url_set = {u, u_replaced}
assert len(url_set) == 2
assert u in url_set

# Interoperability with parse_url
parsed = parse_url(clean_url)
assert isinstance(parsed, Url)
assert parsed == u_clean

print("CONTRACT PASS: urllib3.util.Url verified offline")

Seeder de origem

anônimo