everest.representers.base

Representer base classes.

class everest.representers.base.Representer[source]

Bases: object

Base class for all representers.

A representer knows how to convert an object into a representation of a particular MIME type (content type) and vice versa.

__weakref__

list of weak references to the object (if defined)

class everest.representers.base.RepresenterRegistry[source]

Bases: object

Registry for representer classes and representer factories.

__weakref__

list of weak references to the object (if defined)

create(resource, content_type)[source]

Creates a representer for the given combination of resource and content type. This will also find representer factories that were registered for a base class of the given resource.

register(resource_class, content_type, configuration=None)[source]

Registers a representer factory for the given combination of resource class and content type.

Parameters:configuration (everest.representers.config.RepresenterConfiguration) – representer configuration. A default instance will be created if this is not given.
class everest.representers.base.ResourceRepresenter(resource_class, mapping)[source]

Bases: everest.representers.base.Representer

Base class for resource representers which know how to convert resource representations into resources and back.

This conversion is performed using four customizable, independent helper objects:

  1. The representation parser responsible for converting the representation into a data element tree;
  2. The data element parser responsible for converting a data element tree into a resource;
  3. The data element generator responsible for converting a resource into a data element tree; and
  4. the representation generator responsible for converting the data element tree into a representation.
configure(options=None, attribute_options=None)[source]

Configures the attribute mapping for this representer.

Parameters:
  • options (dict) – configuration options for the mapping associated with this representer.
  • attribute_options (dict) – attribute options for the mapping associated with this representer.
data_from_representation(representation)[source]

Creates a data element from the given representation.

Returns:object implementing everest.representers.interfaces.IExplicitDataElement
data_from_resource(resource)[source]

Extracts managed attributes from a resource and constructs a data element for serialization from it.

Default representer behavior:
  • Top-level member and collections resource attributes are represented as links.
  • Nested member resource attributes are represented as links, nested collection resource attributes are ignored (building a link may require iterating over the collection).

The default behavior can be configured with the “representer” directive (everest.configuration.representer()) by means of the “write_as_link” and “ignore” options of representer configuration objects (everest.representers.config.RepresenterConfiguration).

data_from_stream(stream)[source]

Creates a data element reading a representation from the given stream.

Returns:object implementing everest.representers.interfaces.IExplicitDataElement
representation_from_data(data_element)[source]

Creates a representation from the given data element.

Parameters:data_element
resource_from_data(data_element, resolve_urls=True)[source]

Extracts serialized data from the given data element and constructs a resource from it.

Parameters:resolve_urls – If this is set to False, resolving URLs in the data element tree will be delayed until after loading has completed.
Returns:object implementing everest.resources.interfaces.IResource
everest.representers.base.data_element_tree_to_string(data_element)[source]

Creates a string representation of the given data element tree.

Project Versions

Previous topic

everest.representers.attributes

Next topic

everest.representers.config

This Page