Skip to content

ietfparse.datastructures

ietfparse.datastructures.ContentType(content_type, content_subtype, parameters=None, content_suffix=None)

A MIME Content-Type header.

Internet content types are described by the Content-Type header from RFC-2045. It was reused across many other protocol specifications, most notably HTTP (RFC-9110). In its most basic form, a content type header looks like text/html. The primary content type is text with a subtype of html. Content type headers may include parameters as name=value pairs separated by colons.

RFC-6839 added the ability to use a content type to identify the semantic value of a representation with a content type and also identify the document format as a content type suffix. For example, application/vnd.github.v3+json is used to identify documents that match version 3 of the GitHub API that are represented as JSON documents. The same entity encoded as msgpack would have the content type application/vnd.github.v3+msgpack. In this case, the content type identifies the information that is in the document and the suffix is used to identify the content format.

Parameters:

Name Type Description Default
content_type str

the primary content type

required
content_subtype str

the content subtype

required
content_suffix str | None

optional content suffix

None
parameters Mapping[str, str | int] | None

optional dictionary of content type parameters

None

ietfparse.datastructures.LinkHeader(target, parameters=None)

Represents a single link within a Link header.

The Link header is specified by RFC-8288. It is one of the methods used to represent HyperMedia links between HTTP resources.

Methods:

Name Description
__getitem__

Return the parameter values for param_name as a list.

Attributes:

Name Type Description
parameters Sequence[tuple[str, str]]

Possibly empty sequence of name and value pairs.

rel str

Space-separated relationship parameter.

target str

The target URL of the link.

parameters cached property

Possibly empty sequence of name and value pairs.

Parameters are represented as a sequence since a single parameter may occur more than once.

rel cached property

Space-separated relationship parameter.

This will be the empty string if the rel parameter was not included.

target property

The target URL of the link.

This may be a relative URL so the caller may have to make the link absolute by resolving it against a base URL as described in RFC-3986.

__getitem__(param_name)

Return the parameter values for param_name as a list.

If param_name is not present, then an empty sequence is returned.