def handle(self, identity, message_content): helper = _ClientHelper( message_content, client_pb2.ClientStateListRequest, client_pb2.ClientStateListResponse, validator_pb2.Message.CLIENT_STATE_LIST_RESPONSE, tree=self._tree, block_store=self._block_store) helper.set_root() if helper.has_response(): return helper.result # Fetch leaves and encode as protobuf leaves = [ client_pb2.Leaf(address=a, data=v) for a, v in self._tree.leaves( helper.request.address or '').items() ] if leaves: helper.set_response(helper.status.OK, head_id=helper.head_id, leaves=leaves) else: helper.set_response(helper.status.NO_RESOURCE, head_id=helper.head_id) return helper.result
def _respond(self, request): head_id = self._set_root(request) # Fetch leaves and encode as protobuf leaves = [ client_pb2.Leaf(address=a, data=v) for a, v in self._tree.leaves(request.address or '').items() ] # Order leaves, remove if tree.leaves refactored to be ordered leaves.sort(key=lambda l: l.address) leaves = _Sorter.sort_resources(request, leaves, self._status.INVALID_SORT) leaves, paging = _Pager.paginate_resources(request, leaves, self._status.INVALID_PAGING) if not leaves: return self._wrap_response(self._status.NO_RESOURCE, head_id=head_id, paging=paging) return self._wrap_response(head_id=head_id, paging=paging, leaves=leaves)
def _respond(self, request): head_id = self._set_root(request) # Fetch leaves and encode as protobuf leaves = [ client_pb2.Leaf(address=a, data=v) for a, v in self._tree.leaves(request.address or '').items() ] if not leaves: return self._wrap_response(self._status.NO_RESOURCE, head_id=head_id) return self._wrap_response(head_id=head_id, leaves=leaves)