Python 2.7 has reached end of support
and will be
deprecated
on January 31, 2026. After deprecation, you won't be able to deploy Python 2.7
applications, even if your organization previously used an organization policy to
re-enable deployments of legacy runtimes. Your existing Python
2.7 applications will continue to run and receive traffic after their
deprecation date. We recommend that
you
migrate to the latest supported version of Python.
Stay organized with collections
Save and categorize content based on your preferences.
google.appengine.api.yaml_listener module
Summary
PyYAML event listener
Contains class which interprets YAML events and forwards them to
a handler object.
Contents
- 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 mapping 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”
- EventListener(PrintDocumentHandler()).Parse(‘’‘
-
key1: value1
—
key2: value2
‘’‘
>>> A new document has been started
A new document has been startedIn 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.
Parametersevent – Event to forward to method call in method call.
RaisesIllegalEvent when receives an unrecognized or unsupported event type.
- Parse(stream, loader_class=google.appengine._internal.ruamel.yaml.loader.SafeLoader, **loader_args)source
Call YAML parser to generate and handle all events.
Calls PyYAML parser and sends resulting generator to handle_event method
for processing.
Parameters
-
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.
-
**loader_args – Pass to the loader on construction.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-06-16 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-06-16 UTC."],[[["\u003cp\u003eThe \u003ccode\u003egoogle.appengine.api.yaml_listener\u003c/code\u003e module provides tools for interpreting YAML events and directing them to a designated handler.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eEventHandler\u003c/code\u003e is an interface class that users implement to define custom behavior for handling various YAML events, such as document start/end, mapping, scalar, sequence, and stream events.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eEventListener\u003c/code\u003e is a helper class that takes a user-defined \u003ccode\u003eEventHandler\u003c/code\u003e instance and maps PyYAML events to method calls on that instance.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eEventListener\u003c/code\u003e's \u003ccode\u003eParse\u003c/code\u003e method processes a YAML document stream, using a specified loader class, and calls the appropriate handler methods based on the YAML events encountered.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eHandleEvent\u003c/code\u003e method within the EventListener class processes and redirects individual PyYAML events to the corresponding method calls within a user-provided handler, it will raise an error if the event is not recognized.\u003c/p\u003e\n"]]],[],null,["# google.appengine.api.yaml_listener module\n=========================================\n\nSummary\n-------\n\nPyYAML event listener\n\nContains class which interprets YAML events and forwards them to\na handler object.\n\nContents\n--------\n\n*class* google.appengine.api.yaml_listener.EventHandler[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_listener#EventHandler)\n\n: Bases: object\n\n Handler interface for parsing YAML files.\n\n Implement this interface to define specific YAML event handling class.\n Implementing classes instances are passed to the constructor of\n EventListener to act as a receiver of YAML parse events. \n\n Alias(event, loader)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_listener#EventHandler.Alias)\n\n : Handle alias event\n\n DocumentEnd(event, loader)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_listener#EventHandler.DocumentEnd)\n\n : Handle end of document event\n\n DocumentStart(event, loader)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_listener#EventHandler.DocumentStart)\n\n : Handle start of document event\n\n MappingEnd(event, loader)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_listener#EventHandler.MappingEnd)\n\n : Handle end of mapping event\n\n MappingStart(event, loader)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_listener#EventHandler.MappingStart)\n\n : Handle start of mapping event\n\n Scalar(event, loader)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_listener#EventHandler.Scalar)\n\n : Handle scalar event\n\n SequenceEnd(event, loader)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_listener#EventHandler.SequenceEnd)\n\n : Handle end of sequence event\n\n SequenceStart(event, loader)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_listener#EventHandler.SequenceStart)\n\n : Handle start of sequence event\n\n StreamEnd(event, loader)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_listener#EventHandler.StreamEnd)\n\n : Handle end of stream event\n\n StreamStart(event, loader)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_listener#EventHandler.StreamStart)\n\n : Handle start of stream event\n\n*class* google.appengine.api.yaml_listener.EventListener(event_handler)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_listener#EventListener)\n\n: Bases: object\n\n Helper class to re-map PyYAML events to method calls.\n\n By default, PyYAML generates its events via a Python generator. This class\n is a helper that iterates over the events from the PyYAML parser and forwards\n them to a handle class in the form of method calls. For simplicity, the\n underlying event is forwarded to the handler as a parameter to the call.\n\n This object does not itself produce iterable objects, but is really a mapping\n to a given handler instance.\n\n Example use:\n\n class PrintDocumentHandler(object):\n :\n\n def DocumentStart(event):\n\n : print \"A new document has been started\"\n\n\n EventListener(PrintDocumentHandler()).Parse('''\n\n : key1: value1\n ---\n key2: value2\n '''\n\n \\\u003e\\\u003e\\\u003e A new document has been started A new document has been started\n\n In the example above, the implemented handler class (PrintDocumentHandler)\n has a single method which reports each time a new document is started within\n a YAML file. It is not necessary to subclass the EventListener, merely it\n receives a PrintDocumentHandler instance. Every time a new document begins,\n PrintDocumentHandler.DocumentStart is called with the PyYAML event passed\n in as its parameter.. \n\n HandleEvent(event, loader=None)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_listener#EventListener.HandleEvent)\n\n : Handle individual PyYAML event.\n\n Parameters\n\n event -- Event to forward to method call in method call.\n Raises\n\n IllegalEvent when receives an unrecognized or unsupported event type. \n\n Parse(stream, loader_class=google.appengine._internal.ruamel.yaml.loader.SafeLoader, \\*\\*loader_args)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_listener#EventListener.Parse)\n\n : Call YAML parser to generate and handle all events.\n\n Calls PyYAML parser and sends resulting generator to handle_event method\n for processing.\n Parameters\n\n - stream -- String document or open file object to process as per the\n yaml.parse method. Any object that implements a 'read()' method which\n returns a string document will work with the YAML parser.\n\n - loader_class -- Used for dependency injection.\n\n - \\*\\*loader_args -- Pass to the loader on construction."]]