1
0
mirror of https://github.com/httpie/cli.git synced 2024-11-28 08:38:44 +02:00

Merge branch 'master' of git://github.com/jargonjustin/httpie into jargonjustin-master

This commit is contained in:
Jakub Roztocil 2013-06-02 20:14:51 +02:00
commit 8d302f91f9

View File

@ -2,6 +2,7 @@
"""
import json
import xml.dom.minidom
from functools import partial
from itertools import chain
@ -20,6 +21,9 @@ from .input import (OUT_REQ_BODY, OUT_REQ_HEAD,
OUT_RESP_HEAD, OUT_RESP_BODY)
# The default number of spaces to indent when pretty printing
DEFAULT_INDENT = 4
# Colors on Windows via colorama don't look that
# great and fruity seems to give the best result there.
AVAILABLE_STYLES = set(STYLE_MAP.keys())
@ -389,13 +393,28 @@ class JSONProcessor(BaseProcessor):
content = json.dumps(json.loads(content),
sort_keys=True,
ensure_ascii=False,
indent=4)
indent=DEFAULT_INDENT)
except ValueError:
# Invalid JSON but we don't care.
pass
return content
class XMLProcessor(BaseProcessor):
"""XML body processor."""
def process_body(self, content, content_type, subtype):
if subtype == 'xml':
try:
# Pretty print the XML
doc = xml.dom.minidom.parseString(content)
content = doc.toprettyxml(indent=' '*DEFAULT_INDENT)
except xml.parsers.expat.ExpatError:
# Ignore invalid XML errors (skips attempting to pretty print)
pass
return content
class PygmentsProcessor(BaseProcessor):
"""A processor that applies syntax-highlighting using Pygments
to the headers, and to the body as well if its content type is recognized.
@ -460,7 +479,8 @@ class OutputProcessor(object):
installed_processors = {
'format': [
HeadersProcessor,
JSONProcessor
JSONProcessor,
XMLProcessor
],
'colors': [
PygmentsProcessor