1
0
mirror of https://github.com/httpie/cli.git synced 2024-11-28 08:38:44 +02:00

rename existing_file to readable_file_arg and move to input

This commit is contained in:
Matthias Lehmann 2014-01-29 18:02:06 +01:00
parent b9d7220b10
commit d4363a560d
3 changed files with 14 additions and 13 deletions

View File

@ -18,8 +18,8 @@ from .input import (Parser, AuthCredentialsArgType, KeyValueArgType,
SEP_PROXY, SEP_CREDENTIALS, SEP_GROUP_ALL_ITEMS, SEP_PROXY, SEP_CREDENTIALS, SEP_GROUP_ALL_ITEMS,
OUT_REQ_HEAD, OUT_REQ_BODY, OUT_RESP_HEAD, OUT_REQ_HEAD, OUT_REQ_BODY, OUT_RESP_HEAD,
OUT_RESP_BODY, OUTPUT_OPTIONS, OUTPUT_OPTIONS_DEFAULT, OUT_RESP_BODY, OUTPUT_OPTIONS, OUTPUT_OPTIONS_DEFAULT,
PRETTY_MAP, PRETTY_STDOUT_TTY_ONLY, SessionNameValidator) PRETTY_MAP, PRETTY_STDOUT_TTY_ONLY, SessionNameValidator,
from .utils import existing_file readable_file_arg)
class HTTPieHelpFormatter(RawDescriptionHelpFormatter): class HTTPieHelpFormatter(RawDescriptionHelpFormatter):
@ -469,7 +469,7 @@ network.add_argument(
network.add_argument( network.add_argument(
'--ssl-cert', '--ssl-cert',
default=None, default=None,
type=existing_file, type=readable_file_arg,
help=""" help="""
You can specify a local cert to use as client side SSL certificate. 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 This file may either contain both private key and certificate or you may
@ -481,7 +481,7 @@ network.add_argument(
network.add_argument( network.add_argument(
'--ssl-key', '--ssl-key',
default=None, default=None,
type=existing_file, type=readable_file_arg,
help=""" help="""
The private key to use with SSL. Only needed if --ssl-cert is given and the The private key to use with SSL. Only needed if --ssl-cert is given and the
certificate file does not contain the private key. certificate file does not contain the private key.

View File

@ -1,6 +1,7 @@
"""Parsing and processing of CLI input (args, auth credentials, files, stdin). """Parsing and processing of CLI input (args, auth credentials, files, stdin).
""" """
import argparse
import os import os
import sys import sys
import re import re
@ -630,3 +631,12 @@ def parse_items(items, data=None, headers=None, files=None, params=None):
target[item.key] = value target[item.key] = value
return headers, data, files, params 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

View File

@ -1,5 +1,4 @@
from __future__ import division from __future__ import division
import argparse
def humanize_bytes(n, precision=2): def humanize_bytes(n, precision=2):
@ -46,11 +45,3 @@ def humanize_bytes(n, precision=2):
return '%.*f %s' % (precision, n / factor, suffix) 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