pkgcore.bugzilla.transport module

HTTP plumbing for the Bugzilla REST API, on top of stdlib urllib.

class pkgcore.bugzilla.transport.AuthMode(*values)[source]

Bases: StrEnum

Where the api key is placed.

QUERY is the only mode bugs.gentoo.org honours today; HEADER exists for instances running Bugzilla 6.

HEADER = 'header'
QUERY = 'query'
class pkgcore.bugzilla.transport.Transport(*args, **kwargs)[source]

Bases: Protocol

The seam a client talks through

request(method: str, path: str, *, params: Sequence[tuple[str, str]] = (), body: RequestBody | None = None) JSONValue[source]
class pkgcore.bugzilla.transport.UrllibTransport(base_url: str = 'https://bugs.gentoo.org', api_key: str | None = None, *, timeout: float = 30.0, retries: int = 3, auth_mode: AuthMode = AuthMode.QUERY, retry_writes: bool = False, user_agent: str | None = None, opener: OpenerDirector | None = None)[source]

Bases: object

A Bugzilla transport built on urllib.request.

Reads are retried with exponential backoff, since bugs.gentoo.org signals overload by resetting the connection rather than returning 429. Writes are not, because a retried bug creation files a duplicate.

property authenticated: bool
request(method: str, path: str, *, params: Sequence[tuple[str, str]] = (), body: RequestBody | None = None) JSONValue[source]
pkgcore.bugzilla.transport.build_opener() OpenerDirector[source]

The opener used when a transport isn’t given one.

Indirected through a function so that pkgcore.bugzilla.testing can replace it, and intercept clients built somewhere it can’t reach.

pkgcore.bugzilla.transport.build_user_agent(client: str | None = None) str[source]

Compose the User-Agent, most specific product first.

A caller’s own token goes in front of pkgcore’s rather than replacing it, so Gentoo infra can tell which tool the traffic came from while pkgcore stays identifiable.

pkgcore.bugzilla.transport.expect_list(payload: JSONValue, key: str, context: str) list[Any][source]
pkgcore.bugzilla.transport.expect_object(payload: JSONValue, context: str) dict[str, Any][source]
pkgcore.bugzilla.transport.redact(url: str) str[source]

Strip the api key out of a url before it reaches a log or traceback