mirror of
https://github.com/httpie/cli.git
synced 2025-06-26 12:31:47 +02:00
Removed XML formatter
Closes #443 Closes #389 Closes #415 Closes #384 Closes #394
This commit is contained in:
parent
557911b606
commit
293295cad6
@ -29,6 +29,8 @@ This project adheres to `Semantic Versioning <http://semver.org/>`_.
|
|||||||
* Fixed ``--session`` when used with ``--download``
|
* Fixed ``--session`` when used with ``--download``
|
||||||
* Fixed ``--download`` to trim too long filenames before saving the file
|
* Fixed ``--download`` to trim too long filenames before saving the file
|
||||||
* Fixed handling of ``Content-Type`` with multiple ``+subtype`` parts
|
* 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)
|
`0.9.3`_ (2016-01-01)
|
||||||
|
@ -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('<!DOCTYPE[^\n]+?>', 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
|
|
@ -11,7 +11,6 @@ from httpie.plugins.manager import PluginManager
|
|||||||
from httpie.plugins.builtin import BasicAuthPlugin, DigestAuthPlugin
|
from httpie.plugins.builtin import BasicAuthPlugin, DigestAuthPlugin
|
||||||
from httpie.output.formatters.headers import HeadersFormatter
|
from httpie.output.formatters.headers import HeadersFormatter
|
||||||
from httpie.output.formatters.json import JSONFormatter
|
from httpie.output.formatters.json import JSONFormatter
|
||||||
from httpie.output.formatters.xml import XMLFormatter
|
|
||||||
from httpie.output.formatters.colors import ColorFormatter
|
from httpie.output.formatters.colors import ColorFormatter
|
||||||
|
|
||||||
|
|
||||||
@ -20,5 +19,4 @@ plugin_manager.register(BasicAuthPlugin,
|
|||||||
DigestAuthPlugin)
|
DigestAuthPlugin)
|
||||||
plugin_manager.register(HeadersFormatter,
|
plugin_manager.register(HeadersFormatter,
|
||||||
JSONFormatter,
|
JSONFormatter,
|
||||||
XMLFormatter,
|
|
||||||
ColorFormatter)
|
ColorFormatter)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user