nucypher.characters.control

Submodules

class CharacterControllerBase

Bases: abc.ABC

A transactional interface for a human to interact with all of one characters entry and exit points.

Subclasses of CharacterControllerBase handle a character’s public interface I/O, serialization, interface specification, validation, and transport.

(stdio, http, in-memory python containers, other IPC, or another protocol.)

class CharacterControlServer(app_name: str, interface: nucypher.characters.control.interfaces.CharacterPublicInterface, start_learning: bool = True, crash_on_error: bool = False, *args, **kwargs)

Bases: nucypher.characters.control.controllers.CharacterControllerBase

abstract make_control_transport()
abstract handle_request(method_name, control_request)
abstract test_client()
class CLIController(app_name: str, interface: nucypher.characters.control.interfaces.CharacterPublicInterface, start_learning: bool = True, crash_on_error: bool = False, *args, **kwargs)

Bases: nucypher.characters.control.controllers.CharacterControlServer

make_control_transport()
test_client()
handle_request(method_name, request)dict
class JSONRPCController(app_name: str, interface: nucypher.characters.control.interfaces.CharacterPublicInterface, start_learning: bool = True, crash_on_error: bool = False, *args, **kwargs)

Bases: nucypher.characters.control.controllers.CharacterControlServer

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, interface: nucypher.characters.control.interfaces.CharacterPublicInterface, start_learning: bool = True, crash_on_error: bool = False, *args, **kwargs)

Bases: nucypher.characters.control.controllers.CharacterControlServer

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

test_client()
make_control_transport()
start(http_port: int, 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)
error(e)
get_stream(verbosity: int = 0)
class JSONRPCStdoutEmitter(*args, **kwargs)

Bases: nucypher.characters.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.characters.control.emitters.JSONRPCStdoutEmitter.JSONRPCError

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

Bases: nucypher.characters.control.emitters.JSONRPCStdoutEmitter.JSONRPCError

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

Bases: nucypher.characters.control.emitters.JSONRPCStdoutEmitter.JSONRPCError

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

Bases: nucypher.characters.control.emitters.JSONRPCStdoutEmitter.JSONRPCError

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

Bases: nucypher.characters.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 CharacterPublicInterface(character=None, *args, **kwargs)

Bases: object

classmethod connect_cli(action)
class AliceInterface(character=None, *args, **kwargs)

Bases: nucypher.characters.control.interfaces.CharacterPublicInterface

create_policy(bob_encrypting_key: bytes, bob_verifying_key: bytes, label: bytes, m: int, n: int, expiration: maya.core.MayaDT, value: int = None)dict
derive_policy_encrypting_key(label: bytes)dict
grant(bob_encrypting_key: bytes, bob_verifying_key: bytes, label: bytes, m: int, n: int, expiration: maya.core.MayaDT, value: int = None, rate: int = None)dict
revoke(label: bytes, bob_verifying_key: bytes)dict
decrypt(label: bytes, message_kit: bytes)dict

Character control endpoint to allow Alice to decrypt her own data.

public_keys()dict

Character control endpoint for getting Alice’s public keys.

class BobInterface(character=None, *args, **kwargs)

Bases: nucypher.characters.control.interfaces.CharacterPublicInterface

join_policy(label: bytes, alice_verifying_key: bytes)

Character control endpoint for joining a policy on the network.

retrieve(label: bytes, policy_encrypting_key: bytes, alice_verifying_key: bytes, message_kit: bytes, treasure_map: Union[bytes, str, TreasureMap] = None)

Character control endpoint for re-encrypting and decrypting policy data.

public_keys()

Character control endpoint for getting Bob’s encrypting and signing public keys

class EnricoInterface(character=None, *args, **kwargs)

Bases: nucypher.characters.control.interfaces.CharacterPublicInterface

encrypt_message(plaintext: Union[str, bytes])

Character control endpoint for encrypting data for a policy and receiving the messagekit (and signature) to give to Bob.