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]¶
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 ifforce
is …datetime.date
,datetime.datetime
: Parse the nested value as ISO 8601. On failure, returnNone
.dict
,list
: Return an emptydict
orlist
, respectively.float
,int
,str
: Cast the nested value to that type. On failure, returnNone
.
If the nested value is not set, if
force
is provided, andforce
isdict
,list
orstr
, return an emptydict
,list
orstr
, 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