Esempio n. 1
0
    def __init__(self, *args, **kwargs):
        super(BaseShell, self).__init__(*args, **kwargs)

        # characters preceding the cursor when prompting for command entry
        self.prompt = '> '

        # text to be displayed upon launch of the shell, before displaying
        # the interactive prompt
        self.banner_text = None

        # Flag indicating whether this shell should be closed after the current
        # command finishes processing
        self._done = False

        # Command parser API for parsing tokens from command lines
        self._parser = default_line_parser()

        # input redirection to use instead of the default stdin
        self._input_stream = None

        # parent Friendly Shell this shell runs under
        # only used for nested sub-shells
        self._parent = None

        # default comment delimiter
        self.comment_delimiter = "#"

        # error code / return value produced by this shell
        self._return_code = 0
Esempio n. 2
0
def test_no_params():
    parser = default_line_parser()
    res = parser.parseString('MyCommand')

    assert res is not None
    assert res.command == 'MyCommand'
    assert len(res.params) == 0
Esempio n. 3
0
def test_params_with_nested_double_quotes():
    parser = default_line_parser()
    res = parser.parseString("MyCommand 'param with \"double quotes\"'")

    assert res is not None
    assert res.command == 'MyCommand'
    assert len(res.params) == 1
    assert res.params[0] == '\'param with "double quotes"\''
Esempio n. 4
0
def test_params_with_nested_quotes():
    parser = default_line_parser()
    res = parser.parseString('MyCommand "param with \'quotes\'"')

    assert res is not None
    assert res.command == 'MyCommand'
    assert len(res.params) == 1
    assert res.params[0] == "\"param with 'quotes'\""
Esempio n. 5
0
def test_params_with_spaces():
    parser = default_line_parser()
    res = parser.parseString("MyCommand 'param with spaces'")

    assert res is not None
    assert res.command == 'MyCommand'
    assert len(res.params) == 1
    assert res.params[0] == "'param with spaces'"
Esempio n. 6
0
def test_single_quoted_param():
    parser = default_line_parser()
    res = parser.parseString("MyCommand 'param1'")

    assert res is not None
    assert res.command == 'MyCommand'
    assert len(res.params) == 1
    assert res.params[0] == "'param1'"
Esempio n. 7
0
def test_quoted_param():
    parser = default_line_parser()
    res = parser.parseString('MyCommand "param1"')

    assert res is not None
    assert res.command == 'MyCommand'
    assert len(res.params) == 1
    assert res.params[0] == '"param1"'
Esempio n. 8
0
def test_incomplete_single_quotes():
    parser = default_line_parser()
    res = parser.parseString("MyCommand first_param '")
    assert res is not None
    assert res.command == "MyCommand"
    assert len(res.params) == 2
    assert res.params[0] == "first_param"
    assert res.params[1] == "'"
Esempio n. 9
0
def test_partial_completion_double_quotes():
    parser = default_line_parser()
    res = parser.parseString("MyCommand first_param \"partial")
    assert res is not None
    assert res.command == "MyCommand"
    assert len(res.params) == 2
    assert res.params[0] == "first_param"
    assert res.params[1] == "\"partial"
Esempio n. 10
0
def test_params_whitespace():
    parser = default_line_parser()
    res = parser.parseString('   MyCommand      param1   param2')

    assert res is not None
    assert res.command == 'MyCommand'
    assert len(res.params) == 2
    assert res.params[0] == 'param1'
    assert res.params[1] == 'param2'
Esempio n. 11
0
def test_nested_quoted_param():
    parser = default_line_parser()
    res = parser.parseString(
        "MyCommand first_param \"second param\" third_param")
    assert res is not None
    assert res.command == "MyCommand"
    assert len(res.params) == 3
    assert res.params[0] == "first_param"
    assert res.params[1] == "\"second param\""
    assert res.params[2] == "third_param"
Esempio n. 12
0
def test_mixed_param_quotes():
    parser = default_line_parser()
    res = parser.parseString(
        "MyCommand first_param \"second param\" 'third param' fourth_param")
    assert res is not None
    assert res.command == "MyCommand"
    assert len(res.params) == 4
    assert res.params[0] == "first_param"
    assert res.params[1] == "\"second param\""
    assert res.params[2] == "'third param'"
    assert res.params[3] == "fourth_param"