Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/jargonjustin/httpie into ja…
Browse files Browse the repository at this point in the history
…rgonjustin-master
  • Loading branch information
jkbrzt committed Jun 2, 2013
2 parents 63b61bc + 2e57c08 commit 8d302f9
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions httpie/output.py
Expand Up @@ -2,6 +2,7 @@
"""
import json
import xml.dom.minidom
from functools import partial
from itertools import chain

Expand All @@ -20,6 +21,9 @@
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())
Expand Down Expand Up @@ -389,13 +393,28 @@ def process_body(self, content, content_type, subtype):
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.
Expand Down Expand Up @@ -460,7 +479,8 @@ class OutputProcessor(object):
installed_processors = {
'format': [
HeadersProcessor,
JSONProcessor
JSONProcessor,
XMLProcessor
],
'colors': [
PygmentsProcessor
Expand Down

0 comments on commit 8d302f9

Please sign in to comment.