Package flumotion :: Package common :: Module fxml :: Class Parser
[hide private]

Class Parser

source code

log.Loggable --+
               |
              Parser
Known Subclasses:

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.

Instance Methods [hide private]
 
getRoot(self, file)
Return the root of the XML tree for the the string or filename passed as an argument.
source code
 
checkAttributes(self, node, required=None, optional=None)
Checks that a given XML node has all of the required attributes, and no unknown attributes.
source code
tuple of string or None, as long as the combined length of the required and optional attributes.
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.
source code
 
parseFromTable(self, parent, parsers)
A data-driven verifying XML parser.
source code

Inherited from log.Loggable: __providedBy__, debug, doLog, error, info, log, logFunction, logObjectName, warning, warningFailure

Class Variables [hide private]

Inherited from log.Loggable: __implemented__, __provides__, logCategory

Method Details [hide private]

getRoot(self, file)

source code 

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 (File object; can be a duck file like StringIO. Alternately, the path of a file on disk.) - 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.

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

source code 

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 (xml.dom.Node) - An XML DOM node.
  • required (Sequence (list, tuple, ...) of strings.) - Set of required attributes, or None.
  • optional (Sequence (list, tuple, ...) of strings.) - Set of optional attributes, or None.

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

source code 

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 (xml.dom.Node) - An XML DOM node.
  • required (Sequence (list, tuple, ...) of strings.) - Set of required attributes, or None.
  • optional (Sequence (list, tuple, ...) of strings.) - Set of optional attributes, or None.
Returns: tuple of string or None, as long as the combined length of the required and optional attributes.
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.

parseFromTable(self, parent, parsers)

source code 

A data-driven verifying XML parser. Raises fxml.ParserError if an unexpected child node is encountered.

Parameters:
  • parent (xml.dom.Node) - An XML node whose child nodes you are interested in parsing.
  • parsers (dict of string -> (function, function)) - 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.