本文整理汇总了Python中jmespath.exceptions.EmptyExpressionError方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.EmptyExpressionError方法的具体用法?Python exceptions.EmptyExpressionError怎么用?Python exceptions.EmptyExpressionError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jmespath.exceptions
的用法示例。
在下文中一共展示了exceptions.EmptyExpressionError方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _initialize_for_expression
# 需要导入模块: from jmespath import exceptions [as 别名]
# 或者: from jmespath.exceptions import EmptyExpressionError [as 别名]
def _initialize_for_expression(self, expression):
if not expression:
raise EmptyExpressionError()
self._position = 0
self._expression = expression
self._chars = list(self._expression)
self._current = self._chars[self._position]
self._length = len(self._expression)
示例2: tokenize
# 需要导入模块: from jmespath import exceptions [as 别名]
# 或者: from jmespath.exceptions import EmptyExpressionError [as 别名]
def tokenize(self, expression):
if not expression:
raise EmptyExpressionError()
previous_column = 0
for match in self.master_regex.finditer(expression):
value = match.group()
start = match.start()
end = match.end()
if match.lastgroup == 'skip':
# Ignore whitespace.
previous_column = end
continue
if start != previous_column:
bad_value = expression[previous_column:start]
# Try to give a good error message.
if bad_value == '"':
raise LexerError(
lexer_position=previous_column,
lexer_value=value,
message='Starting quote is missing the ending quote',
expression=expression)
raise LexerError(lexer_position=previous_column,
lexer_value=value,
message='Unknown character',
expression=expression)
previous_column = end
token_type = match.lastgroup
handler = getattr(self, '_token_%s' % token_type.lower(), None)
if handler is not None:
value = handler(value, start, end)
yield {'type': token_type, 'value': value,
'start': start, 'end': end}
# At the end of the loop make sure we've consumed all the input.
# If we haven't then we have unidentified characters.
if end != len(expression):
msg = "Unknown characters at the end of the expression"
raise LexerError(lexer_position=end,
lexer_value='',
message=msg, expression=expression)
else:
yield {'type': 'eof', 'value': '',
'start': len(expression), 'end': len(expression)}