From 727adc8a053402d3e9a38424ff67bde697674156 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Mon, 23 Jul 2018 16:16:42 -0400 Subject: Improve serializer test coverage Should be 100% coverage now. The ProcessingInstruction needed to be imported directly from ElementTree as PY27 was using a PIProxy which resulted in a bug. Interestingly, PY3 worked fine. Also removed the encoding code as it was not used. Besides it was only ever accessable from a private function. --- markdown/serializers.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'markdown') diff --git a/markdown/serializers.py b/markdown/serializers.py index 63446b9..187d755 100644 --- a/markdown/serializers.py +++ b/markdown/serializers.py @@ -39,6 +39,7 @@ from __future__ import absolute_import from __future__ import unicode_literals +from xml.etree.ElementTree import ProcessingInstruction from . import util ElementTree = util.etree.ElementTree QName = util.etree.QName @@ -46,8 +47,6 @@ if hasattr(util.etree, 'test_comment'): # pragma: no cover Comment = util.etree.test_comment else: # pragma: no cover Comment = util.etree.Comment -PI = util.etree.PI -ProcessingInstruction = util.etree.ProcessingInstruction __all__ = ['to_html_string', 'to_xhtml_string'] @@ -66,13 +65,6 @@ def _raise_serialization_error(text): # pragma: no cover ) -def _encode(text, encoding): - try: - return text.encode(encoding, "xmlcharrefreplace") - except (TypeError, AttributeError): # pragma: no cover - _raise_serialization_error(text) - - def _escape_cdata(text): # escape character data try: @@ -181,15 +173,12 @@ def _serialize_html(write, elem, format): write(_escape_cdata(elem.tail)) -def _write_html(root, encoding=None, format="html"): +def _write_html(root, format="html"): assert root is not None data = [] write = data.append _serialize_html(write, root, format) - if encoding is None: - return "".join(data) - else: - return _encode("".join(data), encoding) + return "".join(data) # -------------------------------------------------------------------- -- cgit v1.2.3