nucypher.control

Subpackages

Submodules

class ControllerBase(interface: nucypher.control.interfaces.ControlInterface)

Bases: abc.ABC

A transactional interface for a human to interact with.

class InterfaceControlServer(app_name: str, crash_on_error: bool = False, *args, **kwargs)

Bases: nucypher.control.controllers.ControllerBase

abstract make_control_transport()
abstract handle_request(method_name, control_request)
abstract test_client()
class CLIController(app_name: str, crash_on_error: bool = False, *args, **kwargs)

Bases: nucypher.control.controllers.InterfaceControlServer

make_control_transport()
test_client()
handle_request(method_name, request)dict
class JSONRPCController(app_name: str, crash_on_error: bool = False, *args, **kwargs)

Bases: nucypher.control.controllers.InterfaceControlServer

start()
test_client()
make_control_transport()
handle_procedure_call(control_request)int
handle_message(message: dict, *args, **kwargs)int

Handle single JSON RPC message

handle_batch(control_requests: list)int
handle_request(control_request: bytes, *args, **kwargs)int
call_interface(method_name, request, request_id: int = None)
class WebController(app_name: str, crash_on_error: bool = False, *args, **kwargs)

Bases: nucypher.control.controllers.InterfaceControlServer

A wrapper around a JSON control interface that handles web requests to exert control over an implemented interface.

test_client()
make_control_transport()
start(port: int, tls_key_filepath: pathlib.Path = None, tls_certificate_filepath: pathlib.Path = None, dry_run: bool = False)
handle_request(method_name, control_request, *args, **kwargs) → flask.wrappers.Response
null_stream()
class StdoutEmitter(sink: Callable = None, verbosity: int = 1)

Bases: object

exception MethodNotFound

Bases: BaseException

Cannot find interface method to handle request

transport_serializer

alias of builtins.str

default_color = 'white'
default_sink_callable()

print(value, …, sep=’ ‘, end=’n’, file=sys.stdout, flush=False)

Prints the values to a stream, or to sys.stdout by default. Optional keyword arguments: file: a file-like object (stream); defaults to the current sys.stdout. sep: string inserted between values, default a space. end: string appended after the last value, default a newline. flush: whether to forcibly flush the stream.

clear()
message(message: str, color: str = None, bold: bool = False, verbosity: int = 1)
echo(message: str = None, color: str = None, bold: bool = False, nl: bool = True, verbosity: int = 0)
banner(banner)
ipc(response: dict, request_id: int, duration)
pretty(response)
error(e)
get_stream(verbosity: int = 0)
class JSONRPCStdoutEmitter(*args, **kwargs)

Bases: nucypher.control.emitters.StdoutEmitter

transport_serializer(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, separators=None, default=None, sort_keys=False, **kw)

Serialize obj to a JSON formatted str.

If skipkeys is true then dict keys that are not basic types (str, int, float, bool, None) will be skipped instead of raising a TypeError.

If ensure_ascii is false, then the return value can contain non-ASCII characters if they appear in strings contained in obj. Otherwise, all such characters are escaped in JSON strings.

If check_circular is false, then the circular reference check for container types will be skipped and a circular reference will result in an OverflowError (or worse).

If allow_nan is false, then it will be a ValueError to serialize out of range float values (nan, inf, -inf) in strict compliance of the JSON specification, instead of using the JavaScript equivalents (NaN, Infinity, -Infinity).

If indent is a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation.

If specified, separators should be an (item_separator, key_separator) tuple. The default is (', ', ': ') if indent is None and (',', ': ') otherwise. To get the most compact JSON representation, you should specify (',', ':') to eliminate whitespace.

default(obj) is a function that should return a serializable version of obj or raise TypeError. The default simply raises TypeError.

If sort_keys is true (default: False), then the output of dictionaries will be sorted by key.

To use a custom JSONEncoder subclass (e.g. one that overrides the .default() method to serialize additional types), specify it with the cls kwarg; otherwise JSONEncoder is used.

delimiter = '\n'
exception JSONRPCError

Bases: RuntimeError

code = None
message = 'Unknown JSON-RPC Error'
exception ParseError

Bases: nucypher.control.emitters.JSONRPCStdoutEmitter.JSONRPCError

code = -32700
message = 'Invalid JSON was received by the server.'
exception InvalidRequest

Bases: nucypher.control.emitters.JSONRPCStdoutEmitter.JSONRPCError

code = -32600
message = 'The JSON sent is not a valid Request object.'
exception MethodNotFound

Bases: nucypher.control.emitters.JSONRPCStdoutEmitter.JSONRPCError

code = -32601
message = 'The method does not exist / is not available.'
exception InvalidParams

Bases: nucypher.control.emitters.JSONRPCStdoutEmitter.JSONRPCError

code = -32602
message = 'Invalid method parameter(s).'
exception InternalError

Bases: nucypher.control.emitters.JSONRPCStdoutEmitter.JSONRPCError

code = -32603
message = 'Internal JSON-RPC error.'
static assemble_response(response: dict, message_id: int)dict
static assemble_error(message, code, data=None)dict
clear()
message(message: str, **kwds)
echo(*args, **kwds)
banner(banner)
ipc(response: dict, request_id: int, duration)int

Write RPC response object to stdout and return the number of bytes written.

error(e)

Write RPC error object to stdout and return the number of bytes written.

get_stream(*args, **kwargs)
class WebEmitter(sink: Callable = None, crash_on_error: bool = False, *args, **kwargs)

Bases: object

exception MethodNotFound

Bases: BaseException

Cannot find interface method to handle request

transport_serializer(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, separators=None, default=None, sort_keys=False, **kw)

Serialize obj to a JSON formatted str.

If skipkeys is true then dict keys that are not basic types (str, int, float, bool, None) will be skipped instead of raising a TypeError.

If ensure_ascii is false, then the return value can contain non-ASCII characters if they appear in strings contained in obj. Otherwise, all such characters are escaped in JSON strings.

If check_circular is false, then the circular reference check for container types will be skipped and a circular reference will result in an OverflowError (or worse).

If allow_nan is false, then it will be a ValueError to serialize out of range float values (nan, inf, -inf) in strict compliance of the JSON specification, instead of using the JavaScript equivalents (NaN, Infinity, -Infinity).

If indent is a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation.

If specified, separators should be an (item_separator, key_separator) tuple. The default is (', ', ': ') if indent is None and (',', ': ') otherwise. To get the most compact JSON representation, you should specify (',', ':') to eliminate whitespace.

default(obj) is a function that should return a serializable version of obj or raise TypeError. The default simply raises TypeError.

If sort_keys is true (default: False), then the output of dictionaries will be sorted by key.

To use a custom JSONEncoder subclass (e.g. one that overrides the .default() method to serialize additional types), specify it with the cls kwarg; otherwise JSONEncoder is used.

static assemble_response(response: dict)dict
exception(e, error_message: str, log_level: str = 'info', response_code: int = 500)
respond(response) → flask.wrappers.Response
get_stream(*args, **kwargs)
attach_schema(schema)
class ControlInterface(implementer=None, *args, **kwargs)

Bases: object

classmethod connect_cli(action, exclude: Optional[Set[str]] = None)

Provides click CLI options based on the defined schema for the action.

“exclude” can be used to allow CLI to exclude a subset of click options from the schema from being defined, and allow the CLI to define them differently. For example, it can be used to exclude a required schema click option and allow the CLI to make it not required.