|View source on GitHub|
Helper class to re-map PyYAML events to method calls.
google.appengine.api.yaml_listener.EventListener( event_handler )
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 produce iterable objects itself, but is instead a mapping to a given handler instance.
```python class PrintDocumentHandler(object): def DocumentStart(event): print "A new document has been started" EventListener(PrintDocumentHandler()).Parse(''' key1: value1 --- key2: value2 ''' ``` >>> A new document has been started A new document has been started ``` ```
In the example above, the implemented handler class (
has a single method that reports each time a new document is started within a
YAML file. It is not necessary to subclass the
EventListener, since only it
PrintDocumentHandler instance. Every time a new document begins,
PrintDocumentHandler.DocumentStart is called with the PyYAML event passed in
as its parameter.
The constructor initializes the PyYAML event listener and constructs internal mapping directly from event type to method on the actual handler. This prevents reflection being used during the actual parse time.
Event handler that will receive mapped events. Must
implement at least one appropriate handler method named from
the values of the
HandleEvent( event, loader=None )
Handles individual PyYAML event.
||Event to forward to method call in method call.|
Parse( stream, loader_class=yaml.loader.SafeLoader, **loader_args )
Calls YAML parser to generate and handle all events.
Calls PyYAML parser and sends resulting generator to
String document or open file object to process as per the
||Used for dependency injection.|
||Pass to the loader on construction.|