From 293295cad6547e9e3e59bc2888d94b6b6ba03c8e Mon Sep 17 00:00:00 2001 From: Jakub Roztocil Date: Fri, 18 Mar 2016 09:15:44 +0800 Subject: [PATCH] Removed XML formatter Closes #443 Closes #389 Closes #415 Closes #384 Closes #394 --- CHANGELOG.rst | 2 ++ httpie/output/formatters/xml.py | 61 --------------------------------- httpie/plugins/__init__.py | 2 -- 3 files changed, 2 insertions(+), 63 deletions(-) delete mode 100644 httpie/output/formatters/xml.py diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 23bda11a..7e95e30c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -29,6 +29,8 @@ This project adheres to `Semantic Versioning `_. * Fixed ``--session`` when used with ``--download`` * Fixed ``--download`` to trim too long filenames before saving the file * Fixed handling of ``Content-Type`` with multiple ``+subtype`` parts +* Removed XML formatting as the implementation suffered from multiple issues + `0.9.3`_ (2016-01-01) diff --git a/httpie/output/formatters/xml.py b/httpie/output/formatters/xml.py deleted file mode 100644 index dc82e5be..00000000 --- a/httpie/output/formatters/xml.py +++ /dev/null @@ -1,61 +0,0 @@ -from __future__ import absolute_import -import re -from xml.etree import ElementTree - -from httpie.plugins import FormatterPlugin - - -DECLARATION_RE = re.compile('<\?xml[^\n]+?\?>', flags=re.I) -DOCTYPE_RE = re.compile('', flags=re.I) - - -DEFAULT_INDENT = 4 - - -def indent(elem, indent_text=' ' * DEFAULT_INDENT): - """ - In-place prettyprint formatter - C.f. http://effbot.org/zone/element-lib.htm#prettyprint - - """ - def _indent(elem, level=0): - i = "\n" + level * indent_text - if len(elem): - if not elem.text or not elem.text.strip(): - elem.text = i + indent_text - if not elem.tail or not elem.tail.strip(): - elem.tail = i - for elem in elem: - _indent(elem, level + 1) - if not elem.tail or not elem.tail.strip(): - elem.tail = i - else: - if level and (not elem.tail or not elem.tail.strip()): - elem.tail = i - - return _indent(elem) - - -class XMLFormatter(FormatterPlugin): - # TODO: tests - - def format_body(self, body, mime): - if 'xml' in mime: - # FIXME: orig NS names get forgotten during the conversion, etc. - try: - root = ElementTree.fromstring(body.encode('utf8')) - except ElementTree.ParseError: - # Ignore invalid XML errors (skips attempting to pretty print) - pass - else: - indent(root) - # Use the original declaration - declaration = DECLARATION_RE.match(body) - doctype = DOCTYPE_RE.match(body) - body = ElementTree.tostring(root, encoding='utf-8')\ - .decode('utf8') - if doctype: - body = '%s\n%s' % (doctype.group(0), body) - if declaration: - body = '%s\n%s' % (declaration.group(0), body) - return body diff --git a/httpie/plugins/__init__.py b/httpie/plugins/__init__.py index 4be81e7a..13b85650 100644 --- a/httpie/plugins/__init__.py +++ b/httpie/plugins/__init__.py @@ -11,7 +11,6 @@ from httpie.plugins.manager import PluginManager from httpie.plugins.builtin import BasicAuthPlugin, DigestAuthPlugin from httpie.output.formatters.headers import HeadersFormatter from httpie.output.formatters.json import JSONFormatter -from httpie.output.formatters.xml import XMLFormatter from httpie.output.formatters.colors import ColorFormatter @@ -20,5 +19,4 @@ plugin_manager.register(BasicAuthPlugin, DigestAuthPlugin) plugin_manager.register(HeadersFormatter, JSONFormatter, - XMLFormatter, ColorFormatter)