Developers’ documentation

Module fsa

Finite State Automata

class fsa4streams.fsa.FSA(structure, check_structure=True)[source]

A Finite State Automaton.

classmethod from_str(json_str)[source]
classmethod from_file(json_filelike)[source]
classmethod from_dict(dictobj)[source]
classmethod make_empty(**kw)[source]

TODO doc: must call check_structure() in the end

add_state(stateid, **kw)[source]

TODO doc

IMPORTANT: ‘target’ may not exist yet, so it not checked. Hence, check_structure() should be called in the end.

check_structure(raises=True)[source]
allow_overlap
default_matcher
export_structure_as_dict()[source]
export_structure_as_string(*args, **kw)[source]
export_strutcure_to_file(fp, *args, **kw)[source]
reset()[source]
is_busy()[source]
load_tokens_from_str(json_str, force=False)[source]
load_tokens_from_file(json_filelike, force=False)[source]
load_tokens_from_dict(dictobj, force=False)[source]
export_tokens_as_dict()[source]
export_tokens_as_string(*args, **kw)[source]
export_tokens_to_file(fp, *args, **kw)[source]
match(transition, event, token)[source]
feed(event, timestamp=None)[source]

I ingest event, and I return a list of matching tokens.

A matching token is a token that has reached a final state, and can not further progress in the FSA.

If provided, timestamp must be an integer greater or equal than all previous timestamps; the default value is the previous timestamp + 1. Timestamps are used to check max_duration constraints.

feed_all(iterable, finish=True)[source]
feed_all_timestamps(iterable, finish=True)[source]
finish()[source]

Module state

class fsa4streams.state.State(fsa, stateid)[source]

A proxy object for a state in a FSA.

fsa
id
terminal

TODO doc

max_noise

TODO doc

max_total_noise

TODO doc

max_duration

TODO doc

max_total_duration

TODO doc

default_transition

TODO doc

transitions

TODO doc

add_state(*args, **kw)[source]

Shortcut method to self.fsa.add_state, useful for chaining them.

check_structure(raises=True)[source]

Shortcut method to self.fsa.check_structure, useful for chaining them.

add_transition(condition, target, **kw)[source]

TODO doc return this state to allow chaining IMPORTANT: ‘target’ may not exist yet, so it not checked. Hence, check_structure should be called in the end.

set_default_transition(target, **kw)[source]

TODO doc return this state to allow chaining IMPORTANT: ‘target’ may not exist yet, so it not checked. Hence, check_structure should be called in the end.

Module matcher

fsa4streams.matcher.DIRECTORY = a dict

It originally contains all the matchers contained in this module.

fsa4streams.matcher.match_multiple_choices(transition, event, _token, _fsa)[source]

The ‘multiple-choices’ matcher.

With this matcher, transition conditions must be lists of strings. It matches an event if that event is equal to one of the items of the list.

fsa4streams.matcher.match_regexp(transition, event, _token, _fsa)[source]

The ‘regexp’ matcher.

With this matcher, transition conditions are interpreted as regular expressions. Note that the whole event must match the regular expression (this is ensured by automatically prepending ^ and appending $ to the condition).