Improved --debug output

This commit is contained in:
Jakub Roztocil 2016-03-05 01:42:13 +08:00
parent 4e574e6b8e
commit bb49a1f979
7 changed files with 42 additions and 6 deletions

View File

@ -24,6 +24,7 @@ This project adheres to `Semantic Versioning <http://semver.org/>`_.
is set
* Changed the default ``--style`` back to ``solarized`` for better support
of light and dark terminals
* Improved ``--debug`` output
* Fixed ``--session`` when used with ``--download``
* Fixed handling of ``Content-Type`` with multiple ``+subtype`` parts

View File

@ -11,7 +11,7 @@ from httpie import __version__
from httpie.compat import str
from httpie.input import SSL_VERSION_ARG_MAPPING
from httpie.plugins import plugin_manager
from httpie.utils import repr_dict_nice
try:
# https://urllib3.readthedocs.org/en/latest/security.html
@ -82,7 +82,7 @@ def get_response(args, config_dir):
def dump_request(kwargs):
sys.stderr.write('\n>>> requests.request(**%s)\n\n'
% pformat(kwargs))
% repr_dict_nice(kwargs))
def encode_headers(headers):

View File

@ -3,6 +3,8 @@ import sys
from httpie.compat import is_windows
from httpie.config import DEFAULT_CONFIG_DIR, Config
from httpie.utils import repr_dict_nice
class Environment(object):
"""
@ -82,3 +84,17 @@ class Environment(object):
else:
self._config.load()
return self._config
def __str__(self):
defaults = dict(type(self).__dict__)
actual = dict(defaults)
actual.update(self.__dict__)
actual['config'] = self.config
return repr_dict_nice(dict(
(key, value)
for key, value in actual.items()
if not key.startswith('_'))
)
def __repr__(self):
return '<{0} {1}>'.format(type(self).__name__, str(self))

View File

@ -12,6 +12,7 @@ Invocation flow:
"""
import sys
import errno
import platform
import requests
from requests import __version__ as requests_version
@ -48,11 +49,14 @@ def get_exit_status(http_status, follow=False):
def print_debug_info(env):
env.stderr.writelines([
'HTTPie %s\n' % httpie_version,
'HTTPie data: %s\n' % env.config.directory,
'Requests %s\n' % requests_version,
'Pygments %s\n' % pygments_version,
'Python %s %s\n' % (sys.version, sys.platform)
'Python %s\n%s\n' % (sys.version, sys.executable),
'%s %s' % (platform.system(), platform.release()),
])
env.stderr.write('\n\n')
env.stderr.write(repr(env))
env.stderr.write('\n')
def decode_args(args, stdin_encoding):

View File

@ -10,6 +10,22 @@ 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 humanize_bytes(n, precision=2):
# Author: Doug Latornell
# Licence: MIT

View File

@ -32,7 +32,7 @@ def test_error_traceback(get_response):
exc.request = Request(method='GET', url='http://www.google.com')
get_response.side_effect = exc
with raises(ConnectionError):
ret = main(['--ignore-stdin', '--traceback', 'www.google.com'])
main(['--ignore-stdin', '--traceback', 'www.google.com'])
@mock.patch('httpie.core.get_response')

View File

@ -11,7 +11,6 @@ def test_debug():
r = http('--debug')
assert r.exit_status == httpie.ExitStatus.OK
assert 'HTTPie %s' % httpie.__version__ in r.stderr
assert 'HTTPie data:' in r.stderr
def test_help():