当前位置: 首页>>代码示例>>Python>>正文


Python pyparsing.printables方法代码示例

本文整理汇总了Python中pyparsing.printables方法的典型用法代码示例。如果您正苦于以下问题:Python pyparsing.printables方法的具体用法?Python pyparsing.printables怎么用?Python pyparsing.printables使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyparsing的用法示例。


在下文中一共展示了pyparsing.printables方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _globalParse___username_attributes

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import printables [as 别名]
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 
开发者ID:cisco-config-analysis-tool,项目名称:ccat,代码行数:22,代码来源:username.py

示例2: _globalParse___aaa_attributes

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import printables [as 别名]
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 
开发者ID:cisco-config-analysis-tool,项目名称:ccat,代码行数:39,代码来源:aaa.py


注:本文中的pyparsing.printables方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。