Skip to content

Commit

Permalink
DOC: Improve documentation of XmlSerializable class, update fallback …
Browse files Browse the repository at this point in the history
…return type
  • Loading branch information
effigies committed Sep 22, 2023
1 parent d73bf1b commit 6a4736c
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions nibabel/xmlutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,24 @@


class XmlSerializable:
"""Basic interface for serializing an object to xml"""
"""Basic interface for serializing an object to XML"""

def _to_xml_element(self):
def _to_xml_element(self) -> Element:
"""Output should be a xml.etree.ElementTree.Element"""
raise NotImplementedError()
raise NotImplementedError

def to_xml(self, enc='utf-8', **kwargs) -> bytes:
r"""Generate an XML bytestring with a given encoding.
def to_xml(self, enc='utf-8', **kwargs):
"""Output should be an xml string with the given encoding.
(default: utf-8)"""
Parameters
----------
enc : :class:`string`
Encoding to use for the generated bytestring. Default: 'utf-8'
\*\*kwargs : :class:`dict`
Additional keyword arguments to :func:`xml.etree.ElementTree.tostring`.
"""
ele = self._to_xml_element()
return '' if ele is None else tostring(ele, enc, **kwargs)
return b'' if ele is None else tostring(ele, enc, **kwargs)


class XmlBasedHeader(FileBasedHeader, XmlSerializable):
Expand Down

0 comments on commit 6a4736c

Please sign in to comment.