當前位置: 首頁>>代碼示例>>Python>>正文


Python pyparsing.MatchFirst方法代碼示例

本文整理匯總了Python中pyparsing.MatchFirst方法的典型用法代碼示例。如果您正苦於以下問題:Python pyparsing.MatchFirst方法的具體用法?Python pyparsing.MatchFirst怎麽用?Python pyparsing.MatchFirst使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyparsing的用法示例。


在下文中一共展示了pyparsing.MatchFirst方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _globalParse___username_attributes

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import MatchFirst [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: get_protein_modification_language

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import MatchFirst [as 別名]
def get_protein_modification_language(concept_qualified: ParserElement) -> ParserElement:
    """Build a protein modification parser."""
    pmod_concept = MatchFirst([
        concept_qualified,
        pmod_default_ns,
        pmod_legacy_ns,
    ])

    return pmod_tag + nest(
        Group(pmod_concept)(CONCEPT)
        + Optional(
            WCW
            + amino_acid(PMOD_CODE)
            + Optional(WCW + ppc.integer(PMOD_POSITION)),
        ),
    ) 
開發者ID:pybel,項目名稱:pybel,代碼行數:18,代碼來源:protein_modification.py

示例3: _globalParse___aaa_attributes

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import MatchFirst [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

示例4: get_gene_modification_language

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import MatchFirst [as 別名]
def get_gene_modification_language(concept_qualified: ParserElement) -> ParserElement:
    """Build a gene modification parser."""
    concept = MatchFirst([
        concept_qualified,
        gmod_default_ns,
    ])
    return gmod_tag + nest(Group(concept)(CONCEPT)) 
開發者ID:pybel,項目名稱:pybel,代碼行數:9,代碼來源:gene_modification.py

示例5: flatten_pyparsing_exprs

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import MatchFirst [as 別名]
def flatten_pyparsing_exprs(expr):
    exprs = set()
    for child in expr.exprs:
        if isinstance(child, (Literal, six.string_types)):
            exprs.add(str(child).strip('"'))
        elif isinstance(child, (MatchFirst, ParseExpression, ParserElement)):
            exprs.update(flatten_pyparsing_exprs(child))
    return exprs 
開發者ID:sarugaku,項目名稱:requirementslib,代碼行數:10,代碼來源:strategies.py

示例6: _process_rules_group

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import MatchFirst [as 別名]
def _process_rules_group(self, rules):
        group = None

        group_type = rules.list_type
        data = rules.rules

        if group_type == 'sequence':
            group = self._process_rules(data, pp.And)
        elif group_type == 'option':
            group = self._process_rules(data, pp.MatchFirst)
        elif group_type == 'optional':
            group = pp.Optional(self._process_rules(data, pp.And))

        return group 
開發者ID:weso,項目名稱:CWR-DataApi,代碼行數:16,代碼來源:rule.py


注:本文中的pyparsing.MatchFirst方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。