class documentation

Mutable metadata collection with case-insensitive keys.

This container normalizes keys to lowercase and supports convenient indexing by integer, slice, or key string:

  • metadata[i] returns the key/value tuple at index i.
  • metadata[i:j] returns a list of key/value tuples.
  • metadata["key"] returns a list of values for that key.
Method __delitem__ Delete metadata by numeric index, slice, or key.
Method __getitem__ Return metadata entries by index, slice, or key.
Method __has__ Return True if a key exists in the collection.
Method __init__ Create a metadata collection.
Method __len__ Return the number of stored entries.
Method __repr__ Return a debug representation of the metadata.
Method __setitem__ Set metadata by numeric index, slice, or key.
Method add Append a key/value pair, lowercasing the key.
Method get_one Return the first or last value for a key.
Method insert Insert a key/value pair at the given index.
Instance Variable _contents Undocumented
def __delitem__(self, index: int | slice | str): (source)

Delete metadata by numeric index, slice, or key.

@overload
def __getitem__(self, index: int) -> tuple[str, str]:
@overload
def __getitem__(self, index: slice) -> MutableSequence[tuple[str, str]]:
@overload
def __getitem__(self, index: str) -> Sequence[str]:
(source)

Return metadata entries by index, slice, or key.

def __has__(self, key: str) -> bool: (source)

Return True if a key exists in the collection.

def __init__(self, initial: Iterable[tuple[str, str]] | None = None): (source)

Create a metadata collection.

Parameters
initial:Iterable[tuple[str, str]] | NoneOptional iterable of (key, value) pairs. Only string keys and values are stored and keys are lowercased.
def __len__(self) -> int: (source)

Return the number of stored entries.

def __repr__(self) -> str: (source)

Return a debug representation of the metadata.

def __setitem__(self, index: int | slice | str, value: tuple[str, str] | Iterable[tuple[str, str]] | Iterable[str] | str): (source)

Set metadata by numeric index, slice, or key.

def add(self, index: str, value: str): (source)

Append a key/value pair, lowercasing the key.

Parameters
index:strMetadata key to append.
value:strMetadata value to append.
@overload
def get_one(self, index: str, default: str, first: bool = False) -> str:
@overload
def get_one(self, index: str, default: None = None, first: bool = False) -> str | None:
(source)

Return the first or last value for a key.

Parameters
index:strMetadata key to search.
default:str | NoneValue returned when the key is missing.
first:boolWhen true return the first value instead of the last.
Returns
str | NoneThe selected value or default when absent.
def insert(self, index: int, value: tuple[str, str]): (source)

Insert a key/value pair at the given index.

Parameters
index:intPosition at which to insert the entry.
value:tuple[str, str](key, value) tuple to insert; key is lowercased.
_contents = (source)

Undocumented