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
()¶
-
abstract
-
class
CLIController
(app_name: str, crash_on_error: bool = False, *args, **kwargs)¶ Bases:
nucypher.control.controllers.InterfaceControlServer
-
make_control_transport
()¶
-
test_client
()¶
-
-
class
JSONRPCController
(app_name: str, crash_on_error: bool = False, *args, **kwargs)¶ Bases:
nucypher.control.controllers.InterfaceControlServer
-
start
()¶
-
test_client
()¶
-
make_control_transport
()¶
-
-
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)¶
-
static
json_response_from_worker_pool_exception
(exception)¶
-
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
()¶
-
echo
(message: str = None, color: str = None, bold: bool = False, nl: bool = True, verbosity: int = 0)¶
-
pretty
(response)¶
-
error
(e)¶
-
exception
-
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 formattedstr
.If
skipkeys
is true thendict
keys that are not basic types (str
,int
,float
,bool
,None
) will be skipped instead of raising aTypeError
.If
ensure_ascii
is false, then the return value can contain non-ASCII characters if they appear in strings contained inobj
. 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 anOverflowError
(or worse).If
allow_nan
is false, then it will be aValueError
to serialize out of rangefloat
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 isNone
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 thecls
kwarg; otherwiseJSONEncoder
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.'¶
-
-
clear
()¶
-
echo
(*args, **kwds)¶
-
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 formattedstr
.If
skipkeys
is true thendict
keys that are not basic types (str
,int
,float
,bool
,None
) will be skipped instead of raising aTypeError
.If
ensure_ascii
is false, then the return value can contain non-ASCII characters if they appear in strings contained inobj
. 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 anOverflowError
(or worse).If
allow_nan
is false, then it will be aValueError
to serialize out of rangefloat
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 isNone
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 thecls
kwarg; otherwiseJSONEncoder
is used.
-
exception_with_response
(json_error_response, e, error_message: str, response_code: int, log_level: str = 'info')¶
-
respond
(json_response) → flask.wrappers.Response¶
-
get_stream
(*args, **kwargs)¶
-
exception
-
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.
-
classmethod