ace.ari_text package

CODEC for converting ARI to and from text URI form.

class ace.ari_text.Decoder

Bases: object

The decoder portion of this CODEC.

decode(buf: TextIO) ARI

Decode an ARI from UTF8 text.

Parameters:

buf – The buffer to read from.

Returns:

The decoded ARI.

Throw ParseError:

If there is a problem with the input text.

class ace.ari_text.EncodeOptions(scheme_prefix: bool = True, int_base: int = 10, float_form: str = 'g', text_identity: bool = True, time_text: bool = True, cbor_diag: bool = False)

Bases: object

Preferences for text encoding variations.

cbor_diag: bool = False

True if CBOR values should be in diagnostic form.

float_form: str = 'g'

One of ‘f’ or ‘g’ for standard format, or ‘x’ for raw hex

int_base: int = 10

One of 2, 10, or 16

scheme_prefix: bool = True

True if the scheme is present at the start.

text_identity: bool = True

True if specific text can be left unquoted.

time_text: bool = True

True if time values should be in text form.

class ace.ari_text.Encoder(options: Optional[EncodeOptions] = None, **kwargs)

Bases: object

The encoder portion of this CODEC.

encode(obj: ARI, buf: TextIO)

Encode an ARI into UTF8 text.

Parameters:
  • obj – The ARI object to encode.

  • buf – The buffer to write into.

ace.ari_text.quote(text)

URL-escape each ID and value segment

Parameters:

text – The text to escape.

Returns:

The percent-encoded text.

Submodules

CODEC for converting ARI to and from text URI form.

class ace.ari_text.encode.EncodeOptions(scheme_prefix: bool = True, int_base: int = 10, float_form: str = 'g', text_identity: bool = True, time_text: bool = True, cbor_diag: bool = False)

Bases: object

Preferences for text encoding variations.

cbor_diag: bool = False

True if CBOR values should be in diagnostic form.

float_form: str = 'g'

One of ‘f’ or ‘g’ for standard format, or ‘x’ for raw hex

int_base: int = 10

One of 2, 10, or 16

scheme_prefix: bool = True

True if the scheme is present at the start.

text_identity: bool = True

True if specific text can be left unquoted.

time_text: bool = True

True if time values should be in text form.

class ace.ari_text.encode.Encoder(options: Optional[EncodeOptions] = None, **kwargs)

Bases: object

The encoder portion of this CODEC.

encode(obj: ARI, buf: TextIO)

Encode an ARI into UTF8 text.

Parameters:
  • obj – The ARI object to encode.

  • buf – The buffer to write into.

ace.ari_text.encode.can_unquote(text)

Determine if text can match an identity pattern.

ace.ari_text.encode.encode_datetime(value)
ace.ari_text.encode.encode_timedelta(value)
ace.ari_text.encode.quote(text)

URL-escape each ID and value segment

Parameters:

text – The text to escape.

Returns:

The percent-encoded text.

Lexer configuration for ARI text decoding.

ace.ari_text.lexmod.new_lexer(**kwargs)

Parser configuration for ARI text decoding.

ace.ari_text.parsemod.new_parser(**kwargs)

Utilities for text processing.

ace.ari_text.util.AMKEY = <ace.ari_text.util.TypeSeq object>

Allowed AM key literals.

ace.ari_text.util.FLOAT_FORM = {2: '!e', 4: '!f', 8: '!d'}

Map from IEEE-754 encoded size and struct format char.

ace.ari_text.util.IDSEGMENT = <ace.ari_text.util.TypeSeq object>

Either an integer or identity text.

ace.ari_text.util.MODID = <ace.ari_text.util.TypeSeq object>

Module namespace identity.

ace.ari_text.util.PRIMITIVE = <ace.ari_text.util.TypeSeq object>

Any untyped literal value

ace.ari_text.util.SINGLETONS = <ace.ari_text.util.TypeSeq object>

Types that match singleton values.

ace.ari_text.util.TYPEDLIT = {StructType.NULL: <ace.ari_text.util.TypeSeq object>, StructType.BOOL: <ace.ari_text.util.TypeSeq object>, StructType.BYTE: <ace.ari_text.util.TypeSeq object>, StructType.INT: <ace.ari_text.util.TypeSeq object>, StructType.UINT: <ace.ari_text.util.TypeSeq object>, StructType.VAST: <ace.ari_text.util.TypeSeq object>, StructType.UVAST: <ace.ari_text.util.TypeSeq object>, StructType.REAL32: <ace.ari_text.util.TypeSeq object>, StructType.REAL64: <ace.ari_text.util.TypeSeq object>, StructType.TEXTSTR: <ace.ari_text.util.TypeSeq object>, StructType.BYTESTR: <ace.ari_text.util.TypeSeq object>, StructType.TP: <ace.ari_text.util.TypeSeq object>, StructType.TD: <ace.ari_text.util.TypeSeq object>, StructType.LABEL: <ace.ari_text.util.TypeSeq object>, StructType.CBOR: <ace.ari_text.util.TypeSeq object>, StructType.ARITYPE: <function get_structtype>}

Map from literal types to value parsers.

class ace.ari_text.util.TypeMatch(pattern, parser)

Bases: object

Container for each literal leaf type.

static apply(pattern)

Decorator for parsing functions.

class ace.ari_text.util.TypeSeq(matchers: List[TypeMatch])

Bases: object

An ordered list of TypeMatch to check against.

ace.ari_text.util.get_structtype(text: str) StructType
ace.ari_text.util.part_to_int(digits)

Convert a text time part into integer, defaulting to zero.

ace.ari_text.util.subsec_to_microseconds(digits)

Convert subseconds text into microseconds, defaulting to zero.

ace.ari_text.util.unescape(esc: str) str

unescape tstr/bstr text