Commit 7a505286 authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

[lib] Chart xml parser: Clean/add doc

parent 9de8ba99
......@@ -47,7 +47,7 @@ from __future__ import print_function
from cadbiom.models.guard_transitions.chart_model import ChartModel
from xml.sax import make_parser
from xml.sax import parseString as PS
from xml.sax import parseString
from xml.sax.handler import ContentHandler
from lxml import etree
from lxml import objectify
......@@ -460,14 +460,20 @@ class MakeHandler(ContentHandler):
class MakeModelFromXmlFile:
"""
parse a xml file
"""
def __init__(self, xml_file, model = None):
"""Parse a xml file"""
def __init__(self, xml_file, model=None):
"""
:param xml_file: Path of XML file
:param model: Pre-computed model (never used)
:type xml_file: <str>
:type model: <ChartModel>
"""
self.model = model
self.handler = MakeHandler(model=self.model)
self.parser = make_parser()
self.parser.setContentHandler(self.handler)
try:
self.parser.parse(xml_file)
except Exception:
......@@ -476,15 +482,15 @@ class MakeModelFromXmlFile:
def get_model(self):
"""
As it says
"""Return the model generated from the XML file
:rtype: <ChartModel>
"""
return self.handler.model
class MakeModelFromXmlString:
"""
parse a xml description as string
"""
"""Parse a xml description as string"""
def __init__(self, xml_string):
self.model = None
self.handler = MakeHandler()
......@@ -492,15 +498,16 @@ class MakeModelFromXmlString:
self.parser.setContentHandler(self.handler)
try:
PS(xml_string, self.handler)
parseString(xml_string, self.handler)
except Exception as exc:
print('ERROR while xml parsing')
print(exc)
def get_model(self):
"""
As it says
"""Return the model generated from the XML string
:rtype: <ChartModel>
"""
return self.handler.model
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment