|
15 | 15 |
|
16 | 16 |
|
17 | 17 | class XmlSerializable:
|
18 |
| - """Basic interface for serializing an object to xml""" |
| 18 | + """Basic interface for serializing an object to XML""" |
19 | 19 |
|
20 |
| - def _to_xml_element(self): |
| 20 | + def _to_xml_element(self) -> Element: |
21 | 21 | """Output should be a xml.etree.ElementTree.Element"""
|
22 |
| - raise NotImplementedError() |
| 22 | + raise NotImplementedError # pragma: no cover |
23 | 23 |
|
24 |
| - def to_xml(self, enc='utf-8'): |
25 |
| - """Output should be an xml string with the given encoding. |
26 |
| - (default: utf-8)""" |
| 24 | + def to_xml(self, enc='utf-8', **kwargs) -> bytes: |
| 25 | + r"""Generate an XML bytestring with a given encoding. |
| 26 | +
|
| 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 | + """ |
27 | 34 | ele = self._to_xml_element()
|
28 |
| - return '' if ele is None else tostring(ele, enc) |
| 35 | + return b'' if ele is None else tostring(ele, enc, **kwargs) |
29 | 36 |
|
30 | 37 |
|
31 | 38 | class XmlBasedHeader(FileBasedHeader, XmlSerializable):
|
@@ -101,10 +108,10 @@ def parse(self, string=None, fname=None, fptr=None):
|
101 | 108 | parser.ParseFile(fptr)
|
102 | 109 |
|
103 | 110 | def StartElementHandler(self, name, attrs):
|
104 |
| - raise NotImplementedError |
| 111 | + raise NotImplementedError # pragma: no cover |
105 | 112 |
|
106 | 113 | def EndElementHandler(self, name):
|
107 |
| - raise NotImplementedError |
| 114 | + raise NotImplementedError # pragma: no cover |
108 | 115 |
|
109 | 116 | def CharacterDataHandler(self, data):
|
110 |
| - raise NotImplementedError |
| 117 | + raise NotImplementedError # pragma: no cover |
0 commit comments