Python pyparsing.printables() Examples

The following are 2 code examples of pyparsing.printables(). 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: 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 
Example #2
Source File: aaa.py    From ccat with GNU General Public License v3.0 5 votes vote down vote up
def _globalParse___aaa_attributes(line, type, count_aaa):
    aaa_dict = {}

    authentication_list    = (Suppress('login')                     + Word(printables))  ('authent_list')
    authentication_groups  = (OneOrMore(Optional(Suppress('group')) + Word(printables))) ('authent_methods')

    parse_authentication   = authentication_list + authentication_groups

    # parse_authorization_options  = MatchFirst(['exec', 'login']) + Word(printables) + OneOrMore(Optional(Suppress('group')) + Word(printables))

    accounting_login   = (MatchFirst(['exec', 'network', 'connection', 'commands'])) ('acc_login')
    accounting_list    = (Optional(Word(nums)) + Word(printables))                   ('acc_list')
    accounting_record  = (MatchFirst(['start-stop', 'stop-only', 'stop']))           ('acc_record')
    accounting_methods = (OneOrMore(Optional(Suppress('group')) + Word(printables))) ('acc_methods')

    parse_accounting   = accounting_login + accounting_list + accounting_record + accounting_methods

    if   type == 'authentication':
        result = parse_authentication.parseString(line)
        aaa_dict.update({'login' + str(count_aaa): {}})
        aaa_dict['login' + str(count_aaa)]['list']    = result.authent_list[0]
        aaa_dict['login' + str(count_aaa)]['methods'] = result.authent_methods.asList()
    # elif type == 'authorization':
    #     result = parse_authorization_options.parseString(line)
    #     aaa_dict.update({'login' + str(count_aaa): {}})
    #     aaa_dict['login' + str(count_aaa)]['login']   = result.pop(0)
    #     aaa_dict['login' + str(count_aaa)]['list']    = result.pop(0)
    #     aaa_dict['login' + str(count_aaa)]['methods'] = result.asList()
    elif type == 'accounting':
        result = parse_accounting.parseString(line)
        aaa_dict.update({'login' + str(count_aaa): {}})
        aaa_dict['login' + str(count_aaa)]['login']   = result.acc_login
        aaa_dict['login' + str(count_aaa)]['list']    = result.acc_list.asList()
        aaa_dict['login' + str(count_aaa)]['record']  = result.acc_record
        aaa_dict['login' + str(count_aaa)]['methods'] = result.acc_methods.asList()

    return aaa_dict