Skip to content

Commit f8c940d

Browse files
committed
DOC: Improve documentation of XmlSerializable class, update fallback return type
1 parent 67970ac commit f8c940d

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

nibabel/xmlutils.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,24 @@
1515

1616

1717
class XmlSerializable:
18-
"""Basic interface for serializing an object to xml"""
18+
"""Basic interface for serializing an object to XML"""
1919

20-
def _to_xml_element(self):
20+
def _to_xml_element(self) -> Element:
2121
"""Output should be a xml.etree.ElementTree.Element"""
22-
raise NotImplementedError()
22+
raise NotImplementedError
23+
24+
def to_xml(self, enc='utf-8', **kwargs) -> bytes:
25+
r"""Generate an XML bytestring with a given encoding.
2326
24-
def to_xml(self, enc='utf-8', **kwargs):
25-
"""Output should be an xml string with the given encoding.
26-
(default: utf-8)"""
27+
Parameters
28+
----------
29+
enc : :class:`string`
30+
Encoding to use for the generated bytestring. Default: 'utf-8'
31+
\*\*kwargs : :class:`dict`
32+
Additional keyword arguments to :func:`xml.etree.ElementTree.tostring`.
33+
"""
2734
ele = self._to_xml_element()
28-
return '' if ele is None else tostring(ele, enc, **kwargs)
35+
return b'' if ele is None else tostring(ele, enc, **kwargs)
2936

3037

3138
class XmlBasedHeader(FileBasedHeader, XmlSerializable):

0 commit comments

Comments
 (0)