def dumpd(params, methodname=None, methodresponse=None, encoding=None, allow_none=False, tid=None): assert tid is not None, "need a transaction identifier" if methodname: out = bencode({'y':'q', 't':tid, 'q':methodname, 'a':params}) elif isinstance(params, DFault): out = bencode({'y':'e', 't':tid, 'c':params.faultCode, 's':params.faultString}) elif methodresponse: out = bencode({'y':'r', 't':tid, 'r':params}) else: raise Error("") return out
def dumps(params, methodname=None, methodresponse=None, encoding=None, allow_none=False): if methodresponse and isinstance(params, TupleType): assert len(params) == 1, "response tuple must be a singleton" if methodname: out = bencode({'y':'q', 'q':methodname, 'a':params}) elif isinstance(params, Fault): out = bencode({'y':'e', 'c':params.faultCode, 's':params.faultString}) elif methodresponse: out = bencode({'y':'r', 'r':params[0]}) else: raise Error("") return out