namevalue Module

Key-value pairs.

class wpull.namevalue.NameValueRecord(normalize_overrides=None, encoding='utf-8', wrap_width=None)[source]

Bases: collections.abc.MutableMapping

An ordered mapping of name-value pairs.

Duplicated names are accepted.

add(name, value)[source]

Append the name-value pair to the record.

get_all()[source]

Return an iterator of name-value pairs.

get_list(name)[source]

Return all the values for given name.

parse(string, strict=True)[source]

Parse the string or bytes.

Parameters:strict (bool) – If True, errors will not be ignored
Raises:ValueError if the record is malformed.
to_bytes(errors='strict')[source]

Convert to bytes.

to_str()[source]

Convert to string.

wpull.namevalue.guess_line_ending(string)[source]

Return the most likely line delimiter from the string.

wpull.namevalue.normalize_name(name, overrides=None)[source]

Normalize the key name to title case.

For example, normalize_name('content-id') will become Content-Id

Parameters:
  • name (str) – The name to normalize.
  • overrides (set, sequence) – A set or sequence containing keys that should be cased to themselves. For example, passing set('WARC-Type') will normalize any key named “warc-type” to WARC-Type instead of the default Warc-Type.
Returns:

str

wpull.namevalue.unfold_lines(string)[source]

Join lines that are wrapped.

Any line that starts with a space or tab is joined to the previous line.