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


Python pyparsing.Suppress方法代码示例

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


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

示例1: getLogLineBNF

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Suppress [as 别名]
def getLogLineBNF():
    global logLineBNF
    
    if logLineBNF is None:
        integer = Word( nums )
        ipAddress = delimitedList( integer, ".", combine=True )
        
        timeZoneOffset = Word("+-",nums)
        month = Word(string.uppercase, string.lowercase, exact=3)
        serverDateTime = Group( Suppress("[") + 
                                Combine( integer + "/" + month + "/" + integer +
                                        ":" + integer + ":" + integer + ":" + integer ) +
                                timeZoneOffset + 
                                Suppress("]") )
                         
        logLineBNF = ( ipAddress.setResultsName("ipAddr") + 
                       Suppress("-") +
                       ("-" | Word( alphas+nums+"@._" )).setResultsName("auth") +
                       serverDateTime.setResultsName("timestamp") + 
                       dblQuotedString.setResultsName("cmd").setParseAction(getCmdFields) +
                       (integer | "-").setResultsName("statusCode") + 
                       (integer | "-").setResultsName("numBytesSent")  + 
                       dblQuotedString.setResultsName("referrer").setParseAction(removeQuotes) +
                       dblQuotedString.setResultsName("clientSfw").setParseAction(removeQuotes) )
    return logLineBNF 
开发者ID:nil0x42,项目名称:phpsploit,代码行数:27,代码来源:httpServerLogParser.py

示例2: _globalParse___stp_attributes

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Suppress [as 别名]
def _globalParse___stp_attributes(stp, dct):
    parse_portfast = Suppress('portfast ') + restOfLine
    parse_bpdu = Suppress('portfast bpduguard ') + restOfLine
    parse_loop = Suppress('loopguard ') + restOfLine
    try:
        return util.int_dict_parse(parse_bpdu, stp, 'bpduguard', dct)
    except ParseException:
        pass
    try:
        return util.int_dict_parse(parse_loop, stp, 'loopguard', dct)
    except ParseException:
        pass
    try:
        return util.int_dict_parse(parse_portfast, stp, 'portfast', dct)
    except ParseException:
        pass
    return 0 
开发者ID:cisco-config-analysis-tool,项目名称:ccat,代码行数:19,代码来源:stp_global.py

示例3: _globalParse___username_attributes

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Suppress [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

示例4: __ifaceAttributes___storm_check

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Suppress [as 别名]
def __ifaceAttributes___storm_check(storm,dct):

    parse_level  = Word(alphas)        + Suppress('level ')            + restOfLine
    parse_action = Suppress('action ') + Word(alphas)
    parse_type   = Word(alphas)        + Suppress(Optional("include")) + Word(alphas)
    try:
        value = parse_level.parseString(storm).asList()
        if 'level' in dct:
            dct['level'].append(value)
        else:
            dct['level'] = [value]
        return dct
    except ParseException:
        pass
    try:
        return util.int_dict_parse(parse_action, storm, 'action', dct)
    except ParseException:
        pass
    try:
        return util.int_dict_parse(parse_type,   storm, 'type',   dct)
    except ParseException:
        pass 
开发者ID:cisco-config-analysis-tool,项目名称:ccat,代码行数:24,代码来源:storm_control.py

示例5: parse

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Suppress [as 别名]
def parse(input_string):
        word = Word(alphanums)
        command = Group(OneOrMore(word))
        token = Suppress("->")
        device = Group(OneOrMore(word))
        argument = Group(OneOrMore(word))
        event = command + token + device + Optional(token + argument)
        parse_results = event.parseString(input_string)
        cmd = parse_results[0]
        dev = parse_results[1]
        cmd_str = "_".join(cmd)
        dev_str = "_".join(dev)
        try:
            val = parse_results[2]
        except IndexError:
            val_str = None
        else:
            val_str = "_".join(val)
        return cmd_str, dev_str, val_str 
开发者ID:jackdbd,项目名称:design-patterns,代码行数:21,代码来源:interpreter.py

示例6: grammar

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Suppress [as 别名]
def grammar():
    parenthesis = Forward()
    parenthesis <<= "(" + ZeroOrMore(CharsNotIn("()") | parenthesis) + ")"

    field_def = OneOrMore(Word(alphanums + "_\"'`:-") | parenthesis)
    field_def.setParseAction(field_act)

    tablename_def = ( Word(alphas + "`_") | QuotedString("\"") )

    field_list_def = field_def + ZeroOrMore(Suppress(",") + field_def)
    field_list_def.setParseAction(field_list_act)

    create_table_def = Literal("CREATE") + "TABLE" + tablename_def.setResultsName("tableName") + "(" + field_list_def.setResultsName("fields") + ")" + ";"
    create_table_def.setParseAction(create_table_act)

    add_fkey_def = Literal("FOREIGN") + "KEY" + "(" + Word(alphanums).setResultsName("keyName") + ")" + "REFERENCES" + Word(alphanums).setResultsName("fkTable") + "(" + Word(alphanums + "_").setResultsName("fkCol") + ")" + Optional(Literal("DEFERRABLE")) + ";"
    add_fkey_def.setParseAction(add_fkey_act)

    other_statement_def = OneOrMore(CharsNotIn(";")) + ";"
    other_statement_def.setParseAction(other_statement_act)

    comment_def = "--" + ZeroOrMore(CharsNotIn("\n"))
    comment_def.setParseAction(other_statement_act)

    return OneOrMore(comment_def | create_table_def | add_fkey_def | other_statement_def) 
开发者ID:LGE-ARC-AdvancedAI,项目名称:auptimizer,代码行数:27,代码来源:sql_graphviz.py

示例7: _parse

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Suppress [as 别名]
def _parse(mystr):

    LBRACE, RBRACE, EQUAL = map(pp.Suppress, "{}=")
    field = pp.Word(pp.printables + ' ', excludeChars='[]=')
    field.addParseAction(pp.tokenMap(str.rstrip))
    string = pp.dblQuotedString().setParseAction(pp.removeQuotes)
    number = pp.pyparsing_common.number()
    date_expr = pp.Regex(r'\d\d\d\d-\d\d-\d\d')
    time_expr = pp.Regex(r'\d\d:\d\d:\d\d\.\d\d\d')
    nan = pp.Keyword('nan')
    scalar_value = (string | date_expr | time_expr | number | nan)

    list_marker = pp.Suppress("[]")
    value_list = pp.Forward()
    jobject = pp.Forward()

    memberDef1 = pp.Group(field + EQUAL + scalar_value)
    memberDef2 = pp.Group(field + EQUAL + jobject)
    memberDef3 = pp.Group(field + list_marker + EQUAL + LBRACE + value_list +
                          RBRACE)
    memberDef = memberDef1 | memberDef2 | memberDef3

    value_list <<= (pp.delimitedList(scalar_value, ",") |
                    pp.ZeroOrMore(pp.Group(pp.Dict(memberDef2))))
    value_list.setParseAction(lambda t: [pp.ParseResults(t[:])])

    members = pp.OneOrMore(memberDef)
    jobject <<= pp.Dict(LBRACE + pp.ZeroOrMore(memberDef) + RBRACE)
    # force empty jobject to be a dict
    jobject.setParseAction(lambda t: t or {})

    parser = members
    parser = pp.OneOrMore(pp.Group(pp.Dict(memberDef)))

    return parser.parseString(mystr) 
开发者ID:matthewgilbert,项目名称:pdblp,代码行数:37,代码来源:parser.py

示例8: parse

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Suppress [as 别名]
def parse(self, flags):
        _flags = []
        for k, v in flags.items():
            if v == True:
                _flags.append(k)
            elif v in [False, None]:
                pass
            else:
                _flags.append(k + "_" + v)

        def cb_conditional(s, l, t):
            if (t.cond in _flags) != (t.negate == "!"):
                return t.expr
            else:
                return []

        word = Word(alphanums + ":<>.[]_-,=~/^~")
        conditional = Forward()
        conditional << (
            Optional("!")("negate")
            + word("cond")
            + Suppress("?")
            + Suppress("(")
            + OneOrMore(conditional ^ word)("expr")
            + Suppress(")")
        ).setParseAction(cb_conditional)
        string = word
        string_list = OneOrMore(conditional ^ string)
        s = " ".join(string_list.parseString(self.__str__()))
        logger.debug(
            "Parsing '{}' with flags {} => {}".format(self.__str__(), str(_flags), s)
        )
        return s 
开发者ID:olofk,项目名称:fusesoc,代码行数:35,代码来源:core.py

示例9: parse_line

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Suppress [as 别名]
def parse_line(attribute, string):

    Grammar = Suppress(Keyword('mpc.{}'.format(attribute)) + Keyword('=')) + String('data') + Suppress(Literal(';') + Optional(Comments))
    result, i, j = Grammar.scanString(string).next()

    return [int_else_float_except_string(s) for s in result['data'].asList()] 
开发者ID:power-system-simulation-toolbox,项目名称:psst,代码行数:8,代码来源:case_parser.py

示例10: parse_table

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Suppress [as 别名]
def parse_table(attribute, string):
    Line = OneOrMore(Float)('data') + Literal(';') + Optional(Comments, default='')('name')
    Grammar = Suppress(Keyword('mpc.{}'.format(attribute)) + Keyword('=') + Keyword('[') + Optional(Comments)) + OneOrMore(Group(Line)) + Suppress(Keyword(']') + Optional(Comments))

    result, i, j = Grammar.scanString(string).next()

    _list = list()
    for r in result:
        _list.append([int_else_float_except_string(s) for s in r['data'].asList()])

    return _list 
开发者ID:power-system-simulation-toolbox,项目名称:psst,代码行数:13,代码来源:case_parser.py

示例11: __init__

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Suppress [as 别名]
def __init__(self):
        # create parsing grammer
        sQStringLiteral = pyparsing.QuotedString("'")
        sQStringLiteral.setParseAction(
            lambda s, loc, toks: StringLiteral(s, loc, toks, False))

        dQStringLiteral = pyparsing.QuotedString('"', '\\')
        dQStringLiteral.setParseAction(
            lambda s, loc, toks: StringLiteral(s, loc, toks, True))

        stringLiteral = sQStringLiteral | dQStringLiteral

        functionCall = pyparsing.Forward()
        functionArg = stringLiteral | functionCall
        functionCall << pyparsing.Word(pyparsing.alphas, pyparsing.alphanums+'-') + \
            pyparsing.Suppress('(') + \
            pyparsing.Optional(functionArg +
                pyparsing.ZeroOrMore(pyparsing.Suppress(',') + functionArg)) + \
            pyparsing.Suppress(')')
        functionCall.setParseAction(
            lambda s, loc, toks: FunctionCall(s, loc, toks))

        predExpr = pyparsing.infixNotation(
            stringLiteral ^ functionCall ,
            [
                ('!',  1, pyparsing.opAssoc.RIGHT, lambda s, loc, toks: NotOperator(s, loc, toks)),
                ('<',  2, pyparsing.opAssoc.LEFT,  infixBinaryOp(BinaryStrOperator)),
                ('<=', 2, pyparsing.opAssoc.LEFT,  infixBinaryOp(BinaryStrOperator)),
                ('>',  2, pyparsing.opAssoc.LEFT,  infixBinaryOp(BinaryStrOperator)),
                ('>=', 2, pyparsing.opAssoc.LEFT,  infixBinaryOp(BinaryStrOperator)),
                ('==', 2, pyparsing.opAssoc.LEFT,  infixBinaryOp(BinaryStrOperator)),
                ('!=', 2, pyparsing.opAssoc.LEFT,  infixBinaryOp(BinaryStrOperator)),
                ('&&', 2, pyparsing.opAssoc.LEFT,  infixBinaryOp(BinaryBoolOperator)),
                ('||', 2, pyparsing.opAssoc.LEFT,  infixBinaryOp(BinaryBoolOperator))
            ])

        self.__ifgrammer = predExpr 
开发者ID:BobBuildTool,项目名称:bob,代码行数:39,代码来源:stringparser.py

示例12: get_attributes

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Suppress [as 别名]
def get_attributes(config):
    options_list = []
    option = White(exact=1) + Suppress(Optional(White())) + restOfLine
    next_line = config.readline()
    try:
        option_parse = option.parseString(next_line)
        while option_parse[0] == ' ':
            options_list.append(option_parse[-1])
            next_line = config.readline()
            option_parse = option.parseString(next_line)
    except:
        pass
    return options_list, next_line 
开发者ID:cisco-config-analysis-tool,项目名称:ccat,代码行数:15,代码来源:util.py

示例13: __ifaceAttributes___port_sec_parse

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Suppress [as 别名]
def __ifaceAttributes___port_sec_parse(port, dct):
    parse_aging_time = Suppress('aging time ') + restOfLine
    parse_aging_type = Suppress('aging type ') + restOfLine
    parse_violat = Suppress('violation ') + restOfLine
    parse_max = Suppress('maximum ') + restOfLine
    parse_mac = Suppress('mac-address ') + Optional('sticky') + restOfLine
    try:
        return util.int_dict_parse(parse_aging_time, port, 'aging time', dct)
    except ParseException:
        pass
    try:
        return util.int_dict_parse(parse_aging_type, port, 'aging type', dct)
    except ParseException:
        pass
    try:
        return util.int_dict_parse(parse_violat, port, 'violation', dct)
    except ParseException:
        pass
    try:
        return util.int_dict_parse(parse_mac, port, 'mac-address', dct)
    except ParseException:
        pass
    try:
        return util.int_dict_parse(parse_max, port, 'maximum', dct)
    except ParseException:
        pass 
开发者ID:cisco-config-analysis-tool,项目名称:ccat,代码行数:28,代码来源:port_security.py

示例14: __ifaceAttributes___ip_parse

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Suppress [as 别名]
def __ifaceAttributes___ip_parse(value, dct):
    parse_mode = Word(alphas)
    parse_rate = Suppress('limit rate ') + restOfLine
    try:
        return util.int_dict_parse(parse_rate, value, 'limit', dct)
    except ParseException:
        pass
    try:
        return util.int_dict_parse(parse_mode, value, 'mode', dct)
    except ParseException:
        pass 
开发者ID:cisco-config-analysis-tool,项目名称:ccat,代码行数:13,代码来源:ip_iface.py

示例15: _globalParse___vtp_attributes

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Suppress [as 别名]
def _globalParse___vtp_attributes(vtp, dct):
    parse_domain = Suppress('domain ') + restOfLine
    parse_mode = Suppress('mode ') + restOfLine
    try:
        return util.int_dict_parse(parse_domain, vtp, 'domain', dct)
    except ParseException:
        pass
    try:
        return util.int_dict_parse(parse_mode, vtp, 'mode', dct)
    except ParseException:
        pass
    return 0 
开发者ID:cisco-config-analysis-tool,项目名称:ccat,代码行数:14,代码来源:vtp.py


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