signature stringlengths 8 3.44k | body stringlengths 0 1.41M | docstring stringlengths 1 122k | id stringlengths 5 17 |
|---|---|---|---|
def binary_writer(imports=None): | return writer_trampoline(_managed_binary_writer_coroutine(imports))<EOL> | Returns a binary writer co-routine.
Keyword Args:
imports (Optional[Sequence[SymbolTable]]): A list of shared symbol tables
to be used by this writer.
Yields:
DataEvent: serialization events to write out
Receives :class:`amazon.ion.core.IonEvent`. | f5015:m4 |
def partial_transition(data, delegate): | return Transition(DataEvent(WriteEventType.HAS_PENDING, data), delegate)<EOL> | Generates a :class:`Transition` that has an event indicating ``HAS_PENDING``. | f5016:m0 |
@coroutine<EOL>def writer_trampoline(start): | trans = Transition(None, start)<EOL>while True:<EOL><INDENT>ion_event = (yield trans.event)<EOL>if trans.event is None:<EOL><INDENT>if ion_event is None:<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if trans.event.type is WriteEventType.HAS_PENDING and ion_event is not None:<EOL><INDEN... | 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 its logical flush points with ``WriteE... | f5016:m5 |
def _drain(writer, ion_event): | result_event = _WRITE_EVENT_HAS_PENDING_EMPTY<EOL>while result_event.type is WriteEventType.HAS_PENDING:<EOL><INDENT>result_event = writer.send(ion_event)<EOL>ion_event = None<EOL>yield result_event<EOL><DEDENT> | 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. | f5016:m6 |
@coroutine<EOL>def blocking_writer(writer, output): | result_type = None<EOL>while True:<EOL><INDENT>ion_event = (yield result_type)<EOL>for result_event in _drain(writer, ion_event):<EOL><INDENT>output.write(result_event.data)<EOL><DEDENT>result_type = result_event.type<EOL><DEDENT> | 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 pending.
Receives :class:`amazon.ion.cor... | f5016:m7 |
def _illegal_character(c, ctx, message='<STR_LIT>'): | container_type = ctx.container.ion_type is None and '<STR_LIT>' or ctx.container.ion_type.name<EOL>value_type = ctx.ion_type is None and '<STR_LIT>' or ctx.ion_type.name<EOL>if c is None:<EOL><INDENT>header = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>c = '<STR_LIT>' if BufferQueue.is_eof(c) else _chr(c)<EOL>header = '<... | 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 (Optional[str]): Additional information, as necessary. | f5017:m0 |
def _defaultdict(dct, fallback=_illegal_character): | out = defaultdict(lambda: fallback)<EOL>for k, v in six.iteritems(dct):<EOL><INDENT>out[k] = v<EOL><DEDENT>return out<EOL> | Wraps the given dictionary such that the given fallback function will be called when a nonexistent key is
accessed. | f5017:m1 |
def _merge_mappings(*args): | dct = {}<EOL>for arg in args:<EOL><INDENT>if isinstance(arg, dict):<EOL><INDENT>merge = arg<EOL><DEDENT>else:<EOL><INDENT>assert isinstance(arg, tuple)<EOL>keys, value = arg<EOL>merge = dict(zip(keys, [value]*len(keys)))<EOL><DEDENT>dct.update(merge)<EOL><DEDENT>return dct<EOL> | 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 sequence. | f5017:m2 |
def _seq(s): | return tuple(six.iterbytes(s))<EOL> | Converts bytes to a sequence of integer code points. | f5017:m3 |
def _is_escaped(c): | try:<EOL><INDENT>return c.is_escaped<EOL><DEDENT>except AttributeError:<EOL><INDENT>return False<EOL><DEDENT> | Queries whether a character ordinal or code point was part of an escape sequence. | f5017:m5 |
def _as_symbol(value, is_symbol_value=True): | try:<EOL><INDENT>return value.as_symbol()<EOL><DEDENT>except AttributeError:<EOL><INDENT>assert isinstance(value, SymbolToken)<EOL><DEDENT>if not is_symbol_value:<EOL><INDENT>try:<EOL><INDENT>return value.regular_token()<EOL><DEDENT>except AttributeError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>return value<EOL> | 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`. In this case, there is nothing to do unless the i... | f5017:m6 |
@coroutine<EOL>def _number_negative_start_handler(c, ctx): | assert c == _MINUS<EOL>assert len(ctx.value) == <NUM_LIT:0><EOL>ctx.set_ion_type(IonType.INT)<EOL>ctx.value.append(c)<EOL>c, _ = yield<EOL>yield ctx.immediate_transition(_NEGATIVE_TABLE[c](c, ctx))<EOL> | Handles numeric values that start with a negative sign. Branches to delegate co-routines according to
_NEGATIVE_TABLE. | f5017:m11 |
@coroutine<EOL>def _number_zero_start_handler(c, ctx): | assert c == _ZERO<EOL>assert len(ctx.value) == <NUM_LIT:0> or (len(ctx.value) == <NUM_LIT:1> and ctx.value[<NUM_LIT:0>] == _MINUS)<EOL>ctx.set_ion_type(IonType.INT)<EOL>ctx.value.append(c)<EOL>c, _ = yield<EOL>if _ends_value(c):<EOL><INDENT>trans = ctx.event_transition(IonThunkEvent, IonEventType.SCALAR, ctx.ion_type, ... | Handles numeric values that start with zero or negative zero. Branches to delegate co-routines according to
_ZERO_START_TABLE. | f5017:m12 |
@coroutine<EOL>def _number_or_timestamp_handler(c, ctx): | assert c in _DIGITS<EOL>ctx.set_ion_type(IonType.INT) <EOL>val = ctx.value<EOL>val.append(c)<EOL>c, self = yield<EOL>trans = ctx.immediate_transition(self)<EOL>while True:<EOL><INDENT>if _ends_value(c):<EOL><INDENT>trans = ctx.event_transition(IonThunkEvent, IonEventType.SCALAR,<EOL>ctx.ion_type, _parse_decimal_int(ct... | 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. | f5017:m13 |
@coroutine<EOL>def _number_slash_end_handler(c, ctx, event): | assert c == _SLASH<EOL>c, self = yield<EOL>next_ctx = ctx.derive_child_context(ctx.whence)<EOL>comment = _comment_handler(_SLASH, next_ctx, next_ctx.whence)<EOL>comment.send((c, comment))<EOL>yield _CompositeTransition(event, ctx, comment, next_ctx, initialize_handler=False)<EOL> | 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. | f5017:m14 |
def _numeric_handler_factory(charset, transition, assertion, illegal_before_underscore, parse_func,<EOL>illegal_at_end=(None,), ion_type=None, append_first_if_not=None, first_char=None): | @coroutine<EOL>def numeric_handler(c, ctx):<EOL><INDENT>assert assertion(c, ctx)<EOL>if ion_type is not None:<EOL><INDENT>ctx.set_ion_type(ion_type)<EOL><DEDENT>val = ctx.value<EOL>if c != append_first_if_not:<EOL><INDENT>first = c if first_char is None else first_char<EOL>val.append(first)<EOL><DEDENT>prev = c<EOL>c, ... | Generates a handler co-routine which tokenizes a numeric component (a token or sub-token).
Args:
charset (sequence): Set of ordinals of legal characters for this numeric component.
transition (callable): Called upon termination of this component (i.e. when a character not in ``charset`` is
... | f5017:m15 |
def _exponent_handler_factory(ion_type, exp_chars, parse_func, first_char=None): | def transition(prev, c, ctx, trans):<EOL><INDENT>if c in _SIGN and prev in exp_chars:<EOL><INDENT>ctx.value.append(c)<EOL><DEDENT>else:<EOL><INDENT>_illegal_character(c, ctx)<EOL><DEDENT>return trans<EOL><DEDENT>illegal = exp_chars + _SIGN<EOL>return _numeric_handler_factory(_DIGITS, transition, lambda c, ctx: c in exp... | 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 for this component.
parse_func (callable): Called upon ending the numeric value.... | f5017:m16 |
def _coefficient_handler_factory(trans_table, parse_func, assertion=lambda c, ctx: True,<EOL>ion_type=None, append_first_if_not=None): | def transition(prev, c, ctx, trans):<EOL><INDENT>if prev == _UNDERSCORE:<EOL><INDENT>_illegal_character(c, ctx, '<STR_LIT>' % (_chr(c),))<EOL><DEDENT>return ctx.immediate_transition(trans_table[c](c, ctx))<EOL><DEDENT>return _numeric_handler_factory(_DIGITS, transition, assertion, (_DOT,), parse_func,<EOL>ion_type=ion_... | Generates a handler co-routine which tokenizes a numeric coefficient.
Args:
trans_table (dict): lookup table for the handler for the next component of this numeric token, given the
ordinal of the first character in that component.
parse_func (callable): Called upon ending the numeric va... | f5017:m17 |
def _radix_int_handler_factory(radix_indicators, charset, parse_func): | def assertion(c, ctx):<EOL><INDENT>return c in radix_indicators and((len(ctx.value) == <NUM_LIT:1> and ctx.value[<NUM_LIT:0>] == _ZERO) or<EOL>(len(ctx.value) == <NUM_LIT:2> and ctx.value[<NUM_LIT:0>] == _MINUS and ctx.value[<NUM_LIT:1>] == _ZERO)) andctx.ion_type == IonType.INT<EOL><DEDENT>return _numeric_handler_fact... | 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 of legal characters for this radix.
parse_func (callable): Called upo... | f5017:m18 |
@coroutine<EOL>def _timestamp_zero_start_handler(c, ctx): | val = ctx.value<EOL>ctx.set_ion_type(IonType.TIMESTAMP)<EOL>if val[<NUM_LIT:0>] == _MINUS:<EOL><INDENT>_illegal_character(c, ctx, '<STR_LIT>')<EOL><DEDENT>val.append(c)<EOL>c, self = yield<EOL>trans = ctx.immediate_transition(self)<EOL>while True:<EOL><INDENT>if c in _TIMESTAMP_YEAR_DELIMITERS:<EOL><INDENT>trans = ctx.... | Handles numeric values that start with a zero followed by another digit. This is either a timestamp or an
error. | f5017:m19 |
def _parse_timestamp(tokens): | def parse():<EOL><INDENT>precision = TimestampPrecision.YEAR<EOL>off_hour = tokens[_TimestampState.OFF_HOUR]<EOL>off_minutes = tokens[_TimestampState.OFF_MINUTE]<EOL>microsecond = None<EOL>fraction_digits = None<EOL>if off_hour is not None:<EOL><INDENT>assert off_minutes is not None<EOL>off_sign = -<NUM_LIT:1> if _MINU... | Parses each token in the given `_TimestampTokens` and marshals the numeric components into a `Timestamp`. | f5017:m20 |
@coroutine<EOL>def _timestamp_handler(c, ctx): | assert c in _TIMESTAMP_YEAR_DELIMITERS<EOL>ctx.set_ion_type(IonType.TIMESTAMP)<EOL>if len(ctx.value) != <NUM_LIT:4>:<EOL><INDENT>_illegal_character(c, ctx, '<STR_LIT>' % (len(ctx.value),))<EOL><DEDENT>prev = c<EOL>c, self = yield<EOL>trans = ctx.immediate_transition(self)<EOL>state = _TimestampState.YEAR<EOL>nxt = _DIG... | Handles timestamp values. Entered after the year component has been completed; tokenizes the remaining
components. | f5017:m21 |
@coroutine<EOL>def _comment_handler(c, ctx, whence): | assert c == _SLASH<EOL>c, self = yield<EOL>if c == _SLASH:<EOL><INDENT>ctx.set_line_comment()<EOL>block_comment = False<EOL><DEDENT>elif c == _ASTERISK:<EOL><INDENT>if ctx.line_comment:<EOL><INDENT>ctx.set_line_comment(False)<EOL><DEDENT>block_comment = True<EOL><DEDENT>else:<EOL><INDENT>_illegal_character(c, ctx, '<ST... | Handles comments. Upon completion of the comment, immediately transitions back to `whence`. | f5017:m22 |
@coroutine<EOL>def _sexp_slash_handler(c, ctx, whence=None, pending_event=None): | assert c == _SLASH<EOL>if whence is None:<EOL><INDENT>whence = ctx.whence<EOL><DEDENT>c, self = yield<EOL>ctx.queue.unread(c)<EOL>if c == _ASTERISK or c == _SLASH:<EOL><INDENT>yield ctx.immediate_transition(_comment_handler(_SLASH, ctx, whence))<EOL><DEDENT>else:<EOL><INDENT>if pending_event is not None:<EOL><INDENT>as... | Handles the special case of a forward-slash within an s-expression. This is either an operator or a
comment. | f5017:m23 |
@coroutine<EOL>def _long_string_handler(c, ctx, is_field_name=False): | assert c == _SINGLE_QUOTE<EOL>is_clob = ctx.ion_type is IonType.CLOB<EOL>max_char = _MAX_CLOB_CHAR if is_clob else _MAX_TEXT_CHAR<EOL>assert not (is_clob and is_field_name)<EOL>if not is_clob and not is_field_name:<EOL><INDENT>ctx.set_ion_type(IonType.STRING)<EOL><DEDENT>assert not ctx.value<EOL>ctx.set_unicode(quoted_... | Handles triple-quoted strings. Remains active until a value other than a long string is encountered. | f5017:m26 |
@coroutine<EOL>def _typed_null_handler(c, ctx): | assert c == _DOT<EOL>c, self = yield<EOL>nxt = _NULL_STARTS<EOL>i = <NUM_LIT:0><EOL>length = None<EOL>done = False<EOL>trans = ctx.immediate_transition(self)<EOL>while True:<EOL><INDENT>if done:<EOL><INDENT>if _ends_value(c) or (ctx.container.ion_type is IonType.SEXP and c in _OPERATORS):<EOL><INDENT>trans = ctx.event_... | Handles typed null values. Entered once `null.` has been found. | f5017:m27 |
@coroutine<EOL>def _symbol_or_keyword_handler(c, ctx, is_field_name=False): | in_sexp = ctx.container.ion_type is IonType.SEXP<EOL>if c not in _IDENTIFIER_STARTS:<EOL><INDENT>if in_sexp and c in _OPERATORS:<EOL><INDENT>c_next, _ = yield<EOL>ctx.queue.unread(c_next)<EOL>yield ctx.immediate_transition(_operator_symbol_handler(c, ctx))<EOL><DEDENT>_illegal_character(c, ctx)<EOL><DEDENT>assert not c... | Handles the start of an unquoted text token.
This may be an operator (if in an s-expression), an identifier symbol, or a keyword. | f5017:m28 |
def _inf_or_operator_handler_factory(c_start, is_delegate=True): | @coroutine<EOL>def inf_or_operator_handler(c, ctx):<EOL><INDENT>next_ctx = None<EOL>if not is_delegate:<EOL><INDENT>ctx.value.append(c_start)<EOL>c, self = yield<EOL><DEDENT>else:<EOL><INDENT>assert ctx.value[<NUM_LIT:0>] == c_start<EOL>assert c not in _DIGITS<EOL>ctx.queue.unread(c)<EOL>next_ctx = ctx<EOL>_, self = yi... | 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 processing this token; otherwise, False. This will only
be true for ... | f5017:m29 |
@coroutine<EOL>def _operator_symbol_handler(c, ctx): | assert c in _OPERATORS<EOL>ctx.set_unicode()<EOL>val = ctx.value<EOL>val.append(c)<EOL>c, self = yield<EOL>trans = ctx.immediate_transition(self)<EOL>while c in _OPERATORS:<EOL><INDENT>val.append(c)<EOL>c, _ = yield trans<EOL><DEDENT>yield ctx.event_transition(IonEvent, IonEventType.SCALAR, IonType.SYMBOL, val.as_symbo... | Handles operator symbol values within s-expressions. | f5017:m30 |
def _symbol_token_end(c, ctx, is_field_name, value=None): | if value is None:<EOL><INDENT>value = ctx.value<EOL><DEDENT>if is_field_name or c in _SYMBOL_TOKEN_TERMINATORS or ctx.quoted_text:<EOL><INDENT>ctx.set_self_delimiting(ctx.quoted_text).set_pending_symbol(value).set_quoted_text(False)<EOL>trans = ctx.immediate_transition(ctx.whence)<EOL><DEDENT>else:<EOL><INDENT>trans = ... | Returns a transition which ends the current symbol token. | f5017:m31 |
@coroutine<EOL>def _unquoted_symbol_handler(c, ctx, is_field_name=False): | in_sexp = ctx.container.ion_type is IonType.SEXP<EOL>ctx.set_unicode()<EOL>if c not in _IDENTIFIER_CHARACTERS:<EOL><INDENT>if in_sexp and c in _OPERATORS:<EOL><INDENT>c_next, _ = yield<EOL>ctx.queue.unread(c_next)<EOL>assert ctx.value<EOL>yield _CompositeTransition(<EOL>ctx.event_transition(IonEvent, IonEventType.SCALA... | Handles identifier symbol tokens. If in an s-expression, these may be followed without whitespace by
operators. | f5017:m32 |
@coroutine<EOL>def _symbol_identifier_or_unquoted_symbol_handler(c, ctx, is_field_name=False): | assert c == _DOLLAR_SIGN<EOL>in_sexp = ctx.container.ion_type is IonType.SEXP<EOL>ctx.set_unicode().set_ion_type(IonType.SYMBOL)<EOL>val = ctx.value<EOL>val.append(c)<EOL>prev = c<EOL>c, self = yield<EOL>trans = ctx.immediate_transition(self)<EOL>maybe_ivm = ctx.depth == <NUM_LIT:0> and not is_field_name and not ctx.an... | Handles symbol tokens that begin with a dollar sign. These may end up being system symbols ($ion_*), symbol
identifiers ('$' DIGITS+), or regular unquoted symbols. | f5017:m33 |
def _quoted_text_handler_factory(delimiter, assertion, before, after, append_first=True,<EOL>on_close=lambda ctx: None): | @coroutine<EOL>def quoted_text_handler(c, ctx, is_field_name=False):<EOL><INDENT>assert assertion(c)<EOL>def append():<EOL><INDENT>if not _is_escaped_newline(c):<EOL><INDENT>val.append(c)<EOL><DEDENT><DEDENT>is_clob = ctx.ion_type is IonType.CLOB<EOL>max_char = _MAX_CLOB_CHAR if is_clob else _MAX_TEXT_CHAR<EOL>ctx.set_... | Generates handlers for quoted text tokens (either short strings or quoted symbols).
Args:
delimiter (int): Ordinal of the quoted text's delimiter.
assertion (callable): Accepts the first character's ordinal, returning True if that character is a legal
beginning to the token.
bef... | f5017:m34 |
def _short_string_handler_factory(): | def before(c, ctx, is_field_name, is_clob):<EOL><INDENT>assert not (is_clob and is_field_name)<EOL>is_string = not is_clob and not is_field_name<EOL>if is_string:<EOL><INDENT>ctx.set_ion_type(IonType.STRING)<EOL><DEDENT>val = ctx.value<EOL>if is_field_name:<EOL><INDENT>assert not val<EOL>ctx.set_pending_symbol()<EOL>va... | Generates the short string (double quoted) handler. | f5017:m35 |
def _quoted_symbol_handler_factory(): | def before(c, ctx, is_field_name, is_clob):<EOL><INDENT>assert not is_clob<EOL>_validate_short_quoted_text(c, ctx, _MAX_TEXT_CHAR)<EOL>return ctx.value, False<EOL><DEDENT>return _quoted_text_handler_factory(<EOL>_SINGLE_QUOTE,<EOL>lambda c: (c != _SINGLE_QUOTE or _is_escaped(c)),<EOL>before,<EOL>_symbol_token_end,<EOL>... | Generates the quoted symbol (single quoted) handler. | f5017:m36 |
def _single_quote_handler_factory(on_single_quote, on_other): | @coroutine<EOL>def single_quote_handler(c, ctx, is_field_name=False):<EOL><INDENT>assert c == _SINGLE_QUOTE<EOL>c, self = yield<EOL>if c == _SINGLE_QUOTE and not _is_escaped(c):<EOL><INDENT>yield on_single_quote(c, ctx, is_field_name)<EOL><DEDENT>else:<EOL><INDENT>ctx.set_unicode(quoted_text=True)<EOL>yield on_other(c,... | 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 context, and True if the token is a field name; returns a Transition.
... | f5017:m37 |
@coroutine<EOL>def _struct_or_lob_handler(c, ctx): | assert c == _OPEN_BRACE<EOL>c, self = yield<EOL>yield ctx.immediate_transition(_STRUCT_OR_LOB_TABLE[c](c, ctx))<EOL> | Handles tokens that begin with an open brace. | f5017:m38 |
@coroutine<EOL>def _lob_start_handler(c, ctx): | assert c == _OPEN_BRACE<EOL>c, self = yield<EOL>trans = ctx.immediate_transition(self)<EOL>quotes = <NUM_LIT:0><EOL>while True:<EOL><INDENT>if c in _WHITESPACE:<EOL><INDENT>if quotes > <NUM_LIT:0>:<EOL><INDENT>_illegal_character(c, ctx)<EOL><DEDENT><DEDENT>elif c == _DOUBLE_QUOTE:<EOL><INDENT>if quotes > <NUM_LIT:0>:<E... | Handles tokens that begin with two open braces. | f5017:m41 |
def _lob_end_handler_factory(ion_type, action, validate=lambda c, ctx, action_res: None): | assert ion_type is IonType.BLOB or ion_type is IonType.CLOB<EOL>@coroutine<EOL>def lob_end_handler(c, ctx):<EOL><INDENT>val = ctx.value<EOL>prev = c<EOL>action_res = None<EOL>if c != _CLOSE_BRACE and c not in _WHITESPACE:<EOL><INDENT>action_res = action(c, ctx, prev, action_res, True)<EOL><DEDENT>c, self = yield<EOL>tr... | 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 character encountered before the end of
the lob. Accepts the current character's ordinal, the... | f5017:m42 |
def _blob_end_handler_factory(): | def expand_res(res):<EOL><INDENT>if res is None:<EOL><INDENT>return <NUM_LIT:0>, <NUM_LIT:0><EOL><DEDENT>return res<EOL><DEDENT>def action(c, ctx, prev, res, is_first):<EOL><INDENT>num_digits, num_pads = expand_res(res)<EOL>if c in _BASE64_DIGITS:<EOL><INDENT>if prev == _CLOSE_BRACE or prev == _BASE64_PAD:<EOL><INDENT>... | Generates the handler for the end of a blob value. This includes the base-64 data and the two closing braces. | f5017:m43 |
def _clob_end_handler_factory(): | def action(c, ctx, prev, res, is_first):<EOL><INDENT>if is_first and ctx.is_self_delimiting and c == _DOUBLE_QUOTE:<EOL><INDENT>assert c is prev<EOL>return res<EOL><DEDENT>_illegal_character(c, ctx)<EOL><DEDENT>return _lob_end_handler_factory(IonType.CLOB, action)<EOL> | Generates the handler for the end of a clob value. This includes anything from the data's closing quote through
the second closing brace. | f5017:m44 |
def _container_start_handler_factory(ion_type, before_yield=lambda c, ctx: None): | assert ion_type.is_container<EOL>@coroutine<EOL>def container_start_handler(c, ctx):<EOL><INDENT>before_yield(c, ctx)<EOL>yield<EOL>yield ctx.event_transition(IonEvent, IonEventType.CONTAINER_START, ion_type, value=None)<EOL><DEDENT>return container_start_handler<EOL> | 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 character's ordinal and the
current context; performs any necessary initializati... | f5017:m45 |
@coroutine<EOL>def _read_data_handler(whence, ctx, complete, can_flush): | trans = None<EOL>queue = ctx.queue<EOL>while True:<EOL><INDENT>data_event, self = (yield trans)<EOL>if data_event is not None:<EOL><INDENT>if data_event.data is not None:<EOL><INDENT>data = data_event.data<EOL>data_len = len(data)<EOL>if data_len > <NUM_LIT:0>:<EOL><INDENT>queue.extend(data)<EOL>yield Transition(None, ... | 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 if STREAM_END should be emitted if no bytes are read or
... | f5017:m46 |
@coroutine<EOL>def _container_handler(c, ctx): | _, self = (yield None)<EOL>queue = ctx.queue<EOL>child_context = None<EOL>is_field_name = ctx.ion_type is IonType.STRUCT<EOL>delimiter_required = False<EOL>complete = ctx.depth == <NUM_LIT:0><EOL>can_flush = False<EOL>def has_pending_symbol():<EOL><INDENT>return child_context and child_context.pending_symbol is not Non... | Coroutine for container values. Delegates to other coroutines to tokenize all child values. | f5017:m47 |
@coroutine<EOL>def _skip_trampoline(handler): | data_event, self = (yield None)<EOL>delegate = handler<EOL>event = None<EOL>depth = <NUM_LIT:0><EOL>while True:<EOL><INDENT>def pass_through():<EOL><INDENT>_trans = delegate.send(Transition(data_event, delegate))<EOL>return _trans, _trans.delegate, _trans.event<EOL><DEDENT>if data_event is not None and data_event.type ... | Intercepts events from container handlers, emitting them only if they should not be skipped. | f5017:m48 |
@coroutine<EOL>def _next_code_point_handler(whence, ctx): | data_event, self = yield<EOL>queue = ctx.queue<EOL>unicode_escapes_allowed = ctx.ion_type is not IonType.CLOB<EOL>escaped_newline = False<EOL>escape_sequence = b'<STR_LIT>'<EOL>low_surrogate_required = False<EOL>while True:<EOL><INDENT>if len(queue) == <NUM_LIT:0>:<EOL><INDENT>yield ctx.read_data_event(self)<EOL><DEDEN... | Retrieves the next code point from within a quoted string or symbol. | f5017:m49 |
def reader(queue=None, is_unicode=False): | if queue is None:<EOL><INDENT>queue = BufferQueue(is_unicode)<EOL><DEDENT>ctx = _HandlerContext(<EOL>container=_C_TOP_LEVEL,<EOL>queue=queue,<EOL>field_name=None,<EOL>annotations=None,<EOL>depth=<NUM_LIT:0>,<EOL>whence=None,<EOL>value=None,<EOL>ion_type=None, <EOL>pending_symbol=None<EOL>)<EOL>return reader_trampoline... | 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 text type; False if all
input data to ... | f5017:m50 |
def event_transition(self, event_cls, event_type, ion_type, value): | annotations = self.annotations or ()<EOL>depth = self.depth<EOL>whence = self.whence<EOL>if ion_type is IonType.SYMBOL:<EOL><INDENT>if not annotations and depth == <NUM_LIT:0> and isinstance(value, _IVMToken):<EOL><INDENT>event = value.ivm_event()<EOL>if event is None:<EOL><INDENT>_illegal_character(None, self, '<STR_L... | Returns an ion event event_transition that yields to another co-routine. | f5017:c2:m1 |
def immediate_transition(self, delegate): | return Transition(None, delegate)<EOL> | Returns an immediate transition to another co-routine. | f5017:c2:m2 |
def read_data_event(self, whence, complete=False, can_flush=False): | return Transition(None, _read_data_handler(whence, self, complete, can_flush))<EOL> | 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 emitted if no bytes are read or
available; False if INCOMPLETE sh... | f5017:c2:m3 |
def next_code_point(self, whence): | return Transition(None, _next_code_point_handler(whence, self))<EOL> | Creates a co-routine for retrieving data as code points.
This should be used in quoted string contexts. | f5017:c2:m4 |
def set_unicode(self, quoted_text=False): | if isinstance(self.value, CodePointArray):<EOL><INDENT>assert self.quoted_text == quoted_text<EOL>return self<EOL><DEDENT>self.value = CodePointArray(self.value)<EOL>self.quoted_text = quoted_text<EOL>self.line_comment = False<EOL>return self<EOL> | Converts the context's ``value`` to a sequence of unicode code points for holding text tokens, indicating
whether the text is quoted. | f5017:c2:m5 |
def set_quoted_text(self, quoted_text): | self.quoted_text = quoted_text<EOL>self.line_comment = False<EOL>return self<EOL> | Sets the context's ``quoted_text`` flag. Useful when entering and exiting quoted text tokens. | f5017:c2:m6 |
def set_self_delimiting(self, is_self_delimiting): | self.is_self_delimiting = is_self_delimiting<EOL>return self<EOL> | Sets the context's ``is_self_delimiting`` flag. Useful when the end of a self-delimiting token (short string,
container, or comment) is reached.
This is distinct from the ``quoted_text`` flag because some quoted text (quoted symbols and long strings) are
not self-delimiting--they require lookah... | f5017:c2:m7 |
def set_code_point(self, code_point): | self.code_point = code_point<EOL>return self<EOL> | Sets the context's current ``code_point`` to the given ``int`` or :class:`CodePoint`. | f5017:c2:m8 |
def derive_container_context(self, ion_type, whence): | if ion_type is IonType.STRUCT:<EOL><INDENT>container = _C_STRUCT<EOL><DEDENT>elif ion_type is IonType.LIST:<EOL><INDENT>container = _C_LIST<EOL><DEDENT>elif ion_type is IonType.SEXP:<EOL><INDENT>container = _C_SEXP<EOL><DEDENT>else:<EOL><INDENT>raise TypeError('<STR_LIT>' % (ion_type.name,))<EOL><DEDENT>return _Handler... | Derives a container context as a child of the current context. | f5017:c2:m9 |
def set_empty_symbol(self): | self.field_name = None<EOL>self.annotations = None<EOL>self.ion_type = None<EOL>self.set_pending_symbol(CodePointArray())<EOL>return self<EOL> | 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. | f5017:c2:m10 |
def derive_child_context(self, whence): | return _HandlerContext(<EOL>container=self.container,<EOL>queue=self.queue,<EOL>field_name=None,<EOL>annotations=None,<EOL>depth=self.depth,<EOL>whence=whence,<EOL>value=bytearray(), <EOL>ion_type=None,<EOL>pending_symbol=None<EOL>)<EOL> | Derives a scalar context as a child of the current context. | f5017:c2:m11 |
def set_line_comment(self, is_line_comment=True): | self.line_comment = is_line_comment<EOL>return self<EOL> | Sets the context's ``line_comment`` flag. Useful when entering or exiting a line comment. | f5017:c2:m12 |
def set_ion_type(self, ion_type): | if ion_type is self.ion_type:<EOL><INDENT>return self<EOL><DEDENT>self.ion_type = ion_type<EOL>self.line_comment = False<EOL>return self<EOL> | Sets context to the given IonType. | f5017:c2:m13 |
def set_annotation(self): | assert self.pending_symbol is not None<EOL>assert not self.value<EOL>annotations = (_as_symbol(self.pending_symbol, is_symbol_value=False),) <EOL>self.annotations = annotations if not self.annotations else self.annotations + annotations<EOL>self.ion_type = None<EOL>self.pending_symbol = None <EOL>self.quoted_text = F... | Appends the context's ``pending_symbol`` to its ``annotations`` sequence. | f5017:c2:m14 |
def set_field_name(self): | assert self.pending_symbol is not None<EOL>assert not self.value<EOL>self.field_name = _as_symbol(self.pending_symbol, is_symbol_value=False) <EOL>self.pending_symbol = None <EOL>self.quoted_text = False<EOL>self.line_comment = False<EOL>self.is_self_delimiting = False<EOL>return self<EOL> | Sets the context's ``pending_symbol`` as its ``field_name``. | f5017:c2:m15 |
def set_pending_symbol(self, pending_symbol=None): | if pending_symbol is None:<EOL><INDENT>pending_symbol = CodePointArray()<EOL><DEDENT>self.value = bytearray() <EOL>self.pending_symbol = pending_symbol<EOL>self.line_comment = False<EOL>return self<EOL> | 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. | f5017:c2:m16 |
def ivm_event(self): | try:<EOL><INDENT>return _IVM_EVENTS[self.text]<EOL><DEDENT>except KeyError:<EOL><INDENT>return None<EOL><DEDENT> | If this token's text is a supported IVM, returns the :class:`IonEvent` representing that IVM.
Otherwise, returns `None`. | f5017:c6:m0 |
def regular_token(self): | return SymbolToken(self.text, self.sid, self.location)<EOL> | Returns a copy of this token as a normal :class:`SymbolToken`.
This will be used in _as_symbol when this token is used as an annotation or field name, in which cases it
can no longer be an IVM. | f5017:c6:m1 |
@coroutine<EOL>def managed_reader(reader, catalog=None): | if catalog is None:<EOL><INDENT>catalog = SymbolTableCatalog()<EOL><DEDENT>ctx = _ManagedContext(catalog)<EOL>symbol_trans = Transition(None, None)<EOL>ion_event = None<EOL>while True:<EOL><INDENT>if symbol_trans.delegate is not Noneand ion_event is not Noneand not ion_event.event_type.is_stream_signal:<EOL><INDENT>del... | 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 delegating to symbol table processing as needed.
... | f5018:m5 |
def resolve(self, token): | if token.text is not None:<EOL><INDENT>return token<EOL><DEDENT>resolved_token = self.symbol_table.get(token.sid, None)<EOL>if resolved_token is None:<EOL><INDENT>raise IonException('<STR_LIT>' % token.sid)<EOL><DEDENT>return resolved_token<EOL> | 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. | f5018:c0:m0 |
def is_null(value): | return value is None or isinstance(value, IonPyNull)<EOL> | A mechanism to determine if a value is ``None`` or an Ion ``null``. | f5020:m1 |
def _copy(self): | args, kwargs = self._to_constructor_args(self)<EOL>value = self.__class__(*args, **kwargs)<EOL>value.ion_event = None<EOL>value.ion_type = self.ion_type<EOL>value.ion_annotations = self.ion_annotations<EOL>return value<EOL> | Copies this instance. Its IonEvent (if any) is not preserved.
Keeping this protected until/unless we decide there's use for it publicly. | f5020:c0:m1 |
@classmethod<EOL><INDENT>def from_event(cls, ion_event):<DEDENT> | if ion_event.value is not None:<EOL><INDENT>args, kwargs = cls._to_constructor_args(ion_event.value)<EOL><DEDENT>else:<EOL><INDENT>args, kwargs = (), {}<EOL><DEDENT>value = cls(*args, **kwargs)<EOL>value.ion_event = ion_event<EOL>value.ion_type = ion_event.ion_type<EOL>value.ion_annotations = ion_event.annotations<EOL>... | Constructs the given native extension from the properties of an event.
Args:
ion_event (IonEvent): The event to construct the native value from. | f5020:c0:m3 |
@classmethod<EOL><INDENT>def from_value(cls, ion_type, value, annotations=()):<DEDENT> | if value is None:<EOL><INDENT>value = IonPyNull()<EOL><DEDENT>else:<EOL><INDENT>args, kwargs = cls._to_constructor_args(value)<EOL>value = cls(*args, **kwargs)<EOL><DEDENT>value.ion_event = None<EOL>value.ion_type = ion_type<EOL>value.ion_annotations = annotations<EOL>return value<EOL> | Constructs a value as a copy with an associated Ion type and annotations.
Args:
ion_type (IonType): The associated Ion type.
value (Any): The value to construct from, generally of type ``cls``.
annotations (Sequence[unicode]): The sequence Unicode strings decorating this va... | f5020:c0:m4 |
def to_event(self, event_type, field_name=None, depth=None): | if self.ion_event is None:<EOL><INDENT>value = self<EOL>if isinstance(self, IonPyNull):<EOL><INDENT>value = None<EOL><DEDENT>self.ion_event = IonEvent(event_type, ion_type=self.ion_type, value=value, field_name=field_name,<EOL>annotations=self.ion_annotations, depth=depth)<EOL><DEDENT>return self.ion_event<EOL> | Constructs an IonEvent from this _IonNature value.
Args:
event_type (IonEventType): The type of the resulting event.
field_name (Optional[text]): The field name associated with this value, if any.
depth (Optional[int]): The depth of this value.
Returns:
... | f5020:c0:m5 |
def _serialize_scalar_from_string_representation_factory(type_name, types, str_func=str): | def serialize(ion_event):<EOL><INDENT>value = ion_event.value<EOL>validate_scalar_value(value, types)<EOL>return six.b(str_func(value))<EOL><DEDENT>serialize.__name__ = '<STR_LIT>' + type_name<EOL>return serialize<EOL> | 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.
str_func (Optional[Callable]): The function to convert the value with, defaults to ``str``.
R... | f5021:m1 |
def _serialize_container_factory(suffix, container_map): | def serialize(ion_event):<EOL><INDENT>if not ion_event.ion_type.is_container:<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>return container_map[ion_event.ion_type]<EOL><DEDENT>serialize.__name__ = '<STR_LIT>' + suffix<EOL>return serialize<EOL> | 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. | f5021:m17 |
def raw_writer(indent=None): | is_whitespace_str = isinstance(indent, str) and re.search(r'<STR_LIT>', indent, re.M) is not None<EOL>if not (indent is None or is_whitespace_str):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>indent_bytes = six.b(indent) if isinstance(indent, str) else indent<EOL>return writer_trampoline(_raw_writer_coroutine... | 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. | f5021:m19 |
def convert(self, language, *args, **kwargs): | for f in find_pos(language):<EOL><INDENT>PoToXls(src=f, **kwargs).convert()<EOL><DEDENT> | Run converter.
Args:
language: (unicode) language code. | f5027:c0:m2 |
def __init__(self, src, *args, **kwargs): | self.quiet = kwargs.pop("<STR_LIT>", False)<EOL>if os.path.exists(src):<EOL><INDENT>self.src = src<EOL><DEDENT>else:<EOL><INDENT>if not self.quiet:<EOL><INDENT>sys.stderr.write("<STR_LIT>".format(**{"<STR_LIT:src>": src, }))<EOL><DEDENT>self.logger.error("<STR_LIT>".format(**{"<STR_LIT:src>": src, }))<EOL>sys.exit(-<NU... | Init conversion.
Args:
src: (unicode or string) path to ".po" file. | f5030:c0:m0 |
def header(self, sheet, name): | header = sheet.row(<NUM_LIT:0>)<EOL>for i, column in enumerate(self.headers[name]):<EOL><INDENT>header.write(i, self.headers[name][i])<EOL><DEDENT> | Write sheet header.
Args:
sheet: (xlwt.Worksheet.Worksheet) instance of xlwt sheet.
name: (unicode) name of sheet. | f5030:c0:m1 |
def output(self): | path, src = os.path.split(self.src)<EOL>src, ext = os.path.splitext(src)<EOL>return os.path.join(path, "<STR_LIT>".format(**{"<STR_LIT:src>": src, }))<EOL> | Create full path for excel file to save parsed translations strings.
Returns:
unicode: full path for excel file to save parsed translations strings. | f5030:c0:m2 |
def strings(self): | sheet = self.result.add_sheet("<STR_LIT>")<EOL>self.header(sheet, "<STR_LIT>")<EOL>n_row = <NUM_LIT:1> <EOL>for entry in self.po:<EOL><INDENT>row = sheet.row(n_row)<EOL>row.write(<NUM_LIT:0>, entry.msgid)<EOL>row.write(<NUM_LIT:1>, entry.msgstr)<EOL>n_row += <NUM_LIT:1><EOL>sheet.flush_row_data()<EOL><DEDENT> | Write strings sheet. | f5030:c0:m3 |
def metadata(self): | sheet = self.result.add_sheet("<STR_LIT>")<EOL>self.header(sheet, "<STR_LIT>")<EOL>n_row = <NUM_LIT:1> <EOL>for k in self.po.metadata:<EOL><INDENT>row = sheet.row(n_row)<EOL>row.write(<NUM_LIT:0>, k)<EOL>row.write(<NUM_LIT:1>, self.po.metadata[k])<EOL>n_row += <NUM_LIT:1><EOL>sheet.flush_row_data()<EOL><DEDENT> | Write metadata sheet. | f5030:c0:m4 |
def convert(self, *args, **kwargs): | self.strings()<EOL>self.metadata()<EOL>self.result.save(self.output())<EOL> | Yes it is, thanks captain. | f5030:c0:m5 |
def __init__(self, table=None, columns=None, row_columns=None, tab=None,<EOL>key_on=None, deliminator=None): | self._deliminator = self.DEFAULT_DELIMINATOR<EOL>self._tab = self.DEFAULT_TAB<EOL>self._row_columns = []<EOL>self._column_index = OrderedDict()<EOL>self.shared_tables = []<EOL>if columns:<EOL><INDENT>columns = list(columns)<EOL><DEDENT>if row_columns:<EOL><INDENT>row_columns = list(row_columns)<EOL><DEDENT>if not table... | :param table: obj can be list of list or list of dict
:param columns: list of str of the columns in the table
:param row_columns: list of str if different then visible columns
:param tab: str to include before every row
:param key_on: tuple of str if assigned so table is accessed as dict
:param deliminator: str to sepa... | f5033:c0:m0 |
@classmethod<EOL><INDENT>def list_to_obj(cls, list_, columns, row_columns=None, tab='<STR_LIT>',<EOL>key_on=None, no_header=False):<DEDENT> | if not list_:<EOL><INDENT>return cls(columns=columns, row_columns=row_columns, tab=tab,<EOL>key_on=key_on)<EOL><DEDENT>if getattr(list_[<NUM_LIT:0>], '<STR_LIT>', None) and not isinstance(list_[<NUM_LIT:0>], dict):<EOL><INDENT>row_columns = row_columns or columns or list_[<NUM_LIT:0>].keys()<EOL>column_index = cls._cre... | :param list_: list of list or list of dictionary to use as the
source
:param columns: list of strings to label the columns when
converting to str
:param row_columns: list of columns in the actually data
:param tab: str of the tab to use before the ro... | f5033:c0:m1 |
@classmethod<EOL><INDENT>def dict_to_obj(cls, dict_, columns, row_columns, tab='<STR_LIT>', key_on=None):<DEDENT> | if isinstance(list(dict_.values())[<NUM_LIT:0>], dict):<EOL><INDENT>row_columns = row_columns or columns or cls._key_on_columns(<EOL>key_on, cls._ordered_keys(dict_.values()[<NUM_LIT:0>]))<EOL>column_index = cls._create_column_index(row_columns)<EOL>if key_on is None:<EOL><INDENT>table = [<EOL>SeabornRow(column_index, ... | :param dict_: dict of dict or dict of list
:param columns: list of strings to label the columns on print out
:param row_columns: list of columns in the actually data
:param tab: str of the tab to use before the row on printout
:param key_on: str of the column to key each row on
:return: SeabornTable | f5033:c0:m2 |
@classmethod<EOL><INDENT>def csv_to_obj(cls, file_path=None, text='<STR_LIT>', columns=None,<EOL>remove_empty_rows=True, key_on=None, deliminator='<STR_LIT:U+002C>',<EOL>eval_cells=True):<DEDENT> | lines = cls._get_lines(file_path, text, replace=u'<STR_LIT>')<EOL>for i in range(len(lines)):<EOL><INDENT>lines[i] = lines[i].replace('<STR_LIT:\r>', '<STR_LIT:\n>')<EOL>lines[i] = lines[i].replace('<STR_LIT>', '<STR_LIT:\r>').split('<STR_LIT:U+002C>')<EOL><DEDENT>data = cls._merge_quoted_cells(lines, deliminator, remo... | This will convert a csv file or csv text into a seaborn table
and return it
:param file_path: str of the path to the file
:param text: str of the csv text
:param columns: list of str of columns to use
:param remove_empty_rows: bool if True will remove empty rows
which can happen in non-trimmed file
:param key_o... | f5033:c0:m4 |
@classmethod<EOL><INDENT>def grid_to_obj(cls, file_path=None, text='<STR_LIT>', edges=None,<EOL>columns=None, eval_cells=True, key_on=None):<DEDENT> | edges = edges if edges else cls.FANCY<EOL>lines = cls._get_lines(file_path, text)<EOL>data = []<EOL>for i in range(len(lines)-<NUM_LIT:1>):<EOL><INDENT>if i % <NUM_LIT:2> == <NUM_LIT:1>:<EOL><INDENT>row = lines[i].split(edges['<STR_LIT>'])[<NUM_LIT:1>:-<NUM_LIT:1>]<EOL>data.append([cls._eval_cell(r, _eval=eval_cells) f... | This will convert a grid file or grid text into a seaborn table
and return it
:param file_path: str of the path to the file
:param text: str of the grid text
:param columns: list of str of columns to use
:param key_on: list of str of columns to key on
:param eval_cells: bool if True will try to evalu... | f5033:c0:m5 |
@classmethod<EOL><INDENT>def txt_to_obj(cls, file_path=None, text='<STR_LIT>', columns=None,<EOL>remove_empty_rows=True, key_on=None,<EOL>row_columns=None, deliminator='<STR_LIT:\t>', eval_cells=True):<DEDENT> | return cls.str_to_obj(file_path=file_path, text=text, columns=columns,<EOL>remove_empty_rows=remove_empty_rows,<EOL>key_on=key_on, row_columns=row_columns,<EOL>deliminator=deliminator, eval_cells=eval_cells)<EOL> | This will convert text file or text to a seaborn table
and return it
:param file_path: str of the path to the file
:param text: str of the csv text
:param columns: list of str of columns to use
:param row_columns: list of str of columns in data but not to use
:param remove_empty_rows: bool if True will remove empty row... | f5033:c0:m7 |
@classmethod<EOL><INDENT>def str_to_obj(cls, file_path=None, text='<STR_LIT>', columns=None,<EOL>remove_empty_rows=True, key_on=None,<EOL>row_columns=None, deliminator='<STR_LIT:\t>', eval_cells=True):<DEDENT> | text = cls._get_lines(file_path, text)<EOL>if len(text) == <NUM_LIT:1>:<EOL><INDENT>text = text[<NUM_LIT:0>].split('<STR_LIT:\r>')<EOL><DEDENT>list_of_list = [[cls._eval_cell(cell, _eval=eval_cells)<EOL>for cell in row.split(deliminator)]<EOL>for row in text if not remove_empty_rows or<EOL>True in [bool(r) for r in row... | This will convert text file or text to a seaborn table
and return it
:param file_path: str of the path to the file
:param text: str of the csv text
:param columns: list of str of columns to use
:param row_columns: list of str of columns in data but not to use
:param remove_empty_rows: bool if True will remove empty row... | f5033:c0:m8 |
@classmethod<EOL><INDENT>def rst_to_obj(cls, file_path=None, text='<STR_LIT>', columns=None,<EOL>remove_empty_rows=True, key_on=None,<EOL>deliminator='<STR_LIT:U+0020>', eval_cells=True):<DEDENT> | text = cls._get_lines(file_path, text)<EOL>if len(text) == <NUM_LIT:1>:<EOL><INDENT>text = text[<NUM_LIT:0>].split('<STR_LIT:\r>')<EOL><DEDENT>for i in [-<NUM_LIT:1>, <NUM_LIT:2>, <NUM_LIT:0>]:<EOL><INDENT>if not text[i].replace('<STR_LIT:=>', '<STR_LIT>').strip():<EOL><INDENT>text.pop(i) <EOL><DEDENT><DEDENT>lines = ... | This will convert a rst file or text to a seaborn table
:param file_path: str of the path to the file
:param text: str of the csv text
:param columns: list of str of columns to use
:param remove_empty_rows: bool if True will remove empty rows
:param key_on: list of str of columns to key on
:param deliminator: str to us... | f5033:c0:m9 |
@classmethod<EOL><INDENT>def psql_to_obj(cls, file_path=None, text='<STR_LIT>', columns=None,<EOL>remove_empty_rows=True, key_on=None,<EOL>deliminator='<STR_LIT>', eval_cells=True):<DEDENT> | text = cls._get_lines(file_path, text)<EOL>if len(text) == <NUM_LIT:1>:<EOL><INDENT>text = text[<NUM_LIT:0>].split('<STR_LIT:\r>')<EOL><DEDENT>if not text[<NUM_LIT:1>].replace('<STR_LIT:+>', '<STR_LIT>').replace('<STR_LIT:->', '<STR_LIT>').strip():<EOL><INDENT>text.pop(<NUM_LIT:1>) <EOL><DEDENT>list_of_list = [[cls._e... | This will convert a psql file or text to a seaborn table
:param file_path: str of the path to the file
:param text: str of the csv text
:param columns: list of str of columns to use
:param remove_empty_rows: bool if True will remove empty rows
:param key_on: list of str of columns to key on
:param deliminator: str to u... | f5033:c0:m10 |
@classmethod<EOL><INDENT>def html_to_obj(cls, file_path=None, text='<STR_LIT>', columns=None,<EOL>key_on=None, ignore_code_blocks=True, eval_cells=True):<DEDENT> | raise NotImplemented<EOL> | This will convert a html file or text to a seaborn table
:param file_path: str of the path to the file
:param text: str of the csv text
:param columns: list of str of columns to use
:param remove_empty_rows: bool if True will remove empty rows
:param key_on: list of str of columns to key on
:param deliminator: str to u... | f5033:c0:m11 |
@classmethod<EOL><INDENT>def mark_down_to_dict_of_obj(cls, file_path=None, text='<STR_LIT>', columns=None,<EOL>key_on=None, eval_cells=True):<DEDENT> | text = cls._get_lines(file_path, text, split_lines=False)<EOL>ret = OrderedDict()<EOL>paragraphs = text.split('<STR_LIT>')<EOL>for paragraph in paragraphs[<NUM_LIT:1>:]:<EOL><INDENT>header, text = paragraph.split('<STR_LIT:\n>', <NUM_LIT:1>)<EOL>ret[header.strip()] = cls.mark_down_to_obj(<EOL>text=text, columns=columns... | This will read multiple tables separated by a #### Header
and return it as a dictionary of headers
:param file_path: str of the path to the file
:param text: str of the mark down text
:param columns: list of str of columns to use
:param key_on: list of str of columns to key on
:param eval_cells: bool if True will try t... | f5033:c0:m12 |
@classmethod<EOL><INDENT>def md_to_obj(cls, file_path=None, text='<STR_LIT>', columns=None,<EOL>key_on=None, ignore_code_blocks=True, eval_cells=True):<DEDENT> | return cls.mark_down_to_obj(file_path=file_path, text=text,<EOL>columns=columns, key_on=key_on,<EOL>ignore_code_blocks=ignore_code_blocks,<EOL>eval_cells=eval_cells)<EOL> | This will convert a mark down file to a seaborn table
:param file_path: str of the path to the file
:param text: str of the mark down text
:param columns: list of str of columns to use
:param key_on: list of str of columns to key on
:param ignore_code_blocks: bool if true will filter out
any lines between ```
:para... | f5033:c0:m13 |
@classmethod<EOL><INDENT>def mark_down_to_obj(cls, file_path=None, text='<STR_LIT>', columns=None,<EOL>key_on=None, ignore_code_blocks=True, eval_cells=True):<DEDENT> | text = cls._get_lines(file_path, text, split_lines=False)<EOL>if ignore_code_blocks:<EOL><INDENT>text = text.split("<STR_LIT>")<EOL>for i in range(<NUM_LIT:1>, len(text), <NUM_LIT:2>):<EOL><INDENT>text.pop(i)<EOL><DEDENT>text = ('<STR_LIT>'.join(text)).strip()<EOL><DEDENT>assert text.startswith('<STR_LIT:|>') and text.... | This will convert a mark down file to a seaborn table
and return it
:param file_path: str of the path to the file
:param text: str of the mark down text
:param columns: list of str of columns to use
:param key_on: list of str of columns to key on
:param ignore_code_blocks: bool if true will filter out
any lines be... | f5033:c0:m14 |
@classmethod<EOL><INDENT>def objs_to_mark_down(cls, tables, file_path=None, keys=None,<EOL>pretty_columns=True, quote_numbers=True):<DEDENT> | keys = keys or tables.keys()<EOL>ret = ['<STR_LIT>' + key + '<STR_LIT:\n>' + tables[key].obj_to_mark_down(<EOL>pretty_columns=pretty_columns, quote_numbers=quote_numbers)<EOL>for key in keys]<EOL>ret = '<STR_LIT>'.join(ret)<EOL>cls._save_file(file_path, ret)<EOL>return ret<EOL> | This will return a str of multiple mark down tables.
:param tables: dict of {str <name>:SeabornTable}
:param file_path: str of the path to the file
:param keys: list of str of the order of keys to use
:param pretty_columns: bool if True will make the columns pretty
:param quote_numbers: bool if ... | f5033:c0:m15 |
def obj_to_md(self, file_path=None, title_columns=False,<EOL>quote_numbers=True): | return self.obj_to_mark_down(file_path=file_path,<EOL>title_columns=title_columns,<EOL>quote_numbers=quote_numbers)<EOL> | This will return a str of a mark down tables.
:param title_columns: bool if True will title all headers
:param file_path: str of the path to the file to write to
:param quote_numbers: bool if True will quote numbers that are strings
:return: str | f5033:c0:m16 |
def obj_to_mark_down(self, file_path=None, title_columns=False,<EOL>quote_numbers=True, quote_empty_str=False): | md, column_widths = self.get_data_and_shared_column_widths(<EOL>data_kwargs=dict(quote_numbers=quote_numbers,<EOL>quote_empty_str=quote_empty_str,<EOL>title_columns=title_columns),<EOL>width_kwargs = dict(padding=<NUM_LIT:1>, pad_last_column=True))<EOL>md.insert(<NUM_LIT:1>, [u"<STR_LIT::>" + u'<STR_LIT:->' * (width - ... | This will return a str of a mark down table.
:param title_columns: bool if True will title all headers
:param file_path: str of the path to the file to write to
:param quote_numbers: bool if True will quote numbers that are strings
:param quote_empty_str: bool if True will quote empty strings
:return: str | f5033:c0:m17 |
def obj_to_txt(self, file_path=None, deliminator=None, tab=None,<EOL>quote_numbers=True, quote_empty_str=False): | return self.obj_to_str(file_path=file_path, deliminator=deliminator,<EOL>tab=tab, quote_numbers=quote_numbers,<EOL>quote_empty_str=quote_empty_str)<EOL> | This will return a simple str table.
:param file_path: str of the path to the file
:param keys: list of str of the order of keys to use
:param tab: string of offset of the table
:param quote_numbers: bool if True will quote numbers that are strings
:param quote_empty_str: bool if True wil... | f5033:c0:m18 |
def obj_to_str(self, file_path=None, deliminator=None, tab=None,<EOL>quote_numbers=True, quote_empty_str=False): | deliminator = self.deliminator if deliminator is Noneelse deliminator<EOL>tab = self.tab if tab is None else tab<EOL>list_of_list, column_widths = self.get_data_and_shared_column_widths(<EOL>data_kwargs=dict(quote_numbers=quote_numbers,<EOL>quote_empty_str=quote_empty_str),<EOL>width_kwargs = dict(padding=<NUM_LIT:0>))... | This will return a simple str table.
:param file_path: str of the path to the file
:param keys: list of str of the order of keys to use
:param tab: string of offset of the table
:param quote_numbers: bool if True will quote numbers that are strings
:param quote_empty_str: bool if True wil... | f5033:c0:m19 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.