2 from copy
import deepcopy
8 def __init__(self, reference=None, input_keys=None, output_keys=None, remap=None):
10 self.
_reference = reference
if reference
is not None else dict()
20 for key, value
in self._hashes.items():
21 if value != hash(repr(self.
_data[key])):
22 raise UserDataError(
"Illegally modified input-only key '%s', declare it as output." % key)
30 return self._remap.get(key, key)
in self.
_reference 34 return self.
_data[key]
36 raise UserDataError(
"Key '%s' cannot be accessed, declare it as input key for read access." % key
38 "No data found for key '%s'" % key)
39 value = self.
_reference[self._remap.get(key, key)]
41 self.
_data[key] = value
42 self.
_hashes[key] = hash(repr(value))
43 if getattr(value.__class__,
"_has_header",
False):
47 value = deepcopy(value)
52 self.
_reference[self._remap.get(key, key)] = value
53 self.
_data[key] = value
56 if key.startswith(
'_'):
57 return object.__getattr__(self, key)
61 if key.startswith(
'_'):
62 return object.__setattr__(self, key, value)
64 raise UserDataError(
"Key '%s' cannot be set, declare it as output key for write access." % key)
67 def __call__(self, reference=None, add_from=None, update_from=None, remove_key=None):
69 if isinstance(add_from, UserData):
70 for key, value
in add_from._data.items():
71 if key
not in self.
_data:
72 self.
_data[key] = value
73 if isinstance(update_from, UserData):
74 for key, value
in update_from._data.items():
75 self.
_data[key] = value
76 if remove_key
is not None and remove_key
in self.
_data:
77 del self.
_data[remove_key]
84 data_str =
'\n '.join(str(self.
_reference).split(
'\n'))
87 return (
"UserData object with %d data entries:\n" 88 " Input Keys: %s\n Output Keys: %s\n Data: %s\n Remapping: %s\n Reference: %s" 90 str(self.
_remap), data_str))
def __call__(self, reference=None, add_from=None, update_from=None, remove_key=None)
def __getitem__(self, key)
def __contains__(self, key)
def __setattr__(self, key, value)
def __setitem__(self, key, value)
def __getattr__(self, key)
def __init__(self, reference=None, input_keys=None, output_keys=None, remap=None)