App Engine Python SDK  v1.6.9 rev.445
The Python runtime is available as an experimental Preview feature.
Public Member Functions | List of all members
google.appengine.api.yaml_listener.EventListener Class Reference
Inheritance diagram for google.appengine.api.yaml_listener.EventListener:

Public Member Functions

def __init__
 
def HandleEvent
 
def Parse
 

Detailed Description

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

Constructor & Destructor Documentation

def google.appengine.api.yaml_listener.EventListener.__init__ (   self,
  event_handler 
)
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 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..
Initialize PyYAML event listener.

Constructs internal mapping directly from event type to method on actual
handler.  This prevents reflection being used during actual parse time.

Args:
  event_handler: Event handler that will receive mapped events. Must
implement at least one appropriate handler method named from
the values of the _EVENT_METHOD_MAP.

Raises:
  ListenerConfigurationError if event_handler is not an EventHandler.

Member Function Documentation

def google.appengine.api.yaml_listener.EventListener.HandleEvent (   self,
  event,
  loader = None 
)
Handle individual PyYAML event.

Args:
  event: Event to forward to method call in method call.

Raises:
  IllegalEvent when receives an unrecognized or unsupported event type.
def google.appengine.api.yaml_listener.EventListener.Parse (   self,
  stream,
  loader_class = yaml.loader.SafeLoader 
)
Call YAML parser to generate and handle all events.

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

Args:
  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.

The documentation for this class was generated from the following file: