1
0
mirror of https://github.com/httpie/cli.git synced 2025-11-29 22:58:15 +02:00

Improve --debug output formatting

This commit is contained in:
Jakub Roztocil
2019-08-31 18:00:03 +02:00
parent 224519e0e2
commit 9da5c41704
3 changed files with 11 additions and 22 deletions

View File

@@ -2,6 +2,7 @@ from __future__ import division
import json
import mimetypes
from collections import OrderedDict
from pprint import pformat
import requests.auth
@@ -10,20 +11,8 @@ def load_json_preserve_order(s):
return json.loads(s, object_pairs_hook=OrderedDict)
def repr_dict_nice(d):
def prepare_dict(d):
for k, v in d.items():
if isinstance(v, dict):
v = dict(prepare_dict(v))
elif isinstance(v, bytes):
v = v.decode('utf8')
elif not isinstance(v, (int, str)):
v = repr(v)
yield k, v
return json.dumps(
dict(prepare_dict(d)),
indent=4, sort_keys=True,
)
def repr_dict(d: dict) -> str:
return pformat(d)
def humanize_bytes(n, precision=2):