Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
elif symbol[0] == '"':
yield ('string', IncrementalJsonParser.unescape(symbol[1:-1]))
else:
# if we got a partial token for false / null / true we need to read from the network again
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')
def stream(self, query):
from pyravendb.store.stream import IncrementalJsonParser
import ijson
index_query = query.get_index_query()
if index_query.wait_for_non_stale_results:
raise exceptions.NotSupportedException("Since stream() does not wait for indexing (by design), "
"streaming query with wait_for_non_stale_results is not supported.")
self.session.increment_requests_count()
command = QueryStreamCommand(index_query)
with self.session.requests_executor.execute(command) as response:
basic_parse = IncrementalJsonParser.basic_parse(response)
parser = ijson.backend.common.parse(basic_parse)
results = ijson.backend.common.items(parser, "Results")
for result in next(results, None):
document, metadata, _, _ = Utils.convert_to_entity(result, query.object_type, self.session.conventions,
query.nested_object_types)
yield {"document": document, "metadata": metadata, "id": metadata.get("@id", None),
"change-vector": metadata.get("@change-vector", None)}
yield ('string', IncrementalJsonParser.unescape(symbol[1:-1]))
else:
# if we got a partial token for false / null / true we need to read from the network again
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')
def basic_parse(response, buf_size=ijson.backend.BUFSIZE):
'''
Iterator yielding unprefixed events.
Parameters:
- response: a stream response from requests
'''
lexer = iter(IncrementalJsonParser.lexer(response, buf_size))
for value in ijson.backend.parse_value(lexer):
yield value
try:
next(lexer)
except StopIteration:
pass
else:
raise ijson.common.JSONError('Additional data')