Package Bio :: Module ParserSupport :: Class EventGenerator
[show private | hide private]
[frames | no frames]

Class EventGenerator

ContentHandler --+
                 |
                EventGenerator


Handler to generate events associated with a Martel parsed file.

This acts like a normal SAX handler, and accepts XML generated by Martel during parsing. These events are then converted into 'Biopython events', which can then be caught by a standard biopython consumer
Method Summary
  __init__(self, consumer, interest_tags, callback_finalizer, exempt_tags)
Initialize to begin catching and firing off events.
  characters(self, content)
Extract the information if we are interested in it.
  endDocument(self)
Make sure all of our information has been passed.
  endElement(self, name)
Send the information to the consumer.
  startElement(self, name, attrs)
Determine if we should collect characters from this tag.
  _make_callback(self, name)
Call the callback function with the info with the given name.
    Inherited from ContentHandler
  endElementNS(self, name, qname)
Signals the end of an element in namespace mode.
  endPrefixMapping(self, prefix)
End the scope of a prefix-URI mapping.
  ignorableWhitespace(self, whitespace)
Receive notification of ignorable whitespace in element content.
  processingInstruction(self, target, data)
Receive notification of a processing instruction.
  setDocumentLocator(self, locator)
Called by the parser to give the application a locator for locating the origin of document events.
  skippedEntity(self, name)
Receive notification of a skipped entity.
  startDocument(self)
Receive notification of the beginning of a document.
  startElementNS(self, name, qname, attrs)
Signals the start of an element in namespace mode.
  startPrefixMapping(self, prefix, uri)
Begin the scope of a prefix-URI Namespace mapping.

Method Details

__init__(self, consumer, interest_tags, callback_finalizer=None, exempt_tags=[])
(Constructor)

Initialize to begin catching and firing off events.

Arguments: o consumer - The consumer that we'll send Biopython events to.

o interest_tags - A listing of all the tags we are interested in.

o callback_finalizer - A function to deal with the collected information before passing it on to the consumer. By default the collected information is a list of all of the lines read for a particular tag -- if there are multiple tags in a row like:

<some_info>Spam<some_info> <some_info>More Spam<some_info>

In this case the list of information would be:

['Spam', 'More Spam']

This list of lines will be passed to the callback finalizer if it is present. Otherwise the consumer will be called with the list of content information.

o exempt_tags - A listing of particular tags that are exempt from being processed by the callback_finalizer. This allows you to use a finalizer to deal with most tags, but leave those you don't want touched.
Overrides:
xml.sax.handler.ContentHandler.__init__

characters(self, content)

Extract the information if we are interested in it.
Overrides:
xml.sax.handler.ContentHandler.characters

endDocument(self)

Make sure all of our information has been passed.

This just flushes out any stored tags that need to be passed.
Overrides:
xml.sax.handler.ContentHandler.endDocument

endElement(self, name)

Send the information to the consumer.

Once we've got the end element we've collected up all of the character information we need, and we need to send this on to the consumer to do something with it.

We have a delay of one tag on doing this, so that we can collect all of the info from multiple calls to the same element at once.
Overrides:
xml.sax.handler.ContentHandler.endElement

startElement(self, name, attrs)

Determine if we should collect characters from this tag.
Overrides:
xml.sax.handler.ContentHandler.startElement

_make_callback(self, name)

Call the callback function with the info with the given name.

Generated by Epydoc 2.1 on Mon Aug 27 16:13:11 2007 http://epydoc.sf.net