def receive(self): buffer_receiver = protocol.STRING.receive() request = buffer_receiver.next() #pylint: disable=E1101 while isinstance(request, protocol.Request): value = yield request request = buffer_receiver.send(value) #pylint: disable=E1101 if not isinstance(request, protocol.Result): raise TypeError read = StringIO.StringIO(request.value).read routing = parse_nursery_routing(read) config_count = utils.read_blocking(protocol.UINT32.receive(), read) configs = {} for _ in xrange(config_count): cluster_id = utils.read_blocking(protocol.STRING.receive(), read) cluster_size = utils.read_blocking(protocol.UINT32.receive(), read) config = {} for _ in xrange(cluster_size): node_id = utils.read_blocking(protocol.STRING.receive(), read) ips = utils.read_blocking( protocol.List(protocol.STRING).receive(), read) port = utils.read_blocking(protocol.UINT32.receive(), read) config[node_id] = (tuple(ips), port) configs[cluster_id] = config yield protocol.Result(NurseryConfig(routing, configs))
def handle_prefix_keys(): '''Handle a "prefix_keys" command''' _ = recv(protocol.BOOL) prefix = recv(protocol.STRING) max_elements = recv(protocol.UINT32) matches = [ key for key in self._values.iterkeys() if key.startswith(prefix) ] matches = matches if max_elements < 0 else matches[:max_elements] for rbytes in protocol.UINT32.serialize(protocol.RESULT_SUCCESS): yield rbytes for rbytes in protocol.List(protocol.STRING).serialize(matches): yield rbytes