Remove unneeded and unused code from XmlItemExporter.

This commit is contained in:
Andrey Rakhmatullin 2019-08-20 20:56:26 +05:00
parent bbd9f4be90
commit de7789e52d
1 changed files with 4 additions and 18 deletions

View File

@ -143,11 +143,11 @@ class XmlItemExporter(BaseItemExporter):
def _beautify_newline(self, new_item=False):
if self.indent is not None and (self.indent > 0 or new_item):
self._xg_characters('\n')
self.xg.characters('\n')
def _beautify_indent(self, depth=1):
if self.indent:
self._xg_characters(' ' * self.indent * depth)
self.xg.characters(' ' * self.indent * depth)
def start_exporting(self):
self.xg.startDocument()
@ -182,26 +182,12 @@ class XmlItemExporter(BaseItemExporter):
self._export_xml_field('value', value, depth=depth+1)
self._beautify_indent(depth=depth)
elif isinstance(serialized_value, six.text_type):
self._xg_characters(serialized_value)
self.xg.characters(serialized_value)
else:
self._xg_characters(str(serialized_value))
self.xg.characters(str(serialized_value))
self.xg.endElement(name)
self._beautify_newline()
# Workaround for https://bugs.python.org/issue17606
# Before Python 2.7.4 xml.sax.saxutils required bytes;
# since 2.7.4 it requires unicode. The bug is likely to be
# fixed in 2.7.6, but 2.7.6 will still support unicode,
# and Python 3.x will require unicode, so ">= 2.7.4" should be fine.
if sys.version_info[:3] >= (2, 7, 4):
def _xg_characters(self, serialized_value):
if not isinstance(serialized_value, six.text_type):
serialized_value = serialized_value.decode(self.encoding)
return self.xg.characters(serialized_value)
else: # pragma: no cover
def _xg_characters(self, serialized_value):
return self.xg.characters(serialized_value)
class CsvItemExporter(BaseItemExporter):