here.content.base module#

Support classes common to all the bindings.

class here.content.base.CompositeBinding(content: Content, adapter: Adapter | None = None)[source]#

Bases: _ContentBindingImpl, ABC

The base class for all the bindings based on other, multiple bindings.

class here.content.base.ContentBinding(content: Content, adapter: Adapter | None = None)[source]#

Bases: ContentBinding, ABC

The entry point for developers.

This is the base class for all the bindings: this class represents the main developer-facing API to obtain data form bindings and is common across all the bindings.

Bindings exposes objects.

Features are objects indexed by their partition and identifier. Identifiers cannot be duplicate in the same partition.

Attributes are objects indexed by the feature they apply to.

abstract get(partition: str | int | Iterable[str | int], object_type: str, identifier: str | None = None)[source]#

Get a selected or all the objects of a specific type from the content.

Parameters:
  • partition – the partition(s) where the objects are stored

  • object_type – the type of the objects

  • identifier – the identifier of the object, in case of looking up one specific object

Returns:

one or all the objects of the requested type contained in the requested partition(s), format is adapter-dependent

Raises:
  • ValueError – if the requested object type is not supported

  • KeyError – if a specific object is requested but it cannot be found

get_ref(object_type: str, ref: Ref)[source]#

Get a selected object of a specific type from the content via a direct reference to it.

Parameters:
  • object_type – the type of the objects

  • ref – reference to a partition and object

Returns:

the object of the requested type referenced by ref, that in turn specifies partition and object identifier, format is adapter-dependent

Raises:
  • ValueError – if the requested object type is not supported # noqa: DAR402

  • KeyError – if the requested object cannot be found # noqa: DAR402

abstract get_referencing(partition: str | int | Iterable[str | int], object_type: str, ref_type: str, referenced_obj: Ref | None = None)[source]#

Get objects of a specific type that reference other objects of the content.

Parameters:
  • partition – the partition(s) where the objects are stored

  • object_type – the type of the objects

  • ref_type – the type of the reference, among the ones supported by the object type

  • referenced_obj – return only object referencing this specific partition and object

Returns:

objects containing the requested reference, format is adapter-dependent

Raises:

ValueError – if the requested object or reference type is not supported

abstract classmethod object_types() Mapping[str, type][source]#
Returns:

the name and types of objects supported by this binding

classmethod ref_types() Mapping[str, List[str]][source]#
Returns:

the reference types supported by each object type of this binding

abstract classmethod schema_hrn() List[str][source]#
Returns:

the HRN of schemas this binding can parse and index

class here.content.base.ContentIndexer(partition: None | str | ~typing.Callable[[object], ~here.platform.adapter.Partition] = None, identifier: None | str | ~typing.Callable[[object], ~here.platform.adapter.Identifier] = None, refs: ~typing.Mapping[str, str | ~typing.Callable[[object], ~here.platform.adapter.Ref | ~typing.List[~here.platform.adapter.Ref]]] = <factory>)[source]#

Bases: object

Used to inspect and index content objects.

Each field describes how to extract index entries from an object. Each content class must have one indexer of this type, as static parameter.

  • None: not indexable

  • str: get the value from a dataclass field with the corresponding name

  • Callable: get the value through a function, passing the object as parameter

refs is a mapping because more than one reference type can be defined per class.

identifier: None | str | Callable[[object], Identifier] = None#
partition: None | str | Callable[[object], Partition] = None#
refs: Mapping[str, str | Callable[[object], Ref | List[Ref]]]#
class here.content.base.ContentPartition(binding_cls: Type[ContentBinding], **objects: Iterable[object])[source]#

Bases: object

Class to store, index and lookup objects from a parsed partition.

index(obj_type: str) Mapping[str, object][source]#

Index all the objects contained in the content partition by their identifier. This con be considered a primary index of the content.

Parameters:

obj_type – type of the object to index

Returns:

a collection of objects, indexed by their identifier

Raises:

ValueError – in case of unsupported object type

objects(obj_type: str) Iterable[object][source]#

List all the objects contained in the content partition. Objects are returned in no special order and without duplicates.

Parameters:

obj_type – type of the object to list

Returns:

a collection of objects

Raises:

ValueError – in case of unsupported object type

ref_index(obj_type: str, ref_type: str) Mapping[Ref, Iterable[object]][source]#

Index all the objects contained in the content partition by their references to other objects, in the same partition or in another partition. This con be considered a secondary index of the content.

Parameters:
  • obj_type – type of the object to index

  • ref_type – type of the reference to index

Returns:

a collection of objects, indexed by their external references

Raises:

ValueError – in case of unsupported object or reference type

class here.content.base.MultiLayerBinding(content: Content, adapter: Adapter | None = None)[source]#

Bases: _ContentBindingImpl, ABC

The base class for all the bindings based on multiple layers.

class here.content.base.SingleLayerBinding(content: Content, layer_id: str, adapter: Adapter | None = None, layer_type: LayerType | None = None)[source]#

Bases: _ContentBindingImpl, ABC

The base class for all the bindings based on one single layer.

get_partition(partition_id: str | int) ContentPartition | None[source]#

Main method for the implementation of the binding. Get, decode, parse and index content of a partition. Return None if no content is available for the partition.

The result is cached.

Parameters:

partition_id – identifier of the partition

Returns:

content of the partition parsed and indexed

abstract classmethod parse_and_index(partition_id: str, msg: Message) ContentPartition[source]#

Parse and index decoded message from the single layer into whatever form is comfortable for the bindings. The resulting, parsed content is cached.

This is used by get_partition to parse and index content retrieved and decoded from the layer, before caching it and returning it to the implementation of the binding.

It is responsibility of the binding to implement the parser.

Parameters:
  • partition_id – identifier of the partition

  • msg – decoded content from the layer, in the form of a Protobuf message

Returns:

the content of a partition parsed and indexed in its own data structure