mirror of
https://github.com/httpie/cli.git
synced 2024-11-21 23:33:12 +01:00
Improve --debug output formatting
This commit is contained in:
parent
224519e0e2
commit
9da5c41704
@ -13,7 +13,7 @@ from httpie import __version__, sessions
|
||||
from httpie.cli.constants import SSL_VERSION_ARG_MAPPING
|
||||
from httpie.cli.dicts import RequestHeadersDict
|
||||
from httpie.plugins import plugin_manager
|
||||
from httpie.utils import repr_dict_nice
|
||||
from httpie.utils import repr_dict
|
||||
|
||||
|
||||
try:
|
||||
@ -122,8 +122,8 @@ def get_response(
|
||||
|
||||
|
||||
def dump_request(kwargs: dict):
|
||||
sys.stderr.write('\n>>> requests.request(**%s)\n\n'
|
||||
% repr_dict_nice(kwargs))
|
||||
sys.stderr.write(
|
||||
f'\n>>> requests.request(**{repr_dict(kwargs)})\n\n')
|
||||
|
||||
|
||||
def finalize_headers(headers: RequestHeadersDict) -> RequestHeadersDict:
|
||||
|
@ -11,7 +11,7 @@ except ImportError:
|
||||
from httpie.compat import is_windows
|
||||
from httpie.config import DEFAULT_CONFIG_DIR, Config
|
||||
|
||||
from httpie.utils import repr_dict_nice
|
||||
from httpie.utils import repr_dict
|
||||
|
||||
|
||||
class Environment:
|
||||
@ -94,11 +94,11 @@ class Environment:
|
||||
actual = dict(defaults)
|
||||
actual.update(self.__dict__)
|
||||
actual['config'] = self.config
|
||||
return repr_dict_nice(dict(
|
||||
(key, value)
|
||||
return repr_dict({
|
||||
key: value
|
||||
for key, value in actual.items()
|
||||
if not key.startswith('_'))
|
||||
)
|
||||
if not key.startswith('_')
|
||||
})
|
||||
|
||||
def __repr__(self):
|
||||
return f'<{type(self).__name__} {self}>'
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user