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


Python exceptions.ParseError方法代码示例

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


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

示例1: _token_led_lparen

# 需要导入模块: from jmespath import exceptions [as 别名]
# 或者: from jmespath.exceptions import ParseError [as 别名]
def _token_led_lparen(self, left):
        if left['type'] != 'field':
            #  0 - first func arg or closing paren.
            # -1 - '(' token
            # -2 - invalid function "name".
            prev_t = self._lookahead_token(-2)
            raise exceptions.ParseError(
                prev_t['start'], prev_t['value'], prev_t['type'],
                "Invalid function name '%s'" % prev_t['value'])
        name = left['value']
        args = []
        while not self._current_token() == 'rparen':
            expression = self._expression()
            if self._current_token() == 'comma':
                self._match('comma')
            args.append(expression)
        self._match('rparen')
        function_node = ast.function_expression(name, args)
        return function_node 
开发者ID:skarlekar,项目名称:faces,代码行数:21,代码来源:parser.py

示例2: _parse_slice_expression

# 需要导入模块: from jmespath import exceptions [as 别名]
# 或者: from jmespath.exceptions import ParseError [as 别名]
def _parse_slice_expression(self):
        # [start:end:step]
        # Where start, end, and step are optional.
        # The last colon is optional as well.
        parts = [None, None, None]
        index = 0
        current_token = self._current_token()
        while not current_token == 'rbracket' and index < 3:
            if current_token == 'colon':
                index += 1
                self._advance()
            elif current_token == 'number':
                parts[index] = self._lookahead_token(0)['value']
                self._advance()
            else:
                t = self._lookahead_token(0)
                lex_position = t['start']
                actual_value = t['value']
                actual_type = t['type']
                raise exceptions.ParseError(lex_position, actual_value,
                                            actual_type, 'syntax error')
            current_token = self._current_token()
        self._match('rbracket')
        return ast.slice(*parts) 
开发者ID:awslabs,项目名称:mxnet-lambda,代码行数:26,代码来源:parser.py

示例3: _match

# 需要导入模块: from jmespath import exceptions [as 别名]
# 或者: from jmespath.exceptions import ParseError [as 别名]
def _match(self, token_type=None):
        # inline'd self._current_token()
        if self._current_token() == token_type:
            # inline'd self._advance()
            self._advance()
        else:
            t = self._lookahead_token(0)
            lex_position = t['start']
            actual_value = t['value']
            actual_type = t['type']
            if actual_type == 'eof':
                raise exceptions.IncompleteExpressionError(
                    lex_position, actual_value, actual_type)
            else:
                message = 'Expecting: %s, got: %s' % (token_type,
                                                      actual_type)
            raise exceptions.ParseError(
                lex_position, actual_value, actual_type, message) 
开发者ID:awslabs,项目名称:mxnet-lambda,代码行数:20,代码来源:parser.py

示例4: _parse_projection_rhs

# 需要导入模块: from jmespath import exceptions [as 别名]
# 或者: from jmespath.exceptions import ParseError [as 别名]
def _parse_projection_rhs(self, binding_power):
        # Parse the right hand side of the projection.
        if self.BINDING_POWER[self._current_token()] < 10:
            # BP of 10 are all the tokens that stop a projection.
            right = ast.identity()
        elif self._current_token() == 'lbracket':
            right = self._expression(binding_power)
        elif self._current_token() == 'filter':
            right = self._expression(binding_power)
        elif self._current_token() == 'dot':
            self._match('dot')
            right = self._parse_dot_rhs(binding_power)
        else:
            t = self._lookahead_token(0)
            lex_position = t['start']
            actual_value = t['value']
            actual_type = t['type']
            raise exceptions.ParseError(lex_position, actual_value,
                                        actual_type, 'syntax error')
        return right 
开发者ID:TencentCloud,项目名称:tencentcloud-cli,代码行数:22,代码来源:parser.py

示例5: _do_parse

# 需要导入模块: from jmespath import exceptions [as 别名]
# 或者: from jmespath.exceptions import ParseError [as 别名]
def _do_parse(self, expression):
        try:
            return self._parse(expression)
        except exceptions.LexerError as e:
            e.expression = expression
            raise
        except exceptions.IncompleteExpressionError as e:
            e.set_expression(expression)
            raise
        except exceptions.ParseError as e:
            e.expression = expression
            raise 
开发者ID:skarlekar,项目名称:faces,代码行数:14,代码来源:parser.py

示例6: _parse

# 需要导入模块: from jmespath import exceptions [as 别名]
# 或者: from jmespath.exceptions import ParseError [as 别名]
def _parse(self, expression):
        self.tokenizer = lexer.Lexer().tokenize(expression)
        self._tokens = list(self.tokenizer)
        self._index = 0
        parsed = self._expression(binding_power=0)
        if not self._current_token() == 'eof':
            t = self._lookahead_token(0)
            raise exceptions.ParseError(t['start'], t['value'], t['type'],
                                        "Unexpected token: %s" % t['value'])
        return ParsedResult(expression, parsed) 
开发者ID:skarlekar,项目名称:faces,代码行数:12,代码来源:parser.py

示例7: _token_nud_quoted_identifier

# 需要导入模块: from jmespath import exceptions [as 别名]
# 或者: from jmespath.exceptions import ParseError [as 别名]
def _token_nud_quoted_identifier(self, token):
        field = ast.field(token['value'])
        # You can't have a quoted identifier as a function
        # name.
        if self._current_token() == 'lparen':
            t = self._lookahead_token(0)
            raise exceptions.ParseError(
                0, t['value'], t['type'],
                'Quoted identifier not allowed for function names.')
        return field 
开发者ID:skarlekar,项目名称:faces,代码行数:12,代码来源:parser.py

示例8: _raise_parse_error_for_token

# 需要导入模块: from jmespath import exceptions [as 别名]
# 或者: from jmespath.exceptions import ParseError [as 别名]
def _raise_parse_error_for_token(self, token, reason):
        lex_position = token['start']
        actual_value = token['value']
        actual_type = token['type']
        raise exceptions.ParseError(lex_position, actual_value,
                                    actual_type, reason) 
开发者ID:skarlekar,项目名称:faces,代码行数:8,代码来源:parser.py

示例9: main

# 需要导入模块: from jmespath import exceptions [as 别名]
# 或者: from jmespath.exceptions import ParseError [as 别名]
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('expression')
    parser.add_argument('-f', '--filename',
                        help=('The filename containing the input data.  '
                              'If a filename is not given then data is '
                              'read from stdin.'))
    parser.add_argument('--ast', action='store_true',
                        help=('Pretty print the AST, do not search the data.'))
    args = parser.parse_args()
    expression = args.expression
    if args.ast:
        # Only print the AST
        expression = jmespath.compile(args.expression)
        sys.stdout.write(pformat(expression.parsed))
        sys.stdout.write('\n')
        return 0
    if args.filename:
        with open(args.filename, 'r') as f:
            data = json.load(f)
    else:
        data = sys.stdin.read()
        data = json.loads(data)
    try:
        sys.stdout.write(json.dumps(
            jmespath.search(expression, data), indent=4))
        sys.stdout.write('\n')
    except exceptions.ArityError as e:
        sys.stderr.write("invalid-arity: %s\n" % e)
        return 1
    except exceptions.JMESPathTypeError as e:
        sys.stderr.write("invalid-type: %s\n" % e)
        return 1
    except exceptions.UnknownFunctionError as e:
        sys.stderr.write("unknown-function: %s\n" % e)
        return 1
    except exceptions.ParseError as e:
        sys.stderr.write("syntax-error: %s\n" % e)
        return 1 
开发者ID:QData,项目名称:deepWordBug,代码行数:41,代码来源:jp.py

示例10: _raise_parse_error_maybe_eof

# 需要导入模块: from jmespath import exceptions [as 别名]
# 或者: from jmespath.exceptions import ParseError [as 别名]
def _raise_parse_error_maybe_eof(self, expected_type, token):
        lex_position = token['start']
        actual_value = token['value']
        actual_type = token['type']
        if actual_type == 'eof':
            raise exceptions.IncompleteExpressionError(
                lex_position, actual_value, actual_type)
        message = 'Expecting: %s, got: %s' % (expected_type,
                                              actual_type)
        raise exceptions.ParseError(
            lex_position, actual_value, actual_type, message) 
开发者ID:QData,项目名称:deepWordBug,代码行数:13,代码来源:parser.py

示例11: _parse_dot_rhs

# 需要导入模块: from jmespath import exceptions [as 别名]
# 或者: from jmespath.exceptions import ParseError [as 别名]
def _parse_dot_rhs(self, binding_power):
        # From the grammar:
        # expression '.' ( identifier /
        #                  multi-select-list /
        #                  multi-select-hash /
        #                  function-expression /
        #                  *
        # In terms of tokens that means that after a '.',
        # you can have:
        lookahead = self._current_token()
        # Common case "foo.bar", so first check for an identifier.
        if lookahead in ['quoted_identifier', 'unquoted_identifier', 'star']:
            return self._expression(binding_power)
        elif lookahead == 'lbracket':
            self._match('lbracket')
            return self._parse_multi_select_list()
        elif lookahead == 'lbrace':
            self._match('lbrace')
            return self._parse_multi_select_hash()
        else:
            t = self._lookahead_token(0)
            allowed = ['quoted_identifier', 'unquoted_identifier',
                       'lbracket', 'lbrace']
            lex_position = t['start']
            actual_value = t['value']
            actual_type = t['type']
            raise exceptions.ParseError(
                lex_position, actual_value, actual_type,
                "Expecting: %s, got: %s" % (allowed,
                                            actual_type)) 
开发者ID:awslabs,项目名称:mxnet-lambda,代码行数:32,代码来源:parser.py

示例12: _assert_not_token

# 需要导入模块: from jmespath import exceptions [as 别名]
# 或者: from jmespath.exceptions import ParseError [as 别名]
def _assert_not_token(self, *token_types):
        if self._current_token() in token_types:
            t = self._lookahead_token(0)
            lex_position = t['start']
            actual_value = t['value']
            actual_type = t['type']
            raise exceptions.ParseError(
                lex_position, actual_value, actual_type,
                "Token %s not allowed to be: %s" % (actual_type, token_types)) 
开发者ID:awslabs,项目名称:mxnet-lambda,代码行数:11,代码来源:parser.py


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