def pack_reply(xid, *args): """Packs an RPC reply from a variable-length arg list (args): MSG_ACCEPTED, verf, (SUCCESS | PROG_MISMATCH, low, hi | PROG_UNAVAIL | PROC_UNAVAIL | GARBAGE_ARGS | SYSTEM_ERR) MSG_DENIED, (RPC_MISMATCH, hi, low | AUTH_ERROR, auth_stat) verf is an auth of the form (flavor, value) Returns an xdrlib.Packer that the caller can use to add data, such as the results of a SUCCESSful call. """ arg = list(args) # need a mutable list for pop() msg = RPCProto.rpc_msg() msg.xid = xid msg.body = RPCProto.body_t() msg.body.mtype = RPCProto.REPLY msg.body.rbody = reply = RPCProto.reply_body() reply.stat = reply_stat = arg.pop(0) if reply_stat == MSG_ACCEPTED: reply.areply = RPCProto.accepted_reply() reply.areply.verf = verf = arg.pop(0) reply.areply.reply_data = RPCProto.reply_data_t() reply.areply.reply_data.stat = accept_stat = arg.pop(0) if accept_stat == PROG_MISMATCH: reply.areply.reply_data.mismatch_info = RPCProto.mismatch_info_t() reply.areply.reply_data.mismatch_info.low = arg.pop(0) reply.areply.reply_data.mismatch_info.high = arg.pop(0) elif (accept_stat == SUCCESS): reply.areply.reply_data.results = '' # FIXME? elif (accept_stat == PROG_UNAVAIL or accept_stat == PROC_UNAVAIL or accept_stat == GARBAGE_ARGS or accept_stat == SYSTEM_ERR): pass else: raise ValueError("unknown accept_stat: %u" % accept_stat) elif reply_stat == MSG_DENIED: reply.rreply = RPCProto.rejected_reply() reply.rreply.stat = reject_stat = arg.pop(0) if reject_stat == RPC_MISMATCH: reply.rreply.mismatch_info.low = RPCProto.mismatch_info_t() reply.rreply.mismatch_info.low = arg.pop(0) reply.rreply.mismatch_info.high = arg.pop(0) elif reject_stat == AUTH_ERROR: reply.rreply.astat = arg.pop(0) else: raise ValueError("unknown reject_stat: %u" % reject_stat) else: raise ValueError("unknown reply_stat: %u" % reply_stat) p = Packer() RPCProto.pack_rpc_msg(p, msg) return p