Receiving input from external processes

General interface

Reading from a bunch of input sockets

class seismometer.input.Reader

Network reader, polling for a line and converting it to proper message.

This is a base class for different line-based protocols. See JSONReader for an example implementation.

add(sock)

Add a socket to poll list.

parse_line(host, line)
Parameters:
  • host – name of the host that sent the message
  • line – serialized message sent from the host

Parse line to a usable message. Method should return None if nothing could be parsed.

Method to be implemented in subclass.

read()
Return type:dict

Read a message from polled sockets.

Raises EOF when there is no more sockets to read from.

class seismometer.input.JSONReader

Network reader, expecting JSON object per line.

exception seismometer.input.EOF

EOF condition on all the inputs.

Specific input modules

STDIN input reader

class seismometer.input.stdin.STDIN

Socket-like class for reading from standard input.

Network sockets: TCP and UDP

class seismometer.input.inet.TCP(host, port)

Listening TCP socket. Not intended for reading itself, instead returns connection objects.

Parameters:
  • host (string or None) – bind address
  • port (integer) – bind address
accept()
Return type:TCPConnection

Accept a connection.

class seismometer.input.inet.TCPConnection(conn, host)

TCP connection reader.

Instances of this class are created by TCP.

Parameters:
  • conn (socket.socket()) – connection descriptor
  • host (string) – remote end address
close()

Close TCP connection.

fileno()

Return file descriptor for poll()

readline()
Returns:(host, string)

Read complete line (or lines) from the connection.

class seismometer.input.inet.UDP(host, port)

Listening UDP socket.

Parameters:
  • host (string or None) – bind address
  • port (integer) – bind address
fileno()

Return file descriptor for poll()

readline()
Returns:(host, string)

Read a single line sent to this port.

UNIX domain sockets

class seismometer.input.unix.UNIX(path)

Listening UNIX datagram socket.

Parameters:path (string) – socket address