diff --git a/httpie/cli.py b/httpie/cli.py index 229ac274..b087f783 100644 --- a/httpie/cli.py +++ b/httpie/cli.py @@ -18,8 +18,8 @@ from .input import (Parser, AuthCredentialsArgType, KeyValueArgType, SEP_PROXY, SEP_CREDENTIALS, SEP_GROUP_ALL_ITEMS, OUT_REQ_HEAD, OUT_REQ_BODY, OUT_RESP_HEAD, OUT_RESP_BODY, OUTPUT_OPTIONS, OUTPUT_OPTIONS_DEFAULT, - PRETTY_MAP, PRETTY_STDOUT_TTY_ONLY, SessionNameValidator) -from .utils import existing_file + PRETTY_MAP, PRETTY_STDOUT_TTY_ONLY, SessionNameValidator, + readable_file_arg) class HTTPieHelpFormatter(RawDescriptionHelpFormatter): @@ -469,7 +469,7 @@ network.add_argument( network.add_argument( '--ssl-cert', default=None, - type=existing_file, + type=readable_file_arg, help=""" You can specify a local cert to use as client side SSL certificate. This file may either contain both private key and certificate or you may @@ -481,7 +481,7 @@ network.add_argument( network.add_argument( '--ssl-key', default=None, - type=existing_file, + type=readable_file_arg, help=""" The private key to use with SSL. Only needed if --ssl-cert is given and the certificate file does not contain the private key. diff --git a/httpie/input.py b/httpie/input.py index 3c180129..24269db4 100644 --- a/httpie/input.py +++ b/httpie/input.py @@ -1,6 +1,7 @@ """Parsing and processing of CLI input (args, auth credentials, files, stdin). """ +import argparse import os import sys import re @@ -630,3 +631,12 @@ def parse_items(items, data=None, headers=None, files=None, params=None): target[item.key] = value return headers, data, files, params + + +def readable_file_arg(filename): + try: + open(filename, 'rb') + except IOError as ex: + raise argparse.ArgumentTypeError( + '%s: %s' % (filename, ex.args[1])) + return filename diff --git a/httpie/utils.py b/httpie/utils.py index 3200cce2..37ac745d 100644 --- a/httpie/utils.py +++ b/httpie/utils.py @@ -1,5 +1,4 @@ from __future__ import division -import argparse def humanize_bytes(n, precision=2): @@ -46,11 +45,3 @@ def humanize_bytes(n, precision=2): return '%.*f %s' % (precision, n / factor, suffix) - -def existing_file(filename): - try: - open(filename, 'rb') - except IOError as ex: - raise argparse.ArgumentTypeError( - '%s: %s' % (filename, ex.args[1])) - return filename