bento_meta.entity

This module contains * Entity, the base class for metamodel objects, * the CollValue class to manage collection-valued attributes, and * the ArgError exception.

Exceptions

ArgError

Exception for method argument errors.

Classes

Entity

Base class for all metamodel objects.

CollValue

A UserDict for housing Entity collection attributes.

Module Contents

exception bento_meta.entity.ArgError[source]

Bases: Exception

Exception for method argument errors.

class bento_meta.entity.Entity(init: dict | neo4j.graph.Node | Entity | None = None)[source]

Base class for all metamodel objects.

Entity contains all the magic for metamodel objects such as bento_meta.objects.Node and ‘bento_meta.object.Edge`. It will rarely be used directly. Entity redefines __setattr__ and __getattr__ to enable graph database object mapping under the hood.

The Entity class also defines private and declared attributes that are common to all metamodel objects. It provides the machinery to manage private attributes separately from declared attributes, and to raise exceptions when attempts are made to access attributes that are not declared.

pvt_attr: ClassVar[list[str]] = ['pvt', 'neoid', 'dirty', 'removed_entities', 'attspec', 'mapspec', 'belongs']
defaults
attspec_: ClassVar[dict[str, str]]
attspec
mapspec_: ClassVar[dict[str, str | dict[str, str] | dict[str, dict[str, str | set[str]]] | None]]
property object_map: bento_meta.object_map.ObjectMap | None

Return object map.

pvt
neoid = None
property dirty: int

Flag whether this instance has been changed since retrieval from the database.

Set to -1, ensure that the next time an attribute is accessed, the instance will retrieve itself from the database.

property removed_entities: list[Any]

Return list of removed entities.

property belongs: dict[tuple[int, str, str] | tuple[int, str], Entity]

Return dict that stores information on the owners (referents) of this instance in the model.

classmethod mapspec() dict[str, str | dict[str, str]][source]

Get object to database mapping specification.

Is a class method, not a property.

classmethod default(propname: str) Any[source]

Return a default value for the property named.

Parameters:

propname – Name of the property to get default for.

Returns:

Default value if defined, None otherwise.

get_by_id(id: str) Entity | None[source]

Get an object from the db with the id attribute (not the Neo4j id).

Parameters:

id – Value of id for desired object.

Returns:

A new object if found, None otherwise.

clear_removed_entities() None[source]

Clear the list of removed entities.

set_with_dict(init: dict) None[source]

Set the entity with a dict.

set_with_node(init: neo4j.graph.Node) None[source]

Set the entity with a Neo4j node.

set_with_entity(ent: Entity) Entity[source]

Set the entity with another entity.

__getattribute__(name: str) Any[source]

Get the attribute of the entity.

__getattr__(name: str) Any[source]

Get the attribute of the entity.

__setattr__(name: str, value: Any) None[source]

Set the attribute of the entity.

_set_declared_attr(name: str, value: Any) None[source]

Set the declared attribute of the entity.

__delattr__(name: str) None[source]

Delete the attribute of the entity.

_check_init(init: dict) None[source]

Check the initial value of the entity.

_check_value(att: str, value: Any) None[source]

Check the value of the attribute.

dup() Entity[source]

Duplicate the object, but not too deeply.

delete() None[source]

Delete self from the database.

dget(*, refresh: bool = False) Entity | None[source]

Update self from the database.

Parameters:

refresh – If True, force a retrieval from db. If False, retrieve from cache and don’t disrupt changes already made.

Returns:

The entity if found, None otherwise.

dput() None[source]

Put self to the database.

This will set the neoid property if not yet set.

rm(*, force: bool = False) None[source]

Delete self from the database.

The object instance survives.

Parameters:

force – If True, detach and delete the node.

classmethod attr_doc() str[source]

Create a docstring for declared attributes on class as configured.

get_label() str | dict[str, str] | dict[str, dict[str, str | set[str]]] | None[source]

Return type of entity as label.

get_attr_dict() dict[str, str][source]

Return simple attributes set for Entity as a dict.

Attr values are converted to strings. Doesn’t include attrs with None values.

Returns:

Dictionary of attribute names to string values.

class bento_meta.entity.CollValue(init: dict | None = None, *, owner: Entity, owner_key: str)[source]

Bases: collections.UserDict

A UserDict for housing Entity collection attributes.

This class contains a hook for recording the Entity that owns the value that is being set. The value is marked as belonging to the containing object, not this collection object. It also protects against adding arbitrarily typed elements to the collection; it throws unless a value to set is an Entity.

owner

Entity object of which this collection is an attribute.

owner_key

The attribute name of this collection on the owner.

property owner: Entity

The entity instance of which this collection is an attribute.

property owner_key: str

The attribute name of this collection on the owner.

__setitem__(name: str, value: Entity) None[source]

Set the value for the collection.

__getitem__(name: str) Any[source]

Get the value for the collection.

__delitem__(name: str) None[source]

Delete the value for the collection.