google.appengine.api.yaml_listener module


PyYAML event listener

Contains class which interprets YAML events and forwards them to a handler object.


class google.appengine.api.yaml_listener.EventHandlersource

Bases: object

Handler interface for parsing YAML files.

Implement this interface to define specific YAML event handling class. Implementing classes instances are passed to the constructor of EventListener to act as a receiver of YAML parse events.

Alias(event, loader)source

Handle alias event

DocumentEnd(event, loader)source

Handle end of document event

DocumentStart(event, loader)source

Handle start of document event

MappingEnd(event, loader)source

Handle end of mapping event

MappingStart(event, loader)source

Handle start of mappping event

Scalar(event, loader)source

Handle scalar event

SequenceEnd(event, loader)source

Handle end of sequence event

SequenceStart(event, loader)source

Handle start of sequence event

StreamEnd(event, loader)source

Handle end of stream event

StreamStart(event, loader)source

Handle start of stream event

class google.appengine.api.yaml_listener.EventListener(event_handler)source

Bases: object

Helper class to re-map PyYAML events to method calls.

By default, PyYAML generates its events via a Python generator. This class is a helper that iterates over the events from the PyYAML parser and forwards them to a handle class in the form of method calls. For simplicity, the underlying event is forwarded to the handler as a parameter to the call.

This object does not itself produce iterable objects, but is really a mapping to a given handler instance.

Example use:

class PrintDocumentHandler(object):
def DocumentStart(event):

print "A new document has been started"


key1: value1 --- key2: value2 '''

>>> A new document has been started A new document has been started

In the example above, the implemented handler class (PrintDocumentHandler) has a single method which reports each time a new document is started within a YAML file. It is not necessary to subclass the EventListener, merely it receives a PrintDocumentHandler instance. Every time a new document begins, PrintDocumentHandler.DocumentStart is called with the PyYAML event passed in as its parameter..

HandleEvent(event, loader=None)source

Handle individual PyYAML event.


event -- Event to forward to method call in method call.


IllegalEvent when receives an unrecognized or unsupported event type.

Parse(stream, loader_class=yaml.loader.SafeLoader)source

Call YAML parser to generate and handle all events.

Calls PyYAML parser and sends resulting generator to handle_event method for processing.

  • 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.

Send feedback about...

App Engine standard environment for Python