def deserialize(self, stream, **kwargs):
"""
Deserialize from `PROV-XML <http://www.w3.org/TR/prov-xml/>`_
representation to a :class:`~prov.model.ProvDocument` instance.
:param stream: Input data.
"""
if isinstance(stream, io.TextIOBase):
with io.BytesIO() as buf:
buf.write(stream.read().encode('utf-8'))
buf.seek(0, 0)
xml_doc = etree.parse(buf).getroot()
else:
xml_doc = etree.parse(stream).getroot()
# Remove all comments.
for c in xml_doc.xpath("//comment()"):
p = c.getparent()
p.remove(c)
document = prov.model.ProvDocument()
self.deserialize_subtree(xml_doc, document)
return document
评论列表
文章目录