6. ASTM protocol implementation

6.1. astm.protocol :: Common protocol routines

astm.protocol.STATE = ASTMState(init=0, opened=1, transfer=2)

ASTM protocol states set.

class astm.protocol.ASTMProtocol(sock=None, map=None, timeout=None)[source]

Common ASTM protocol routines.

astm_header

ASTM header record class.

alias of GenericRecord

astm_terminator

ASTM terminator record class.

alias of GenericRecord

dispatch(data)[source]

Dispatcher of received data.

is_chunked_transfer = None

Flag about chunked transfer.

on_ack()[source]

Calls on <ACK> message receiving.

on_enq()[source]

Calls on <ENQ> message receiving.

on_eot()[source]

Calls on <EOT> message receiving.

on_init_state()[source]

Calls on set state INIT (0)

on_message()[source]

Calls on ASTM message receiving.

on_nak()[source]

Calls on <NAK> message receiving.

on_opened_state()[source]

Calls on set state OPENED (1)

on_timeout()[source]

Calls when timeout event occurs. Used to limit time for waiting response data.

on_transfer_state()[source]

Calls on set state TRANSFER (2)

set_init_state()[source]

Sets handler state to INIT (0).

In ASTM specification this state also called as neutral which means that handler is ready to establish data transfer.

set_opened_state()[source]

Sets handler state to OPENED (1).

Intermediate state that only means for client implementation. On this state client had already sent <ENQ> and awaits for <ACK> or <NAK> response. On <ACK> it switched his state to transfer.

set_transfer_state()[source]

Sets handler state to TRANSFER (2).

In this state handler is able to send or receive ASTM messages depending on his role (client or server). At the end of data transfer client should send <EOT> and switch state to init.

state

ASTM handler state value:

  • init: Neutral state
  • opened: ENQ message was sent, waiting for ACK
  • transfer: Data transfer processing
timeout = None

Operation timeout value.

6.2. astm.server :: ASTM Server

class astm.server.BaseRecordsDispatcher(encoding=None)[source]

Dispatcher of received ASTM records by RequestHandler.

encoding = 'latin-1'

Encoding of received messages.

on_comment(record)[source]

Comment record handler.

on_header(record)[source]

Header record handler.

on_order(record)[source]

Order record handler.

on_patient(record)[source]

Patient record handler.

on_result(record)[source]

Result record handler.

on_terminator(record)[source]

Terminator record handler.

on_unknown(record)[source]

Fallback handler for dispatcher.

class astm.server.RequestHandler(sock, dispatcher)[source]

ASTM protocol request handler.

Parameters:
  • sock – Socket object.
  • dispatcher (BaseRecordsDispatcher) – Request handler records dispatcher instance.
class astm.server.Server(host='localhost', port=15200, request=None, dispatcher=None)[source]

Asyncore driven ASTM server.

Parameters:
  • host (str) – Server IP address or hostname.
  • port (int) – Server port number.
  • request – Custom server request handler. If omitted the RequestHandler will be used by default.
  • dispatcher – Custom request handler records dispatcher. If omitted the BaseRecordsDispatcher will be used by default.
dispatcher

alias of BaseRecordsDispatcher

request

alias of RequestHandler

serve_forever(*args, **kwargs)[source]

Enters into the polling loop to let server handle incoming requests.

6.3. astm.client :: ASTM Client

class astm.client.Client(emitter, host='localhost', port=15200, timeout=20, retry_attempts=3, records_sm=<astm.client.RecordsStateMachine object at 0x1ae2a90>)[source]

Common ASTM client implementation.

Parameters:
  • emitter (function) – Generator function that will produce ASTM records.
  • host (str) – Server IP address or hostname.
  • port (int) – Server port number.
  • timeout (int) – Time to wait for response from server. If response wasn’t received, the on_timeout() will be called. If None this timer will be disabled.
  • retry_attempts (int) – Number or attempts to send record to server.
  • records_sm – Records type state machine that controls right order of generated records by the emitter. The default state machine may be replaced by any callable which takes single argument as record type.
Type :

callable

emit_header()[source]

Returns Header record.

emit_terminator()[source]

Returns Terminator record.

push(data, with_timer=True)[source]

Pushes data on to the channel’s fifo to ensure its transmission with optional timer. Timer is used to control receiving response for sent data within specified time frame. If it’s doesn’t on_timeout() method will be called and data may be sent once again.

Parameters:
  • data (str) – Sending data.
  • with_timer (bool) – Flag to use timer.
push_record(record)[source]

Sends single ASTM record and autoincrement frame sequence number.

Parameters:record (list or Record) – ASTM record object.

Records should be sent in specific order or AssertionError will be raised:

Legend:

Previous record type Current record type
None, this is first record H
H P, L
P P, O, C, L
O O, R, C, L
R R, C, L
L H
run(*args, **kwargs)[source]

Enters into the polling loop to let client send outgoing requests.

Project Versions

Table Of Contents

Previous topic

5. astm.asynclib :: Asynchronous socket handler

Next topic

7. ASTM implemetation modules

This Page