pyhrf.xmliobak.xmlbase.
FuncWrapper
(func, params=None)¶pyhrf.xmliobak.xmlbase.
TypedXMLHandler
(write_callback=None)¶Class handling the xml format with the following generic document structure:
<root>
<tagName 'type'=tagType>
tagContent
</tagName>
</root>
The root tag is mandatory, so is the ‘type’ attribute for every other tag. This class can parse an xml string and build a dictionary of python objects according to each tag (see parseXMLString()). Conversely, it can build the xml string corresponding to a list or dictionary of objects ( see to_xml()). This class is based on the xml.dom python module and relies on the DOM structure to parse XML. XML input/output is handled via a mapping between a type attribute of a tag and a static handling function. This class handles the following basic python types: string, int, float, array.array, list, dict. One can add other type-specific read or write handlers with the functions addDOMTagReader() and addDOMWriter().
Reading XML:
specific handlers are added with method addDOMTagReader(stype, myReadHandler) which maps the function myReadHandler to the string stype.
a tag reading handler must have the following prototype:
myReadHandler(domTreeWalker):
# interpret and process tag content
# return built python object
, where domTreeWalker is an instance of the _xmlplus.dom.TreeWalker.TreeWalker class.
useful things to use the domTreeWalker and implement a handler:
Writing XML:
handlers are added with method addDOMTagWriter(pythonType, myWriteHandler), where pythonType is of python type ‘type’ and myWriteHandler a function.
a tag writing handler must have the following prototype:
myWriteHandler(domDocument, node, pyObj):
where:
useful things to write handlers :
ATTRIBUTE_LABEL_META
= 'meta'¶ATTRIBUTE_LABEL_PYTHON_CLASS
= 'pythonClass'¶ATTRIBUTE_LABEL_PYTHON_CLASS_INIT_MODE
= 'pythonInitMode'¶ATTRIBUTE_LABEL_PYTHON_FUNCTION
= 'pythonFunction'¶ATTRIBUTE_LABEL_PYTHON_MODULE
= 'pythonModule'¶ATTRIBUTE_LABEL_TYPE
= 'type'¶TYPE_LABEL_ARRAY
= 'array'¶TYPE_LABEL_BOOL
= 'bool'¶TYPE_LABEL_DICT
= 'struct'¶TYPE_LABEL_FLOAT
= 'double'¶TYPE_LABEL_INT
= 'int'¶TYPE_LABEL_KEY_VAL_PAIR
= 'dictItem'¶TYPE_LABEL_LIST
= 'list'¶TYPE_LABEL_NONE
= 'none'¶TYPE_LABEL_ODICT
= 'ordered_struct'¶TYPE_LABEL_STRING
= 'char'¶TYPE_LABEL_TUPLE
= 'tuple'¶TYPE_LABEL_XML_INCLUDE
= 'include'¶arrayDOMWriter
(doc, node, arrayObj, xmlHandler)¶arrayTagDOMReader
(walker, xmlHandler)¶boolDOMWriter
(doc, node, boolObj, xmlHandler)¶boolTagDOMReader
(walker, xmlHandler)¶buildXMLString
(obj, label=None, pretty=False)¶createDocument
()¶dictDOMWriter
(doc, node, dictObj, xmlHandler, atype=None)¶dictTagDOMReader
(walker, xmlHandler, init_class=None)¶floatDOMWriter
(doc, node, floatObj, xmlHandler)¶floatTagDOMReader
(walker, xmlHandler)¶includeTagDOMReader
(walker, xmlHandler)¶inspect_and_append_to_DOM_tree
(doc, node, obj)¶inspectable
(obj)¶intDOMWriter
(doc, node, intObj, xmlHandler)¶intTagDOMReader
(walker, xmlHandler)¶listDOMWriter
(doc, node, listObj, xmlHandler)¶listTagDOMReader
(walker, xmlHandler)¶mountDefaultHandlers
()¶noneDOMWriter
(doc, node, noneObj, xmlHandler)¶noneTagDOMReader
(walker, xmlHandler)¶odictDOMWriter
(doc, node, dictObj, xmlHandler)¶odictTagDOMReader
(walker, xmlHandler)¶packHandlers
()¶parseXMLString
(xml)¶readDOMData
(walker)¶rootTagDOMReader
(walker)¶stringDOMWriter
(doc, node, stringObj, xmlHandler)¶stringTagDOMReader
(walker, xmlHandler)¶tupleDOMWriter
(doc, node, tupleObj, xmlHandler)¶tupleTagDOMReader
(walker, xmlHandler)¶writeDOMData
(doc, node, obj, label, comment=None, meta=None)¶pyhrf.xmliobak.xmlbase.
XMLParamDrivenClass
(parameters=None, xmlHandler=<pyhrf.xmliobak.xmlbase.TypedXMLHandler instance>, xmlLabel=None, xmlComment=None)¶Base “abstract” class to handle parameters with clear specification and default values. Recursive aggregation is availaible to handle aggregated variables which also require parameter specifications.
appendParametersToDOMTree
(doc, node)¶defaultParameters
= {}¶fetchDefaultParameters
()¶parametersComments
= {}¶parametersMeta
= {}¶parametersToXml
(tagName=None, pretty=False)¶updateParameters
(newp)¶pyhrf.xmliobak.xmlbase.
XMLParamDrivenClassInitException
¶pyhrf.xmliobak.xmlbase.
XMLable
(**kwargs)¶get_parameters_comments
()¶get_parameters_meta
()¶get_parameters_to_show
()¶override_init
(param_name, init_obj, init_params=None)¶override_value
(param_name, value)¶set_init
(init_func, init_params=None)¶pyhrf.xmliobak.xmlbase.
XMLable2
¶Bases: object
check_init_func
(params=None)¶get_parameters_comments
()¶get_parameters_meta
()¶get_parameters_to_show
()¶override_param_init
(init_func, **params)¶TODO (if needed)
set_init
(init_func, **init_params)¶set_init_param
(param_name, param_value)¶pyhrf.xmliobak.xmlbase.
from_xml
(s, handler=<pyhrf.xmliobak.xmlbase.TypedXMLHandler instance>)¶pyhrf.xmliobak.xmlbase.
getargspec
(func)¶pyhrf.xmliobak.xmlbase.
match_init_args
(c, argsDict)¶pyhrf.xmliobak.xmlbase.
read_xml
(fn)¶pyhrf.xmliobak.xmlbase.
to_xml
(o, handler=<pyhrf.xmliobak.xmlbase.TypedXMLHandler instance>, objName='anonymObject', pretty=False)¶pyhrf.xmliobak.xmlbase.
write_xml
(obj, fn)¶