Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
yield ('start_array', None)
try:
pos, symbol = next(lexer)
if symbol != ']':
while True:
for event in IncrementalJsonParser.parse_value(lexer, symbol, pos):
yield event
pos, symbol = next(lexer)
if symbol == ']':
break
if symbol != ',':
raise ijson.backend.UnexpectedSymbol(symbol, pos)
pos, symbol = next(lexer)
yield ('end_array', None)
except StopIteration:
raise ijson.backend.common.IncompleteJSONError('Incomplete JSON data')
pos = match.start()
start = pos + 1
while True:
try:
end = buf.index(b'"', start)
escpos = end - 1
while buf[escpos] == '\\':
escpos -= 1
if (end - escpos) % 2 == 0:
start = end + 1
else:
break
except ValueError:
data = socket.recv().encode('utf-8') if IS_WEBSOCKET else socket.recv(buf_size)
if not data:
raise ijson.backend.common.IncompleteJSONError('Incomplete string lexeme')
buf += data[1:-1] if IS_WEBSOCKET else data
yield discarded + pos, buf[pos:end + 1].decode('utf-8')
pos = end + 1
else:
while match.end() == len(buf) and buf[pos] not in BYTE_ARRAY_CHARACTERS:
try:
data = socket.recv().encode('utf-8') if IS_WEBSOCKET else socket.recv(buf_size)
if not data:
break
buf += data[1:-1].encode('utf-8') if IS_WEBSOCKET else data
match = LEXEME_RE.search(buf, pos)
lexeme = match.group()
except timeout:
break
while symbol[0] in ('t', 'n') and len(symbol) < 4 or symbol[0] == 'f' and len(symbol) < 5:
_, nextpart = next(lexer)
if symbol == 'null':
yield ('null', None)
elif symbol == 'true':
yield ('boolean', True)
elif symbol == 'false':
yield ('boolean', False)
return
try:
yield ('number', ijson.backend.common.number(symbol))
except ijson.backend.decimal.InvalidOperation:
raise ijson.backend.UnexpectedSymbol(symbol, pos)
except StopIteration:
raise ijson.backend.common.IncompleteJSONError('Incomplete JSON data')
raise ijson.backend.UnexpectedSymbol(symbol, pos)
yield ('map_key', IncrementalJsonParser.unescape(symbol[1:-1]))
pos, symbol = next(lexer)
if symbol != ':':
raise ijson.backend.UnexpectedSymbol(symbol, pos)
for event in IncrementalJsonParser.parse_value(lexer, None, pos):
yield event
pos, symbol = next(lexer)
if symbol == '}':
break
if symbol != ',':
raise ijson.backend.UnexpectedSymbol(symbol, pos)
pos, symbol = next(lexer)
yield ('end_map', None)
except StopIteration:
raise ijson.backend.common.IncompleteJSONError('Incomplete JSON data')