Python pyparsing.restOfLine() Examples

The following are 2 code examples of pyparsing.restOfLine(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pyparsing , or try the search function .
Example #1
Source File: ssh.py    From ccat with GNU General Public License v3.0 6 votes vote down vote up
def _globalParse___ssh_attributes(line):
    ssh_dict = {}

    ssh_option = (Word(alphas + '-'))('option')
    ssh_value  = (restOfLine)        ('value')

    result     = (ssh_option + White() + ssh_value).parseString(line)

    if   result.option == 'logging':
        ssh_dict['logging-events']         = 'yes'
    elif result.option == 'authentication-retries':
        ssh_dict['authentication_retries'] = result.value.split()[0]
    elif result.option == 'port':
        ssh_dict['port_rotary']            = result.value.split()[0]
    elif result.option == 'maxstartups':
        ssh_dict['maxstartups']            = result.value.split()[0]
    elif result.option == 'time-out':
        ssh_dict['time-out']               = result.value.split()[0]
    elif result.option == 'version':
        ssh_dict['version']                = result.value.split()[0]

    return ssh_dict 
Example #2
Source File: username.py    From ccat with GNU General Public License v3.0 6 votes vote down vote up
def _globalParse___username_attributes(line):
    username_dict = {}

    username       = (Word(printables))                                         ('user')
    privilege      = (Suppress('privilege') + Word(nums))                       ('priv_num')
    password_type  = (Suppress(MatchFirst(['secret', 'password'])) + Word(nums))('pass_type')

    parse_username = username + Optional(privilege) + password_type + Suppress(restOfLine)

    result = parse_username.parseString(line)

    username_dict[result.user] = {}
    username_dict[result.user]['password_type'] = result.pass_type.asList()[0]

    try:
        username_dict[result.user]['privilege'] = result.priv_num.asList()[0]
    except AttributeError:
        pass

    return username_dict