def _scalar_event_pairs(data, events, info):
"""Generates event pairs for all scalars.
Each scalar is represented by a sequence whose first element is the raw data and whose following elements are the
expected output events.
"""
first = True
delimiter, in_container = info
space_delimited = not (b',' in delimiter)
for event in events:
input_event = NEXT
if first:
input_event = e_read(data + delimiter)
if space_delimited and event.value is not None \
and ((event.ion_type is IonType.SYMBOL) or
(event.ion_type is IonType.STRING and
six.byte2int(b'"') != six.indexbytes(data, 0))): # triple-quoted strings
# Because annotations and field names are symbols, a space delimiter after a symbol isn't enough to
# generate a symbol event immediately. Similarly, triple-quoted strings may be followed by another
# triple-quoted string if only delimited by whitespace or comments.
yield input_event, INC
if in_container:
# Within s-expressions, these types are delimited in these tests by another value - in this case,
# int 0 (but it could be anything).
yield e_read(b'0' + delimiter), event
input_event, event = (NEXT, e_int(0))
else:
# This is a top-level value, so it may be flushed with NEXT after INCOMPLETE.
input_event, event = (NEXT, event)
first = False
yield input_event, event
评论列表
文章目录