Class Parser
An XODE parser.
Parameters
Certain aspects of the parsing can be controlled by setting
parameters with setParams()
.
spaceFactory
spaceFactory
can be set to a callable object that
creates instances which inherit from ode.SpaceBase
. This factory will be
used by the parser to create Space objects for <space> tags
unless the class is overridden in the XODE file. The default behavior
is to use the ode.SimpleSpace
class.
Example using ode.HashSpace
:
| from xode import parser
| import ode
|
| p = parser.Parser()
| p.setParams(spaceFactory=ode.HashSpace)
Example using ode.QuadTreeSpace
:
| from xode import parser
| import ode
|
| def makeSpace():
| return ode.QuadTreeSpace((0, 0, 0), (2, 2, 2), 3)
|
| p = parser.Parser()
| p.setParams(spaceFactory=makeSpace)
Method Summary |
|
__init__ (self)
Initialise the parser. |
|
getParam (self,
name)
Return the value of the given parameter. |
instance of node.TreeNode
|
parseFile (self,
fp)
Parses the given file. |
instance of node.TreeNode
|
parseString (self,
xml)
Parses the given string. |
tuple
|
parseVector (self,
attrs)
Parses an element's attributes as a vector. |
|
pop(self)
|
|
push(self,
startElement,
endElement)
|
|
setParams (self,
**params)
Sets some parse parameters. |
__init__(self)
(Constructor)
Initialise the parser.
-
|
getParam(self,
name)
-
- Parameters:
name -
The parameter name.
(type=str)
- Returns:
-
The value of the given parameter.
- Raises:
KeyError -
If the parameter is not defined.
|
parseFile(self,
fp)
Parses the given file.
-
- Parameters:
fp -
A file-like object.
(type=file-like instance)
- Returns:
-
The root container.
(type=instance of node.TreeNode )
- Raises:
errors.InvalidError -
If document is invalid.
|
parseString(self,
xml)
Parses the given string.
-
- Parameters:
xml -
The string to parse.
(type=str)
- Returns:
-
The root container.
(type=instance of node.TreeNode )
- Raises:
errors.InvalidError -
If document is invalid.
|
parseVector(self,
attrs)
Parses an element's attributes as a vector.
-
- Returns:
-
The vector (x, y, z).
(type=tuple)
- Raises:
errors.InvalidError -
If the attributes don't correspond to a valid vector.
|
setParams(self,
**params)
Sets some parse parameters.
-
|