本文整理汇总了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
示例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)
示例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)
示例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
示例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
示例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)
示例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
示例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)
示例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
示例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)
示例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))
示例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))