grapa.internal.container_metadata.MetadataContainer
- class grapa.internal.container_metadata.MetadataContainer(host_curve_or_graph: Graph | Curve)
Bases:
objectContainer for handling metadata as pairs key-values. It behaves similarly to a dict. Main differences:
key are str, lower case internally, case insensitive from the outside (historical)
update({key: VALUE_DEFAULT}) (value “”) does remove the key-value pair
it is callable (historical reason): obj(key) is equivalent to obj.get(key)
Note: uses the grapa recorder to undo/redo actions. Suggestion to grapa users: it may be advantageous to stick to the methods defined in classes Curve and Graph, which behave consistently: attr(key), update({key: value}), has_attr(key), get_attributes(), attr_pop(key)) It avoids the technicality that Graph constains 2 MetadataContainer objects.
Methods
__init__(host_curve_or_graph)clear()Remove all items from the container
format(key)Formats the key.
get(key[, default])Returns the value associated with key.
has_attr(key)Returns if a key has been defined.
is_attr_value_default(value)Test if value corresponds to default value.
items()to iterate over items
pop(key)Removes an existing key-value pair.
update(attributes)Updates attributes.
values([keys_list])Returns a copied dict of all attributes key-values.
Attributes
VALUE_DEFAULT- clear()
Remove all items from the container
- static format(key: str) str
Formats the key. key must be a str
- get(key: str, default='')
Returns the value associated with key. If key not found, returns VALUE_DEFAULT (i.e. not KeyError)
- Parameters:
key – a str
default – default return value.
- Returns:
The value associated with key.
- has_attr(key: str) bool
Returns if a key has been defined.
- Parameters:
key – the key of interest
- Returns:
True if key is defined and not default, False otherwise
- classmethod is_attr_value_default(value) bool
Test if value corresponds to default value.
- Parameters:
value – a value
- Returns:
True if val is default value (e.g. not defined), False otherwise
- items()
to iterate over items
- pop(key: str)
Removes an existing key-value pair. Returns the earlier value, or default if not specified. Does not raise KeyError.
- update(attributes: dict) None
Updates attributes. Some clean-up is performed e.g. key as lower case and strip of characters ` =:\t\r\n`.
- Parameters:
attributes – a dict, key-value
- values(keys_list: list | None = None)
Returns a copied dict of all attributes key-values.
- Parameters:
keys_list – is provided, the returned dict contains only these keys.