Exemple #1
0
def httpie(
    *args,
    **kwargs
) -> StrCLIResponse:
    """
    Run HTTPie manager command with the given
    args/kwargs, and capture stderr/out and exit
    status.
    """

    env = kwargs.setdefault('env', MockEnvironment())
    cli_args = ['httpie']
    if not kwargs.pop('no_debug', False):
        cli_args.append('--debug')
    cli_args += normalize_args(args)
    exit_status = manager.main(
        args=cli_args,
        **kwargs
    )

    env.stdout.seek(0)
    env.stderr.seek(0)
    try:
        response = BaseCLIResponse.from_raw_data(env.stdout.read())
        response.stderr = env.stderr.read()
        response.exit_status = exit_status
        response.args = cli_args
    finally:
        env.stdout.truncate(0)
        env.stderr.truncate(0)
        env.stdout.seek(0)
        env.stderr.seek(0)

    return response
Exemple #2
0
def httpie(*args, **kwargs) -> StrCLIResponse:
    """
    Run HTTPie manager command with the given
    args/kwargs, and capture stderr/out and exit
    status.
    """

    env = kwargs.setdefault('env', MockEnvironment(stdout_mode=''))
    cli_args = ['httpie']
    if not kwargs.pop('no_debug', False):
        cli_args.append('--debug')
    cli_args += normalize_args(args)
    exit_status = manager.main(args=cli_args, **kwargs)

    env.stdout.seek(0)
    env.stderr.seek(0)
    try:
        output = env.stdout.read()
        if isinstance(output, bytes):
            with suppress(UnicodeDecodeError):
                output = output.decode()

        if isinstance(output, bytes):
            response = BytesCLIResponse(output)
        else:
            response = StrCLIResponse(output)

        response.stderr = env.stderr.read()
        response.exit_status = exit_status
        response.args = cli_args
    finally:
        env.stdout.truncate(0)
        env.stderr.truncate(0)
        env.stdout.seek(0)
        env.stderr.seek(0)

    return response
Exemple #3
0
from httpie.manager.__main__ import main

if __name__ == '__main__':
    import sys
    sys.exit(main())