本文整理汇总了Python中jmespath.exceptions.LexerError方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.LexerError方法的具体用法?Python exceptions.LexerError怎么用?Python exceptions.LexerError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jmespath.exceptions
的用法示例。
在下文中一共展示了exceptions.LexerError方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _consume_until
# 需要导入模块: from jmespath import exceptions [as 别名]
# 或者: from jmespath.exceptions import LexerError [as 别名]
def _consume_until(self, delimiter):
# Consume until the delimiter is reached,
# allowing for the delimiter to be escaped with "\".
start = self._position
buff = ''
self._next()
while self._current != delimiter:
if self._current == '\\':
buff += '\\'
self._next()
if self._current is None:
raise LexerError(lexer_position=start,
lexer_value=self._expression,
message="Unclosed %s delimiter" % delimiter)
buff += self._current
self._next()
# Skip the closing delimiter.
self._next()
return buff
示例2: _consume_literal
# 需要导入模块: from jmespath import exceptions [as 别名]
# 或者: from jmespath.exceptions import LexerError [as 别名]
def _consume_literal(self):
start = self._position
lexeme = self._consume_until('`').replace('\\`', '`')
try:
# Assume it is valid JSON and attempt to parse.
parsed_json = loads(lexeme)
except ValueError:
try:
# Invalid JSON values should be converted to quoted
# JSON strings during the JEP-12 deprecation period.
parsed_json = loads('"%s"' % lexeme.lstrip())
warnings.warn("deprecated string literal syntax",
PendingDeprecationWarning)
except ValueError:
raise LexerError(lexer_position=start,
lexer_value=self._expression,
message="Bad token %s" % lexeme)
token_len = self._position - start
return {'type': 'literal', 'value': parsed_json,
'start': start, 'end': token_len}
示例3: _consume_until
# 需要导入模块: from jmespath import exceptions [as 别名]
# 或者: from jmespath.exceptions import LexerError [as 别名]
def _consume_until(self, delimiter):
# Consume until the delimiter is reached,
# allowing for the delimiter to be escaped with "\".
start = self._position
buff = ''
self._next()
while self._current != delimiter:
if self._current == '\\':
buff += '\\'
self._next()
if self._current is None:
# We're at the EOF.
raise LexerError(lexer_position=start,
lexer_value=self._expression[start:],
message="Unclosed %s delimiter" % delimiter)
buff += self._current
self._next()
# Skip the closing delimiter.
self._next()
return buff
示例4: _consume_literal
# 需要导入模块: from jmespath import exceptions [as 别名]
# 或者: from jmespath.exceptions import LexerError [as 别名]
def _consume_literal(self):
start = self._position
lexeme = self._consume_until('`').replace('\\`', '`')
try:
# Assume it is valid JSON and attempt to parse.
parsed_json = loads(lexeme)
except ValueError:
try:
# Invalid JSON values should be converted to quoted
# JSON strings during the JEP-12 deprecation period.
parsed_json = loads('"%s"' % lexeme.lstrip())
warnings.warn("deprecated string literal syntax",
PendingDeprecationWarning)
except ValueError:
raise LexerError(lexer_position=start,
lexer_value=self._expression[start:],
message="Bad token %s" % lexeme)
token_len = self._position - start
return {'type': 'literal', 'value': parsed_json,
'start': start, 'end': token_len}
示例5: _consume_quoted_identifier
# 需要导入模块: from jmespath import exceptions [as 别名]
# 或者: from jmespath.exceptions import LexerError [as 别名]
def _consume_quoted_identifier(self):
start = self._position
lexeme = '"' + self._consume_until('"') + '"'
try:
token_len = self._position - start
return {'type': 'quoted_identifier', 'value': loads(lexeme),
'start': start, 'end': token_len}
except ValueError as e:
error_message = str(e).split(':')[0]
raise LexerError(lexer_position=start,
lexer_value=lexeme,
message=error_message)
示例6: _do_parse
# 需要导入模块: from jmespath import exceptions [as 别名]
# 或者: from jmespath.exceptions import LexerError [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
示例7: _token_quoted_identifier
# 需要导入模块: from jmespath import exceptions [as 别名]
# 或者: from jmespath.exceptions import LexerError [as 别名]
def _token_quoted_identifier(self, value, start, end):
try:
return loads(value)
except ValueError as e:
error_message = str(e).split(':')[0]
raise LexerError(lexer_position=start,
lexer_value=value,
message=error_message)