ait.core.seq module

AIT Sequences

The ait.core.seq module provides sequences of commands.

class ait.core.seq.Seq(pathname=None, cmddict=None, id=None, version=0)

Bases: object

Seq - Sequence

__init__(pathname=None, cmddict=None, id=None, version=0)

Creates a new AIT Command Sequence

Creates an empty sequence which will be encoded and decoded based on the given command dictionary (default: cmd.DefaultCmdDict). If the optional pathname is given, the command sequence (text or binary) will be read from it.

append(cmd, delay=0.0, attrs=None)

Adds a new command with a relative time delay to this sequence.

printText(stream=None)

Prints a text representation of this sequence to the given stream or standard output.

read(filename=None)

Reads a command sequence from the given filename (defaults to self.pathname).

readBinary(filename=None)

Reads a binary command sequence from the given filename (defaults to self.pathname).

readText(filename=None)

Reads a text command sequence from the given filename (defaults to self.pathname).

validate()

Returns True if this Sequence is valid, False otherwise. Validation error messages are stored in self.messages.

writeBinary(filename=None)

Writes a binary representation of this sequence to the given filename (defaults to self.binpath).

writeText(filename=None)

Writes a text representation of this sequence to the given filename (defaults to self.txtpath).

Magic = 3075
binpath

The full path to the binary sequence filename.

cmddict

The command dictionary used to encode and decode this sequence.

commands

The ordered list of SeqCmds in this sequence.

duration

The total duration of this sequence.

pathname

The underlying sequence pathname.

txtpath

The full path to the text sequence filename.

class ait.core.seq.SeqAtom(pos=None)

Bases: object

SeqAtom - Sequence Atom

Sequence atoms are the smallest unit of a sequence. This class serves as a base class for specific parts of a sequence, e.g. header, comments, commands, attributes, and meta-commands.

__init__(pos=None)

Creates a new SeqAtom with the given SeqPos.

classmethod decode(bytes, cmddict=None)

Decodes an SeqAtom from an array of bytes, according to the given command dictionary, and returns a new SeqAtom.

encode()

Encodes this SeqAtom to binary and returns a bytearray.

classmethod parse(line, lineno, log, cmddict=None)

Parses the SeqAtom from a line of text, according to the given command dictionary, and returns a new SeqAtom or None. Warning and error messages are logged via the SeqMsgLog log.

validate(log)

Returns True if this SeqAtom is valid, False otherwise. Warning and error messages are logged via the SeqMsgLog log.

class ait.core.seq.SeqCmd(cmd, delay=0.0, attrs=None, comment=None, pos=None)

Bases: ait.core.seq.SeqAtom

SeqCmd - Sequence Command

Each SeqCmd contains a command, a relative time delay, and command attributes. New SeqCmds may be created with an explicit cmd.Cmd and decimal delay (SeqCmd()), via an array of bytes (decode()), or a line of text (parse()).

__init__(cmd, delay=0.0, attrs=None, comment=None, pos=None)

Creates a new SeqCmd.

classmethod decode(bytes, cmddict)

Decodes a sequence command from an array of bytes, according to the given command dictionary, and returns a new SeqCmd.

encode()

Encodes this SeqCmd to binary and returns a bytearray.

classmethod parse(line, lineno, log, cmddict)

Parses the sequence command from a line of text, according to the given command dictionary, and returns a new SeqCmd.

class ait.core.seq.SeqCmdAttrs(attrs=None, pos=None)

Bases: ait.core.seq.SeqAtom

SeqCmdAttrs - Sequence Command Attributes

Each sequence command may be annotated with attributes following the command by using the following syntax:

{ name: value, … }
__init__(attrs=None, pos=None)

Creates a new SeqCmdAttrs.

classmethod decode(bytes, cmddict=None)

Decodes sequence command attributes from an array of bytes and returns a new SeqCmdAttrs.

encode()

Encodes this SeqCmdAttrs to binary and returns a bytearray.

classmethod parse(line, lineno, log, cmddict=None)

Parses a SeqCmdAttrs from a line of text and returns it or None. Warning and error messages are logged via the SeqMsgLog log.

Table = [[7, 'OnError', 'Halt', 'Continue', 'Halt'], [6, 'Attribute6', 'Value0', 'Value1', 'Value0'], [5, 'Attribute5', 'Value0', 'Value1', 'Value0'], [4, 'Attribute4', 'Value0', 'Value1', 'Value0'], [3, 'Attribute3', 'Value0', 'Value1', 'Value0'], [2, 'Attribute2', 'Value0', 'Value1', 'Value0'], [1, 'Attribute1', 'Value0', 'Value1', 'Value0'], [0, 'Attribute0', 'Value0', 'Value1', 'Value0']]
default

The default sequence command attributes (as an integer).

class ait.core.seq.SeqComment(comment, pos=None)

Bases: ait.core.seq.SeqAtom

SeqComment - Sequence Comment

Sequence comments are parsed for completeness, but are ignored when translating a sequence to its binary representation.

__init__(comment, pos=None)

Creates a new SeqComment.

classmethod parse(line, lineno, log, cmddict=None)

Parses the SeqComment from a line of text. Warning and error messages are logged via the SeqMsgLog log.

class ait.core.seq.SeqDelay(delay=0.0, pos=None)

Bases: ait.core.seq.SeqAtom

SeqDelay - Sequence Delay

Sequence lines begin with a decimal relative time delay.

__init__(delay=0.0, pos=None)

Creates a new SeqDelay with the given relative time delay.

classmethod decode(bytes, cmddict=None)

Decodes a sequence delay from an array of bytes, according to the given command dictionary, and returns a new SeqDelay.

encode()

Encodes this SeqDelay to a binary bytearray.

classmethod parse(line, lineno, log, cmddict=None)

Parses the SeqDelay from a line of text. Warning and error messages are logged via the SeqMsgLog log.

validate(log)

Returns True if this SeqDelay is valid, False otherwise. Warning and error messages are logged via the SeqMsgLog log.

class ait.core.seq.SeqMetaCmd(metacmd, pos=None)

Bases: ait.core.seq.SeqAtom

SeqMetaCmd - Sequence Meta-Command

Sequence meta-commands are parsed and executed locally, but are ignored when translating a sequence to its binary representation.

__init__(metacmd, pos=None)

Creates a new SeqMetaCmd.

classmethod parse(line, lineno, log, cmddict=None)

Parses the SeqMetaCmd from a line of text. Warning and error messages are logged via the SeqMsgLog log.

class ait.core.seq.SeqMsgLog(filename=None)

Bases: object

SeqMsgLog - Sequence Message Log

SeqMsgLog logs warning and errors encountered during sequence parsing and validation.

__init__(filename=None)

Creates a new SeqMsgLog pertaining to the given sequence filename.

error(msg, pos=None)

Logs an error message pertaining to the given SeqPos.

location(pos)

Formats the location of the given SeqPos as:

filename:line:col:

log(msg, prefix=None)

Logs a message with an optional prefix.

warning(msg, pos=None)

Logs a warning message pertaining to the given SeqAtom.

class ait.core.seq.SeqPos(line=None, lineno=1, start=1, stop=None)

Bases: object

SeqPos - Sequence Position

Each SeqAtom contains a SeqPos to locate the atom within the text sequence.

__init__(line=None, lineno=1, start=1, stop=None)

Creates a new SeqPos from the given line in the sequence and start and stop line and character positions within the line.

ait.core.seq.setBit(value, bit, bitval)

Returns value with a specific bit position set to bitval.