gws.core.tree_impl

Internal implementations of gws.Node and gws.Root methods.

Source code: gws.core.tree_impl

Module Contents

gws.core.tree_impl.Access = None
gws.core.tree_impl.activate_root(root)

Implement gws.activate_root.

Parameters:

root – The root.

Returns:

The root.

gws.core.tree_impl.alloc_node(self, classref, typ=None)

Create an uninitialized node of the class found in the specs.

Parameters:
  • self – The root.

  • classref – Class reference.

  • typ – Extension type, for ext class references.

Returns:

The new node, with root, extName and extType set.

Raises:

Error – If the class is not found.

gws.core.tree_impl.class_name(node)

Return the full class name of an object.

Parameters:

node – An object.

Returns:

The module and class name, like gws.base.layer.core.Object.

gws.core.tree_impl.config_info(self, message)

Create a configuration error or warning record.

Parameters:
  • self – The root.

  • message – The message.

Returns:

A Data object with message and stack, a list of locations from the innermost node outwards.

gws.core.tree_impl.config_location_repr(loc)

Return a short representation of a configuration location.

Parameters:

loc – A location from config_info.

Returns:

A string with the object type, name, uid and the property name.

gws.core.tree_impl.configure_permissions(self)

Compute the permissions of a node from its access and permissions config.

access sets the read permission. In permissions, all sets all modes, edit sets write, create and delete, and the specific modes override both.

Parameters:

self – The node.

Returns:

A mapping from an access mode to an ACL.

gws.core.tree_impl.create_node(self, classref, parent, config, temp=False)

Create and initialize a node.

Parameters:
  • self – The root.

  • classref – Class reference.

  • parent – Parent node, the new node is appended to its children.

  • config – Configuration. Its type selects the extension type.

  • temp – If True, the node is not registered in the root.

Returns:

The new node, or None if the initialization failed.

gws.core.tree_impl.Data = None
gws.core.tree_impl.deactivate_root()

Implement gws.deactivate_root.

gws.core.tree_impl.Error = None
gws.core.tree_impl.find_all_in(root, nodes, classref)

Filter nodes by a class reference.

Parameters:
  • root – The root.

  • nodes – A list of nodes.

  • classref – Class reference. If None, all nodes match.

Returns:

A list of matching nodes.

gws.core.tree_impl.find_first_in(root, nodes, classref)

Find the first node that matches a class reference.

Parameters:
  • root – The root.

  • nodes – A list of nodes.

  • classref – Class reference. If None, all nodes match.

Returns:

The first matching node or None.

gws.core.tree_impl.get_or_generate_uid(self, config)

Return the uid from the config, or generate a new numeric one.

Parameters:
  • self – The root.

  • config – Configuration.

Returns:

A uid.

gws.core.tree_impl.get_root()

Implement gws.get_root.

Returns:

The root.

gws.core.tree_impl.is_a(root, node, classref)

Check if a node matches a class reference.

A class matches by isinstance, a class name matches exactly, an ext name matches the node’s extension name or its prefix.

Parameters:
  • root – The root.

  • node – The node.

  • classref – Class reference.

Returns:

True if the node matches.

gws.core.tree_impl.load_root(path=None)

Implement gws.load_root.

Parameters:

path – File path.

Returns:

The root.

gws.core.tree_impl.make_props2(obj, user)

Recursively convert a value to props for a user.

Objects are converted with their props method, or dropped if the user has no read permission. None values are removed from dicts and lists.

Parameters:
  • obj – An object, Data, dict, list or a scalar value.

  • user – The user.

Returns:

A scalar, dict or list, or None.

gws.core.tree_impl.node_cfg(self, key: str, default=None)

Implement gws.Node.cfg.

Parameters:
  • self – The node.

  • key – Property key, nested keys are separated by dots.

  • default – Value to return if the property is None or missing.

Returns:

The property value or the default.

gws.core.tree_impl.node_create_child(self, classref, config, **kwargs)

Implement gws.Node.create_child.

Parameters:
  • self – The parent node.

  • classref – Class reference.

  • config – Configuration.

  • **kwargs – Additional configuration properties.

Returns:

A newly created node or None.

gws.core.tree_impl.node_create_child_if_configured(self, classref, config=None, **kwargs)

Implement gws.Node.create_child_if_configured.

Parameters:
  • self – The parent node.

  • classref – Class reference.

  • config – Configuration.

  • **kwargs – Additional configuration properties.

Returns:

A newly created node or None.

gws.core.tree_impl.node_create_children(self, classref, configs, **kwargs)

Implement gws.Node.create_children.

Parameters:
  • self – The parent node.

  • classref – Class reference.

  • configs – List of configurations.

  • **kwargs – Additional configuration properties.

Returns:

A list of newly created nodes, without the ones that failed.

gws.core.tree_impl.node_find_all(self, classref)

Implement gws.Node.find_all.

Parameters:
  • self – The node.

  • classref – Class reference. If None, all nodes match.

Returns:

A list of matching children.

gws.core.tree_impl.node_find_ancestors(self, classref)

Implement gws.Node.find_ancestors.

Parameters:
  • self – The node.

  • classref – Class reference. If None, all nodes match.

Returns:

A list of matching ancestors below the root, from the parent upwards.

gws.core.tree_impl.node_find_closest(self, classref)

Implement gws.Node.find_closest.

Parameters:
  • self – The node.

  • classref – Class reference. If None, all nodes match.

Returns:

The closest matching ancestor below the root, or None.

gws.core.tree_impl.node_find_descendants(self, classref)

Implement gws.Node.find_descendants.

Parameters:
  • self – The node.

  • classref – Class reference. If None, all nodes match.

Returns:

A list of matching descendants in the depth-first order.

gws.core.tree_impl.node_find_first(self, classref)

Implement gws.Node.find_first.

Parameters:
  • self – The node.

  • classref – Class reference. If None, all nodes match.

Returns:

The first matching child or None.

gws.core.tree_impl.node_initialize(self, config)

Implement gws.Node.initialize.

Parameters:
  • self – The node.

  • config – Configuration.

gws.core.tree_impl.Object = None
gws.core.tree_impl.object_repr(self)

Return a short representation of an object.

Parameters:

self – The object.

Returns:

A string with the class or extension name, title, uid and the object id.

gws.core.tree_impl.Props = None
gws.core.tree_impl.props_of(node, user, *context)

Implement gws.props_of.

Parameters:
  • node – The object.

  • user – The user.

  • *context – Context objects for the permission check.

Returns:

A Props object or None.

Raises:

Error – If the object’s props returns an invalid type.

gws.core.tree_impl.register_config_error(self, exc)

Record an exception in configErrors, with the current config stack.

Parameters:
  • self – The root.

  • exc – The exception.

gws.core.tree_impl.root_activate(self)

Implement gws.Root.activate.

Parameters:

self – The root.

gws.core.tree_impl.root_config_warning(self, message)

Implement gws.Root.config_warning.

Parameters:
  • self – The root.

  • message – Warning message.

gws.core.tree_impl.root_create(self, classref, parent, config, **kwargs)

Implement gws.Root.create.

Parameters:
  • self – The root.

  • classref – Class reference.

  • parent – Parent node.

  • config – Configuration.

  • **kwargs – Additional configuration properties.

Returns:

A newly created node or None.

gws.core.tree_impl.root_create_application(self, config, **kwargs)

Implement gws.Root.create_application.

The application gets the fixed uid const.APPLICATION_UID.

Parameters:
  • self – The root.

  • config – Configuration.

  • **kwargs – Additional configuration properties.

Returns:

The Application object.

gws.core.tree_impl.root_create_shared(self, classref, config, **kwargs)

Implement gws.Root.create_shared.

Parameters:
  • self – The root.

  • classref – Class reference.

  • config – Configuration.

  • **kwargs – Additional configuration properties.

Returns:

An existing node with the same uid, a newly created node, or None.

gws.core.tree_impl.root_create_temporary(self, classref, config, **kwargs)

Implement gws.Root.create_temporary.

The node is not registered in the root and post_configure is run immediately.

Parameters:
  • self – The root.

  • classref – Class reference.

  • config – Configuration.

  • **kwargs – Additional configuration properties.

Returns:

A newly created node or None.

gws.core.tree_impl.root_find_all(self, classref)

Implement gws.Root.find_all.

Parameters:
  • self – The root.

  • classref – Class reference. If None, all nodes match.

Returns:

A list of matching nodes.

gws.core.tree_impl.root_find_first(self, classref)

Implement gws.Root.find_first.

Parameters:
  • self – The root.

  • classref – Class reference. If None, all nodes match.

Returns:

The first matching node or None.

gws.core.tree_impl.root_get(self, uid, classref)

Implement gws.Root.get.

Parameters:
  • self – The root.

  • uid – Node uid.

  • classref – Class reference. If given, the node must match it.

Returns:

The node or None.

gws.core.tree_impl.root_init(self, specs)

Implement gws.Root.__init__.

Parameters:
  • self – The root.

  • specs – Specs runtime.

gws.core.tree_impl.root_initialize(self, node, config)

Implement gws.Root.initialize.

The node is pushed onto configStack while it is initialized. Exceptions are logged and recorded in configErrors.

Parameters:
  • self – The root.

  • node – The node.

  • config – Configuration.

Returns:

True if the node was initialized, False if it failed.

gws.core.tree_impl.root_object_count(self) → int

Implement gws.Root.object_count.

Parameters:

self – The root.

Returns:

The number of nodes.

gws.core.tree_impl.root_post_initialize(self)

Implement gws.Root.post_initialize.

Parameters:

self – The root.

gws.core.tree_impl.save_root(root, path=None)

Implement gws.save_root.

Parameters:
  • root – The root.

  • path – File path.

Returns:

The file path.

gws.core.tree_impl.super_invoke(node, method)

Invoke a method of every class in the node’s MRO that defines it, base classes first.

Parameters:
  • node – The node.

  • method – Method name.

gws.core.tree_impl.to_config(config, defaults)

Merge keyword defaults and a configuration into a new Data object.

Values in config override the defaults, None values are skipped.

Parameters:
  • config – Configuration.

  • defaults – Default values.

Returns:

A new Data object.