Getter¶
- 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]¶
Return 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]¶
Get a nested value from nested dicts, safely.
If
forceis provided and the nested value is not of that type, then ifforceis …datetime.date,datetime.datetime: Parse the nested value as ISO 8601. On failure, returnNone.dict,list: Return an emptydictorlist, respectively.float,int,str: Cast the nested value to that type. On failure, returnNone.
If the nested value is not set, if
forceis provided, andforceisdict,listorstr, return an emptydict,listorstr, respectively. Otherwise, if the nested value is not set, returnNone.- 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