Package flumotion :: Package common :: Module fxml :: Class Parser
[show private | hide private]
[frames | no frames]

Class Parser

Loggable --+
           |
          Parser

Known Subclasses:
BaseConfigParser, RegistryParser

XML parser base class.

I add some helper functions for specialized XML parsers, mostly the parseFromTable method.

I am here so that the config parser and the registry parser can share code.
Method Summary
  checkAttributes(self, node, required, optional)
Checks that a given XML node has all of the required attributes, and no unknown attributes.
  getRoot(self, file)
Return the root of the XML tree for the the string or filename passed as an argument.
tuple of string or None, as long as the combined length of the required and optional attributes. parseAttributes(self, node, required, optional)
Checks the validity of the attributes on an XML node, via Parser.checkAttributes, then parses them out and returns them all as a tuple.
  parseFromTable(self, parent, parsers)
A data-driven verifying XML parser.
    Inherited from Loggable
  debug(self, *args)
Log a debug message.
dict doLog(self, level, where, format, *args, **kwargs)
Log a message at the given level, with the possibility of going higher up in the stack.
  error(self, *args)
Log an error.
  info(self, *args)
Log an informational message.
  log(self, *args)
Log a log message.
  logFunction(self, *args)
Overridable log function.
  logObjectName(self)
Overridable object name function.
  warning(self, *args)
Log a warning.
  warningFailure(self, failure, swallow)
Log a warning about a Failure.

Class Variable Summary
    Inherited from Loggable
Implements __implemented__ = <implementedBy flumotion.common.log.Lo...
ClassProvides __providedBy__ = <zope.interface.declarations.ClassProvi...
ClassProvides __provides__ = <zope.interface.declarations.ClassProvide...
str logCategory: Implementors can provide a category to log their messages under.

Method Details

checkAttributes(self, node, required=None, optional=None)

Checks that a given XML node has all of the required attributes, and no unknown attributes. Raises fxml.ParserError if unknown or missing attributes are detected.
Parameters:
node - An XML DOM node.
           (type=xml.dom.Node)
required - Set of required attributes, or None.
           (type=Sequence (list, tuple, ...) of strings.)
optional - Set of optional attributes, or None.
           (type=Sequence (list, tuple, ...) of strings.)

getRoot(self, file)

Return the root of the XML tree for the the string or filename passed as an argument. Raises fxml.ParserError if the XML could not be parsed.
Parameters:
file - An open file object, or the name of a file. Note that if you pass a file object, this function will leave the file open.
           (type=File object; can be a duck file like StringIO. Alternately, the path of a file on disk.)

parseAttributes(self, node, required=None, optional=None)

Checks the validity of the attributes on an XML node, via Parser.checkAttributes, then parses them out and returns them all as a tuple.
Parameters:
node - An XML DOM node.
           (type=xml.dom.Node)
required - Set of required attributes, or None.
           (type=Sequence (list, tuple, ...) of strings.)
optional - Set of optional attributes, or None.
           (type=Sequence (list, tuple, ...) of strings.)
Returns:
List of all attributes as a tuple. The first element of the returned tuple will be the value of the first required attribute, the second the value of the second required attribute, and so on. The optional attributes follow, with None as the value if the optional attribute was not present.
           (type=tuple of string or None, as long as the combined length of the required and optional attributes.)

parseFromTable(self, parent, parsers)

A data-driven verifying XML parser. Raises fxml.ParserError if an unexpected child node is encountered.
Parameters:
parent - An XML node whose child nodes you are interested in parsing.
           (type=xml.dom.Node)
parsers - A parse table defining how to parse the child nodes. The keys are the possible child nodes, and the value is a two-tuple of how to parse them consisting of a parser and a value handler. The parser is a one-argument function that will be called with the child node as an argument, and the handler is a one-argument function that will be called with the result of calling the parser.
           (type=dict of string -> (function, function))

Generated by Epydoc 2.1 on Mon Oct 1 03:52:13 2007 http://epydoc.sf.net