cardinal_pythonlib.datamapping
Original code copyright (C) 2009-2022 Rudolf Cardinal (rudolf@pobox.com).
This file is part of cardinal_pythonlib.
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Functions to help transform data.
- cardinal_pythonlib.datamapping.dict_to_map(d: Dict[Any, Any]) List[Tuple[List[Any], Any]] [source]
Converts a dictionary into a structure usable by
map_value()
.
- cardinal_pythonlib.datamapping.map_value(value: Any, maplist: Iterable[Tuple[Iterable[Any], Any]], transmit_none: bool = True, required: bool = True, default: Any | None = None, name: str | None = None) Any [source]
If the value is
None
andtransmit_none
is true, returnNone
.Map
value
to a result, viamapping
, which is a list of tuplespossibilities, result
. Work throughmaplist
in sequence, and ifvalue
is inpossibilities
, return result.If no result was found, then:
if
required
is False, returndefault
;otherwise, raise
ValueError
, usingname
to describe the problem.