Parser => HTTPieArgumentParser

This commit is contained in:
Jakub Roztocil 2016-02-28 19:01:54 +08:00
parent 10da7b63a3
commit 8c33e5e3d3
3 changed files with 11 additions and 8 deletions

View File

@ -13,7 +13,8 @@ from httpie.plugins.builtin import BuiltinAuthPlugin
from httpie.plugins import plugin_manager
from httpie.sessions import DEFAULT_SESSIONS_DIR
from httpie.output.formatters.colors import AVAILABLE_STYLES, DEFAULT_STYLE
from httpie.input import (Parser, AuthCredentialsArgType, KeyValueArgType,
from httpie.input import (HTTPieArgumentParser,
AuthCredentialsArgType, KeyValueArgType,
SEP_PROXY, SEP_CREDENTIALS, SEP_GROUP_ALL_ITEMS,
OUT_REQ_HEAD, OUT_REQ_BODY, OUT_RESP_HEAD,
OUT_RESP_BODY, OUTPUT_OPTIONS,
@ -40,7 +41,7 @@ class HTTPieHelpFormatter(RawDescriptionHelpFormatter):
text = dedent(text).strip() + '\n\n'
return text.splitlines()
parser = Parser(
parser = HTTPieArgumentParser(
formatter_class=HTTPieHelpFormatter,
description='%s <http://httpie.org>' % __doc__.strip(),
epilog=dedent("""
@ -51,10 +52,12 @@ parser = Parser(
https://github.com/jkbrzt/httpie/issues
""")
"""),
usage='see http --help'
)
#######################################################################
# Positional arguments.
#######################################################################

View File

@ -103,7 +103,7 @@ OUTPUT_OPTIONS_DEFAULT = OUT_RESP_HEAD + OUT_RESP_BODY
OUTPUT_OPTIONS_DEFAULT_STDOUT_REDIRECTED = OUT_RESP_BODY
class Parser(ArgumentParser):
class HTTPieArgumentParser(ArgumentParser):
"""Adds additional logic to `argparse.ArgumentParser`.
Handles all input (CLI args, file args, stdin), applies defaults,
@ -113,13 +113,13 @@ class Parser(ArgumentParser):
def __init__(self, *args, **kwargs):
kwargs['add_help'] = False
super(Parser, self).__init__(*args, **kwargs)
super(HTTPieArgumentParser, self).__init__(*args, **kwargs)
# noinspection PyMethodOverriding
def parse_args(self, env, args=None, namespace=None):
self.env = env
self.args, no_options = super(Parser, self)\
self.args, no_options = super(HTTPieArgumentParser, self)\
.parse_known_args(args, namespace)
if self.args.debug:
@ -164,7 +164,7 @@ class Parser(ArgumentParser):
}.get(file, file)
if not hasattr(file, 'buffer') and isinstance(message, str):
message = message.encode(self.env.stdout_encoding)
super(Parser, self)._print_message(message, file)
super(HTTPieArgumentParser, self)._print_message(message, file)
def _setup_standard_streams(self):
"""

View File

@ -201,7 +201,7 @@ class TestURLshorthand:
class TestArgumentParser:
def setup_method(self, method):
self.parser = input.Parser()
self.parser = input.HTTPieArgumentParser()
def test_guess_when_method_set_and_valid(self):
self.parser.args = argparse.Namespace()