Search is not available for this dataset
text stringlengths 75 104k |
|---|
def _parse_var_int_components(buf, signed):
"""Parses a ``VarInt`` or ``VarUInt`` field from a file-like object."""
value = 0
sign = 1
while True:
ch = buf.read(1)
if ch == '':
raise IonException('Variable integer under-run')
octet = ord(ch)
if signed:
... |
def _parse_signed_int_components(buf):
"""Parses the remainder of a file-like object as a signed magnitude value.
Returns:
Returns a pair of the sign bit and the unsigned magnitude.
"""
sign_bit = 0
value = 0
first = True
while True:
ch = buf.read(1)
if ch == b'':
... |
def _parse_decimal(buf):
"""Parses the remainder of a file-like object as a decimal."""
exponent = _parse_var_int(buf, signed=True)
sign_bit, coefficient = _parse_signed_int_components(buf)
if coefficient == 0:
# Handle the zero cases--especially negative zero
value = Decimal((sign_bit,... |
def _parse_sid_iter(data):
"""Parses the given :class:`bytes` data as a list of :class:`SymbolToken`"""
limit = len(data)
buf = BytesIO(data)
while buf.tell() < limit:
sid = _parse_var_int(buf, signed=False)
yield SymbolToken(None, sid) |
def _create_delegate_handler(delegate):
"""Creates a handler function that creates a co-routine that can yield once with the given
positional arguments to the delegate as a transition.
Args:
delegate (Coroutine): The co-routine to delegate to.
Returns:
A :class:`callable` handler that ... |
def _read_data_handler(length, whence, ctx, skip=False, stream_event=ION_STREAM_INCOMPLETE_EVENT):
"""Creates a co-routine for retrieving data up to a requested size.
Args:
length (int): The minimum length requested.
whence (Coroutine): The co-routine to return to after the data is satisfied.
... |
def _var_uint_field_handler(handler, ctx):
"""Handler co-routine for variable unsigned integer fields that.
Invokes the given ``handler`` function with the read field and context,
then immediately yields to the resulting co-routine.
"""
_, self = yield
queue = ctx.queue
value = 0
while ... |
def _length_scalar_handler(scalar_factory, ion_type, length, ctx):
"""Handles scalars, ``scalar_factory`` is a function that returns a value or thunk."""
_, self = yield
if length == 0:
data = b''
else:
yield ctx.read_data_transition(length, self)
data = ctx.queue.read(length)
... |
def _annotation_handler(ion_type, length, ctx):
"""Handles annotations. ``ion_type`` is ignored."""
_, self = yield
self_handler = _create_delegate_handler(self)
if ctx.annotations is not None:
raise IonException('Annotation cannot be nested in annotations')
# We have to replace our conte... |
def _ordered_struct_start_handler(handler, ctx):
"""Handles the special case of ordered structs, specified by the type ID 0xD1.
This coroutine's only purpose is to ensure that the struct in question declares at least one field name/value pair,
as required by the spec.
"""
_, self = yield
self_h... |
def _container_start_handler(ion_type, length, ctx):
"""Handles container delegation."""
_, self = yield
container_ctx = ctx.derive_container_context(length)
if ctx.annotations and ctx.limit != container_ctx.limit:
# 'ctx' is the annotation wrapper context. `container_ctx` represents the wrappe... |
def _container_handler(ion_type, ctx):
"""Handler for the body of a container (or the top-level stream).
Args:
ion_type (Optional[IonType]): The type of the container or ``None`` for the top-level.
ctx (_HandlerContext): The context for the container.
"""
transition = None
first = T... |
def _bind_length_handlers(tids, user_handler, lns):
"""Binds a set of handlers with the given factory.
Args:
tids (Sequence[int]): The Type IDs to bind to.
user_handler (Callable): A function that takes as its parameters
:class:`IonType`, ``length``, and the ``ctx`` context
... |
def _bind_length_scalar_handlers(tids, scalar_factory, lns=_NON_ZERO_LENGTH_LNS):
"""Binds a set of scalar handlers for an inclusive range of low-nibble values.
Args:
tids (Sequence[int]): The Type IDs to bind to.
scalar_factory (Callable): The factory for the scalar parsing function.
... |
def raw_reader(queue=None):
"""Returns a raw binary reader co-routine.
Args:
queue (Optional[BufferQueue]): The buffer read data for parsing, if ``None`` a
new one will be created.
Yields:
IonEvent: parse events, will have an event type of ``INCOMPLETE`` if data is needed
... |
def remaining(self):
"""Determines how many bytes are remaining in the current context."""
if self.depth == 0:
return _STREAM_REMAINING
return self.limit - self.queue.position |
def read_data_transition(self, length, whence=None,
skip=False, stream_event=ION_STREAM_INCOMPLETE_EVENT):
"""Returns an immediate event_transition to read a specified number of bytes."""
if whence is None:
whence = self.whence
return Transition(
... |
def event_transition(self, event_cls, event_type,
ion_type=None, value=None, annotations=None, depth=None, whence=None):
"""Returns an ion event event_transition that yields to another co-routine.
If ``annotations`` is not specified, then the ``annotations`` are the annotations... |
def dump(obj, fp, imports=None, binary=True, sequence_as_stream=False, skipkeys=False, ensure_ascii=True,
check_circular=True, allow_nan=True, cls=None, indent=None, separators=None, encoding='utf-8', default=None,
use_decimal=True, namedtuple_as_object=True, tuple_as_array=True, bigint_as_string=Fals... |
def dumps(obj, imports=None, binary=True, sequence_as_stream=False, skipkeys=False, ensure_ascii=True, check_circular=True,
allow_nan=True, cls=None, indent=None, separators=None, encoding='utf-8', default=None, use_decimal=True,
namedtuple_as_object=True, tuple_as_array=True, bigint_as_string=False... |
def load(fp, catalog=None, single_value=True, encoding='utf-8', cls=None, object_hook=None, parse_float=None,
parse_int=None, parse_constant=None, object_pairs_hook=None, use_decimal=None, **kw):
"""Deserialize ``fp`` (a file-like object), which contains a text or binary Ion stream, to a Python object usin... |
def loads(ion_str, catalog=None, single_value=True, encoding='utf-8', cls=None, object_hook=None, parse_float=None,
parse_int=None, parse_constant=None, object_pairs_hook=None, use_decimal=None, **kw):
"""Deserialize ``ion_str``, which is a string representation of an Ion object, to a Python object using ... |
def _narrow_unichr(code_point):
"""Retrieves the unicode character representing any given code point, in a way that won't break on narrow builds.
This is necessary because the built-in unichr function will fail for ordinals above 0xFFFF on narrow builds (UCS2);
ordinals above 0xFFFF would require recalcula... |
def reader_trampoline(start, allow_flush=False):
"""Provides the co-routine trampoline for a reader state machine.
The given co-routine is a state machine that yields :class:`Transition` and takes
a Transition of :class:`amazon.ion.core.DataEvent` and the co-routine itself.
A reader must start with a ... |
def blocking_reader(reader, input, buffer_size=_DEFAULT_BUFFER_SIZE):
"""Provides an implementation of using the reader co-routine with a file-like object.
Args:
reader(Coroutine): A reader co-routine.
input(BaseIO): The file-like object to read from.
buffer_size(Optional[int]): The opt... |
def read(self, length, skip=False):
"""Consumes the first ``length`` bytes from the accumulator."""
if length > self.__size:
raise IndexError(
'Cannot pop %d bytes, %d bytes in buffer queue' % (length, self.__size))
self.position += length
self.__size -= lengt... |
def unread(self, c):
"""Unread the given character, byte, or code point.
If this is a unicode buffer and the input is an int or byte, it will be interpreted as an ordinal representing
a unicode code point.
If this is a binary buffer, the input must be a byte or int; a unicode character... |
def skip(self, length):
"""Removes ``length`` bytes and returns the number length still required to skip"""
if length >= self.__size:
skip_amount = self.__size
rem = length - skip_amount
self.__segments.clear()
self.__offset = 0
self.__size = 0... |
def managed_reader(reader, catalog=None):
"""Managed reader wrapping another reader.
Args:
reader (Coroutine): The underlying non-blocking reader co-routine.
catalog (Optional[SymbolTableCatalog]): The catalog to use for resolving imports.
Yields:
Events from the underlying reader ... |
def resolve(self, token):
"""Attempts to resolve the :class:`SymbolToken` against the current table.
If the ``text`` is not None, the token is returned, otherwise, a token
in the table is attempted to be retrieved. If not token is found, then
this method will raise.
"""
... |
def _illegal_character(c, ctx, message=''):
"""Raises an IonException upon encountering the given illegal character in the given context.
Args:
c (int|None): Ordinal of the illegal character.
ctx (_HandlerContext): Context in which the illegal character was encountered.
message (Option... |
def _defaultdict(dct, fallback=_illegal_character):
"""Wraps the given dictionary such that the given fallback function will be called when a nonexistent key is
accessed.
"""
out = defaultdict(lambda: fallback)
for k, v in six.iteritems(dct):
out[k] = v
return out |
def _merge_mappings(*args):
"""Merges a sequence of dictionaries and/or tuples into a single dictionary.
If a given argument is a tuple, it must have two elements, the first of which is a sequence of keys and the second
of which is a single value, which will be mapped to from each of the keys in the sequen... |
def _as_symbol(value, is_symbol_value=True):
"""Converts the input to a :class:`SymbolToken` suitable for being emitted as part of a :class:`IonEvent`.
If the input has an `as_symbol` method (e.g. :class:`CodePointArray`), it will be converted using that method.
Otherwise, it must already be a `SymbolToken... |
def _number_negative_start_handler(c, ctx):
"""Handles numeric values that start with a negative sign. Branches to delegate co-routines according to
_NEGATIVE_TABLE.
"""
assert c == _MINUS
assert len(ctx.value) == 0
ctx.set_ion_type(IonType.INT)
ctx.value.append(c)
c, _ = yield
yield... |
def _number_zero_start_handler(c, ctx):
"""Handles numeric values that start with zero or negative zero. Branches to delegate co-routines according to
_ZERO_START_TABLE.
"""
assert c == _ZERO
assert len(ctx.value) == 0 or (len(ctx.value) == 1 and ctx.value[0] == _MINUS)
ctx.set_ion_type(IonType.... |
def _number_or_timestamp_handler(c, ctx):
"""Handles numeric values that start with digits 1-9. May terminate a value, in which case that value is an
int. If it does not terminate a value, it branches to delegate co-routines according to _NUMBER_OR_TIMESTAMP_TABLE.
"""
assert c in _DIGITS
ctx.set_io... |
def _number_slash_end_handler(c, ctx, event):
"""Handles numeric values that end in a forward slash. This is only legal if the slash begins a comment; thus,
this co-routine either results in an error being raised or an event being yielded.
"""
assert c == _SLASH
c, self = yield
next_ctx = ctx.de... |
def _numeric_handler_factory(charset, transition, assertion, illegal_before_underscore, parse_func,
illegal_at_end=(None,), ion_type=None, append_first_if_not=None, first_char=None):
"""Generates a handler co-routine which tokenizes a numeric component (a token or sub-token).
Args:... |
def _exponent_handler_factory(ion_type, exp_chars, parse_func, first_char=None):
"""Generates a handler co-routine which tokenizes an numeric exponent.
Args:
ion_type (IonType): The type of the value with this exponent.
exp_chars (sequence): The set of ordinals of the legal exponent characters ... |
def _coefficient_handler_factory(trans_table, parse_func, assertion=lambda c, ctx: True,
ion_type=None, append_first_if_not=None):
"""Generates a handler co-routine which tokenizes a numeric coefficient.
Args:
trans_table (dict): lookup table for the handler for the nex... |
def _radix_int_handler_factory(radix_indicators, charset, parse_func):
"""Generates a handler co-routine which tokenizes a integer of a particular radix.
Args:
radix_indicators (sequence): The set of ordinals of characters that indicate the radix of this int.
charset (sequence): Set of ordinals... |
def _timestamp_zero_start_handler(c, ctx):
"""Handles numeric values that start with a zero followed by another digit. This is either a timestamp or an
error.
"""
val = ctx.value
ctx.set_ion_type(IonType.TIMESTAMP)
if val[0] == _MINUS:
_illegal_character(c, ctx, 'Negative year not allowe... |
def _parse_timestamp(tokens):
"""Parses each token in the given `_TimestampTokens` and marshals the numeric components into a `Timestamp`."""
def parse():
precision = TimestampPrecision.YEAR
off_hour = tokens[_TimestampState.OFF_HOUR]
off_minutes = tokens[_TimestampState.OFF_MINUTE]
... |
def _timestamp_handler(c, ctx):
"""Handles timestamp values. Entered after the year component has been completed; tokenizes the remaining
components.
"""
assert c in _TIMESTAMP_YEAR_DELIMITERS
ctx.set_ion_type(IonType.TIMESTAMP)
if len(ctx.value) != 4:
_illegal_character(c, ctx, 'Timesta... |
def _comment_handler(c, ctx, whence):
"""Handles comments. Upon completion of the comment, immediately transitions back to `whence`."""
assert c == _SLASH
c, self = yield
if c == _SLASH:
ctx.set_line_comment()
block_comment = False
elif c == _ASTERISK:
if ctx.line_comment:
... |
def _sexp_slash_handler(c, ctx, whence=None, pending_event=None):
"""Handles the special case of a forward-slash within an s-expression. This is either an operator or a
comment.
"""
assert c == _SLASH
if whence is None:
whence = ctx.whence
c, self = yield
ctx.queue.unread(c)
if c... |
def _long_string_handler(c, ctx, is_field_name=False):
"""Handles triple-quoted strings. Remains active until a value other than a long string is encountered."""
assert c == _SINGLE_QUOTE
is_clob = ctx.ion_type is IonType.CLOB
max_char = _MAX_CLOB_CHAR if is_clob else _MAX_TEXT_CHAR
assert not (is_c... |
def _typed_null_handler(c, ctx):
"""Handles typed null values. Entered once `null.` has been found."""
assert c == _DOT
c, self = yield
nxt = _NULL_STARTS
i = 0
length = None
done = False
trans = ctx.immediate_transition(self)
while True:
if done:
if _ends_value(c... |
def _symbol_or_keyword_handler(c, ctx, is_field_name=False):
"""Handles the start of an unquoted text token.
This may be an operator (if in an s-expression), an identifier symbol, or a keyword.
"""
in_sexp = ctx.container.ion_type is IonType.SEXP
if c not in _IDENTIFIER_STARTS:
if in_sexp a... |
def _inf_or_operator_handler_factory(c_start, is_delegate=True):
"""Generates handler co-routines for values that may be `+inf` or `-inf`.
Args:
c_start (int): The ordinal of the character that starts this token (either `+` or `-`).
is_delegate (bool): True if a different handler began processi... |
def _operator_symbol_handler(c, ctx):
"""Handles operator symbol values within s-expressions."""
assert c in _OPERATORS
ctx.set_unicode()
val = ctx.value
val.append(c)
c, self = yield
trans = ctx.immediate_transition(self)
while c in _OPERATORS:
val.append(c)
c, _ = yield... |
def _symbol_token_end(c, ctx, is_field_name, value=None):
"""Returns a transition which ends the current symbol token."""
if value is None:
value = ctx.value
if is_field_name or c in _SYMBOL_TOKEN_TERMINATORS or ctx.quoted_text:
# This might be an annotation or a field name. Mark it as self-... |
def _unquoted_symbol_handler(c, ctx, is_field_name=False):
"""Handles identifier symbol tokens. If in an s-expression, these may be followed without whitespace by
operators.
"""
in_sexp = ctx.container.ion_type is IonType.SEXP
ctx.set_unicode()
if c not in _IDENTIFIER_CHARACTERS:
if in_s... |
def _symbol_identifier_or_unquoted_symbol_handler(c, ctx, is_field_name=False):
"""Handles symbol tokens that begin with a dollar sign. These may end up being system symbols ($ion_*), symbol
identifiers ('$' DIGITS+), or regular unquoted symbols.
"""
assert c == _DOLLAR_SIGN
in_sexp = ctx.container.... |
def _quoted_text_handler_factory(delimiter, assertion, before, after, append_first=True,
on_close=lambda ctx: None):
"""Generates handlers for quoted text tokens (either short strings or quoted symbols).
Args:
delimiter (int): Ordinal of the quoted text's delimiter.
... |
def _short_string_handler_factory():
"""Generates the short string (double quoted) handler."""
def before(c, ctx, is_field_name, is_clob):
assert not (is_clob and is_field_name)
is_string = not is_clob and not is_field_name
if is_string:
ctx.set_ion_type(IonType.STRING)
... |
def _quoted_symbol_handler_factory():
"""Generates the quoted symbol (single quoted) handler."""
def before(c, ctx, is_field_name, is_clob):
assert not is_clob
_validate_short_quoted_text(c, ctx, _MAX_TEXT_CHAR)
return ctx.value, False
return _quoted_text_handler_factory(
_S... |
def _single_quote_handler_factory(on_single_quote, on_other):
"""Generates handlers used for classifying tokens that begin with one or more single quotes.
Args:
on_single_quote (callable): Called when another single quote is found. Accepts the current character's ordinal,
the current contex... |
def _struct_or_lob_handler(c, ctx):
"""Handles tokens that begin with an open brace."""
assert c == _OPEN_BRACE
c, self = yield
yield ctx.immediate_transition(_STRUCT_OR_LOB_TABLE[c](c, ctx)) |
def _lob_start_handler(c, ctx):
"""Handles tokens that begin with two open braces."""
assert c == _OPEN_BRACE
c, self = yield
trans = ctx.immediate_transition(self)
quotes = 0
while True:
if c in _WHITESPACE:
if quotes > 0:
_illegal_character(c, ctx)
e... |
def _lob_end_handler_factory(ion_type, action, validate=lambda c, ctx, action_res: None):
"""Generates handlers for the end of blob or clob values.
Args:
ion_type (IonType): The type of this lob (either blob or clob).
action (callable): Called for each non-whitespace, non-closing brace characte... |
def _blob_end_handler_factory():
"""Generates the handler for the end of a blob value. This includes the base-64 data and the two closing braces."""
def expand_res(res):
if res is None:
return 0, 0
return res
def action(c, ctx, prev, res, is_first):
num_digits, num_pads ... |
def _clob_end_handler_factory():
"""Generates the handler for the end of a clob value. This includes anything from the data's closing quote through
the second closing brace.
"""
def action(c, ctx, prev, res, is_first):
if is_first and ctx.is_self_delimiting and c == _DOUBLE_QUOTE:
as... |
def _container_start_handler_factory(ion_type, before_yield=lambda c, ctx: None):
"""Generates handlers for tokens that begin with container start characters.
Args:
ion_type (IonType): The type of this container.
before_yield (Optional[callable]): Called at initialization. Accepts the first cha... |
def _read_data_handler(whence, ctx, complete, can_flush):
"""Creates a co-routine for retrieving data up to a requested size.
Args:
whence (Coroutine): The co-routine to return to after the data is satisfied.
ctx (_HandlerContext): The context for the read.
complete (True|False): True i... |
def _container_handler(c, ctx):
"""Coroutine for container values. Delegates to other coroutines to tokenize all child values."""
_, self = (yield None)
queue = ctx.queue
child_context = None
is_field_name = ctx.ion_type is IonType.STRUCT
delimiter_required = False
complete = ctx.depth == 0
... |
def _skip_trampoline(handler):
"""Intercepts events from container handlers, emitting them only if they should not be skipped."""
data_event, self = (yield None)
delegate = handler
event = None
depth = 0
while True:
def pass_through():
_trans = delegate.send(Transition(data_e... |
def _next_code_point_handler(whence, ctx):
"""Retrieves the next code point from within a quoted string or symbol."""
data_event, self = yield
queue = ctx.queue
unicode_escapes_allowed = ctx.ion_type is not IonType.CLOB
escaped_newline = False
escape_sequence = b''
low_surrogate_required = F... |
def reader(queue=None, is_unicode=False):
"""Returns a raw binary reader co-routine.
Args:
queue (Optional[BufferQueue]): The buffer read data for parsing, if ``None`` a
new one will be created.
is_unicode (Optional[bool]): True if all input data to this reader will be of unicode t... |
def event_transition(self, event_cls, event_type, ion_type, value):
"""Returns an ion event event_transition that yields to another co-routine."""
annotations = self.annotations or ()
depth = self.depth
whence = self.whence
if ion_type is IonType.SYMBOL:
if not annot... |
def read_data_event(self, whence, complete=False, can_flush=False):
"""Creates a transition to a co-routine for retrieving data as bytes.
Args:
whence (Coroutine): The co-routine to return to after the data is satisfied.
complete (Optional[bool]): True if STREAM_END should be em... |
def set_unicode(self, quoted_text=False):
"""Converts the context's ``value`` to a sequence of unicode code points for holding text tokens, indicating
whether the text is quoted.
"""
if isinstance(self.value, CodePointArray):
assert self.quoted_text == quoted_text
... |
def set_quoted_text(self, quoted_text):
"""Sets the context's ``quoted_text`` flag. Useful when entering and exiting quoted text tokens."""
self.quoted_text = quoted_text
self.line_comment = False
return self |
def derive_container_context(self, ion_type, whence):
"""Derives a container context as a child of the current context."""
if ion_type is IonType.STRUCT:
container = _C_STRUCT
elif ion_type is IonType.LIST:
container = _C_LIST
elif ion_type is IonType.SEXP:
... |
def set_empty_symbol(self):
"""Resets the context, retaining the fields that make it a child of its container (``container``, ``queue``,
``depth``, ``whence``), and sets an empty ``pending_symbol``.
This is useful when an empty quoted symbol immediately follows a long string.
"""
... |
def derive_child_context(self, whence):
"""Derives a scalar context as a child of the current context."""
return _HandlerContext(
container=self.container,
queue=self.queue,
field_name=None,
annotations=None,
depth=self.depth,
whenc... |
def set_ion_type(self, ion_type):
"""Sets context to the given IonType."""
if ion_type is self.ion_type:
return self
self.ion_type = ion_type
self.line_comment = False
return self |
def set_annotation(self):
"""Appends the context's ``pending_symbol`` to its ``annotations`` sequence."""
assert self.pending_symbol is not None
assert not self.value
annotations = (_as_symbol(self.pending_symbol, is_symbol_value=False),) # pending_symbol becomes an annotation
s... |
def set_field_name(self):
"""Sets the context's ``pending_symbol`` as its ``field_name``."""
assert self.pending_symbol is not None
assert not self.value
self.field_name = _as_symbol(self.pending_symbol, is_symbol_value=False) # pending_symbol becomes field name
self.pending_sym... |
def set_pending_symbol(self, pending_symbol=None):
"""Sets the context's ``pending_symbol`` with the given unicode sequence and resets the context's ``value``.
If the input is None, an empty :class:`CodePointArray` is used.
"""
if pending_symbol is None:
pending_symbol = Cod... |
def _write_base(buf, value, bits_per_octet, end_bit=0, sign_bit=0, is_signed=False):
"""Write a field to the provided buffer.
Args:
buf (Sequence): The buffer into which the UInt will be written
in the form of integer octets.
value (int): The value to write as a UInt.
bits_p... |
def record(*fields):
"""Constructs a type that can be extended to create immutable, value types.
Examples:
A typical declaration looks like::
class MyRecord(record('a', ('b', 1))):
pass
The above would make a sub-class of ``collections.namedtuple`` that was named `... |
def coroutine(func):
"""Wraps a PEP-342 enhanced generator in a way that avoids boilerplate of the "priming" call to ``next``.
Args:
func (Callable): The function constructing a generator to decorate.
Returns:
Callable: The decorated generator.
"""
def wrapper(*args, **kwargs):
... |
def unicode_iter(val):
"""Provides an iterator over the *code points* of the given Unicode sequence.
Notes:
Before PEP-393, Python has the potential to support Unicode as UTF-16 or UTF-32.
This is reified in the property as ``sys.maxunicode``. As a result, naive iteration
of Unicode se... |
def _next_code_point(val, val_iter, yield_char=False, to_int=lambda x: x):
"""Provides the next *code point* in the given Unicode sequence.
This generator function yields complete character code points, never incomplete surrogates. When a low surrogate is
found without following a high surrogate, this func... |
def timestamp(year, month=1, day=1,
hour=0, minute=0, second=0, microsecond=None,
off_hours=None, off_minutes=None,
precision=None, fractional_precision=None):
"""Shorthand for the :class:`Timestamp` constructor.
Specifically, converts ``off_hours`` and ``off_minutes``... |
def derive_field_name(self, field_name):
"""Derives a new event from this one setting the ``field_name`` attribute.
Args:
field_name (Union[amazon.ion.symbols.SymbolToken, unicode]): The field name to set.
Returns:
IonEvent: The newly generated event.
"""
... |
def derive_annotations(self, annotations):
"""Derives a new event from this one setting the ``annotations`` attribute.
Args:
annotations: (Sequence[Union[amazon.ion.symbols.SymbolToken, unicode]]):
The annotations associated with the derived event.
Returns:
... |
def derive_value(self, value):
"""Derives a new event from this one setting the ``value`` attribute.
Args:
value: (any):
The value associated with the derived event.
Returns:
IonEvent: The newly generated non-thunk event.
"""
return IonEv... |
def derive_depth(self, depth):
"""Derives a new event from this one setting the ``depth`` attribute.
Args:
depth: (int):
The annotations associated with the derived event.
Returns:
IonEvent: The newly generated event.
"""
cls = type(self)... |
def adjust_from_utc_fields(*args, **kwargs):
"""Constructs a timestamp from UTC fields adjusted to the local offset if given."""
raw_ts = Timestamp(*args, **kwargs)
offset = raw_ts.utcoffset()
if offset is None or offset == timedelta():
return raw_ts
# XXX This retur... |
def _serialize_scalar_from_string_representation_factory(type_name, types, str_func=str):
"""Builds functions that leverage Python ``str()`` or similar functionality.
Args:
type_name (str): The name of the Ion type.
types (Union[Sequence[type],type]): The Python types to validate for.
s... |
def _serialize_container_factory(suffix, container_map):
"""Returns a function that serializes container start/end.
Args:
suffix (str): The suffix to name the function with.
container_map (Dictionary[core.IonType, bytes]): The
Returns:
function: The closure for serialization.
"... |
def raw_writer(indent=None):
"""Returns a raw text writer co-routine.
Yields:
DataEvent: serialization events to write out
Receives :class:`amazon.ion.core.IonEvent` or ``None`` when the co-routine yields
``HAS_PENDING`` :class:`WriteEventType` events.
"""
is_whitespace_str = ... |
def writer_trampoline(start):
"""Provides the co-routine trampoline for a writer state machine.
The given co-routine is a state machine that yields :class:`Transition` and takes
a :class:`Transition` with a :class:`amazon.ion.core.IonEvent` and the co-routine itself.
Notes:
A writer delimits i... |
def _drain(writer, ion_event):
"""Drain the writer of its pending write events.
Args:
writer (Coroutine): A writer co-routine.
ion_event (amazon.ion.core.IonEvent): The first event to apply to the writer.
Yields:
DataEvent: Yields each pending data event.
"""
result_event =... |
def blocking_writer(writer, output):
"""Provides an implementation of using the writer co-routine with a file-like object.
Args:
writer (Coroutine): A writer co-routine.
output (BaseIO): The file-like object to pipe events to.
Yields:
WriteEventType: Yields when no events are pendi... |
def _copy(self):
"""Copies this instance. Its IonEvent (if any) is not preserved.
Keeping this protected until/unless we decide there's use for it publicly.
"""
args, kwargs = self._to_constructor_args(self)
value = self.__class__(*args, **kwargs)
value.ion_event = None
... |
def from_event(cls, ion_event):
"""Constructs the given native extension from the properties of an event.
Args:
ion_event (IonEvent): The event to construct the native value from.
"""
if ion_event.value is not None:
args, kwargs = cls._to_constructor_args(ion_eve... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.