Getter

pelican.util.getter.get_amount(no_conversion, amount, currency, date)[source]
pelican.util.getter.parse_datetime(string)[source]

Parse a string to a datetime.

Parameters:

string (str | None) – the value to parse

Return type:

datetime | None

pelican.util.getter.parse_date(string)[source]

Parse a string to a date.

Parameters:

string (str | None) – the value to parse

Return type:

date | None

pelican.util.getter.deep_has(value, path)[source]

Returns whether a nested value exists in nested dicts, safely.

Use this instead of deep_get() to check for the presence of a key. For example, deep_get({"id": 0}, "id") is falsy.

Parameters:
  • value (Any) – the value to index into

  • path (str) – a period-separated list of keys

Return type:

bool

pelican.util.getter.deep_get(value, path, force=None)[source]

Gets a nested value from nested dicts, safely. If force is provided and the nested value is not of that type, then if force is …

  • datetime.date, datetime.datetime: Parse the nested value as ISO 8601. On failure, return None.

  • dict, list: Return an empty dict or list, respectively.

  • float, int, str: Cast the nested value to that type. On failure, return None.

If the nested value is not set, if force is provided, and force is dict, list or str, return an empty dict, list or str, respectively. Otherwise, if the nested value is not set, return None.

Parameters:
  • value (Any) – the value to index into

  • path (str) – a period-separated list of keys

  • force (type[Any] | None) – the type to which to coerce the nested value, if possible

Return type:

Any

pelican.util.getter.get_values(item, str_path, value_only=False)[source]
Parameters:
  • item (Any)

  • str_path (str)

  • value_only (bool | None)

Return type:

list[Any]