nxt.remote.nxt_socket module

class COM_TYPE[source]

Bases: object

Constants used as keys in the pickled message dicts sent over to the nxt socket server.

LOG = 'log'
CACHE = 'cache'
SHUTDOWN = 'shutdown'
PING = 'ping'
WAIT = 'wait'
ERR = 'error'
setup()[source]

Setup a connection to the nxt socket server. Sets the global variable __nxt_server__ to the newly created socket instance. :return: socket instance

format_msg(msg, com_typ, msg_dict=None)[source]

Formats the given msg into a dict matching the expected format used by nxt socket servers and clients. :param msg: Object to be formatted as a socket message :param com_typ: COM_TYPE constant :param msg_dict: Optionally if you are combining commands you can pass an existing msg_dict returned from a previous call to this function. :return: dict

get_nxt_model()[source]

Gets the existing SocketClientModel instance in global scope, if none is found a new one is created and returned. It is stored in the global scope to allow maximum context compatibility. :return: SocketClientModel instance

class SocketClientModel(com_server)[source]

Bases: object

Simple nxt model used by remote socket clients

load(filepath)[source]

Loads the given file path and builds a comp layer ready to be executed. :param filepath: string of nxt save filepath. :return: None

run(exec_order=())[source]

General purpose run function meant to be called over a socket command port. If a GraphError is raised the internal nxt ERR message is sent over the socket to the server. :param exec_order: Optional list of node paths to execute. :return: None

refresh()[source]

Refresh (rebuild) stage and comp objects. :return: None

close(notify_server=False)[source]

Attempts to gracefully close connection to nxt socket server.

open()[source]

Opens connection to nxt socket server. Installs NXTSocketLogHandler logging handler if none is installed. :return: None

ping()[source]

Debug function for testing 2 way communication from the nxt socket server to this client. :return:

get_cache()[source]

Method for the nxt socket server to request cache data from this client model. :return: Save data dict

send_log(record)[source]

Simple method for sending log records to an nxt socket server. :param record: logging record :return: None

send_to_server(data_dict)[source]

Pickles the given data, assembles fixed length header, casts to bytes and sends to the nxt socket server. NOTE: This function catches ALL exceptions raised by the socket instance! :param data_dict: Dict formatted by format_msg :return: None

class IPCWait(model)[source]

Bases: object

Simple context manager for telling the server to wait while a command is being processed by the client interpreter.

send_wait_msg(state)[source]
class NXTSocketLogHandler[source]

Bases: logging.Handler

Simple logging handler for emitting log records to the nxt socket server.

emit(record)[source]

Do whatever it takes to actually log the specified logging record.

This version is intended to be implemented by subclasses and so raises a NotImplementedError.