import capnp capnp.remove_import_hook() connection_capnp = capnp.load('schema/connection.capnp') authenticationsystem_capnp = capnp.load('schema/authenticationsystem.capnp') def connect(host, user, pw): """TODO: Docstring for connect. :returns: TODO """ client = capnp.TwoPartyClient(host) boot = client.bootstrap().cast_as(connection_capnp.Bootstrap) auth = boot.authenticationSystem().authenticationSystem req = auth.start_request() req.request.mechanism = "PLAIN" req.request.initialResponse.initial = "\0" + user + "\0" + pw rep_prom = req.send() response = rep_prom.wait() if response.response.outcome.result == "successful": return boot else: print("Auth failed") return None