google.appengine.api.yaml_object module

Summary

Builder for mapping YAML documents to object instances.

ObjectBuilder is responsible for mapping a YAML document to classes defined using the validation mechanism (see google.appengine.api.validation.py).

Contents

google.appengine.api.yaml_object.BuildObjects(default_class, stream, loader=google.appengine._internal.ruamel.yaml.loader.SafeLoader)source

Build objects from stream.

Handles the basic case of loading all the objects from a stream.

Parameters
  • default_class – Class that is instantiated upon the detection of a new document. An instance of this class will act as the document itself.

  • stream – String document or open file object to process as per the yaml.parse method. Any object that implements a ‘read()’ method which returns a string document will work with the YAML parser.

  • loader_class – Used for dependency injection.

Returns

List of default_class instances parsed from the stream.

google.appengine.api.yaml_object.BuildSingleObject(default_class, stream, loader=google.appengine._internal.ruamel.yaml.loader.SafeLoader)source

Build object from stream.

Handles the basic case of loading a single object from a stream.

Parameters
  • default_class – Class that is instantiated upon the detection of a new document. An instance of this class will act as the document itself.

  • stream – String document or open file object to process as per the yaml.parse method. Any object that implements a ‘read()’ method which returns a string document will work with the YAML parser.

  • loader_class – Used for dependency injection.

class google.appengine.api.yaml_object.ObjectBuilder(default_class)source

Bases: google.appengine.api.yaml_builder.Builder

Builder used for constructing validated objects.

Given a class that implements validation.ValidatedBase, it will parse a YAML document and attempt to build an instance of the class. ObjectBuilder will only map YAML fields that are accepted by the ValidatedBase’s GetValidator function. Lists are mapped to validated. Repeated attributes and maps are mapped to validated.Type properties.

For a YAML map to be compatible with a class, the class must have a constructor that can be called with no parameters. If the provided type does not have such a constructor a parse time error will occur.

AppendTo(subject, value)source

Append a value to a sequence.

Parameters
  • subject – _ObjectSequence that is receiving new value.

  • value – Value that is being appended to sequence.

BuildDocument()source

Instantiate new root validated object.

Returns

New instance of validated object.

BuildMapping(top_value)source

New instance of object mapper for opening map scope.

Parameters

top_value – Parent of nested object.

Returns

New instance of object mapper.

BuildSequence(top_value)source

New instance of object sequence.

Parameters

top_value – Object that contains the new sequence.

Returns

A new _ObjectSequencer instance.

EndMapping(top_value, mapping)source

When leaving scope, makes sure new object is initialized.

This method is mainly for picking up on any missing required attributes.

Parameters
  • top_value – Parent of closing mapping object.

  • mapping – _ObjectMapper instance that is leaving scope.

MapTo(subject, key, value)source

Map key-value pair to an objects attribute.

Parameters
  • subject – _ObjectMapper of object that will receive new attribute.

  • key – Key of attribute.

  • value – Value of new attribute.

Raises
  • UnexpectedAttribute when the key is not a validated attribute of

  • the subject value class.