data [,options] -> marshalled data Convert an argument tuple or a Fault instance to an XML-RPC request (or response, if the methodresponse option is used). In addition to the data object, the following options can be given as keyword arguments: methodname: the meth
(params, methodname=None, methodresponse=None, encoding=None,
allow_none=False)
| 942 | # @return A string containing marshalled data. |
| 943 | |
| 944 | def dumps(params, methodname=None, methodresponse=None, encoding=None, |
| 945 | allow_none=False): |
| 946 | """data [,options] -> marshalled data |
| 947 | |
| 948 | Convert an argument tuple or a Fault instance to an XML-RPC |
| 949 | request (or response, if the methodresponse option is used). |
| 950 | |
| 951 | In addition to the data object, the following options can be given |
| 952 | as keyword arguments: |
| 953 | |
| 954 | methodname: the method name for a methodCall packet |
| 955 | |
| 956 | methodresponse: true to create a methodResponse packet. |
| 957 | If this option is used with a tuple, the tuple must be |
| 958 | a singleton (i.e. it can contain only one element). |
| 959 | |
| 960 | encoding: the packet encoding (default is UTF-8) |
| 961 | |
| 962 | All byte strings in the data structure are assumed to use the |
| 963 | packet encoding. Unicode strings are automatically converted, |
| 964 | where necessary. |
| 965 | """ |
| 966 | |
| 967 | assert isinstance(params, (tuple, Fault)), "argument must be tuple or Fault instance" |
| 968 | if isinstance(params, Fault): |
| 969 | methodresponse = 1 |
| 970 | elif methodresponse and isinstance(params, tuple): |
| 971 | assert len(params) == 1, "response tuple must be a singleton" |
| 972 | |
| 973 | if not encoding: |
| 974 | encoding = "utf-8" |
| 975 | |
| 976 | if FastMarshaller: |
| 977 | m = FastMarshaller(encoding) |
| 978 | else: |
| 979 | m = Marshaller(encoding, allow_none) |
| 980 | |
| 981 | data = m.dumps(params) |
| 982 | |
| 983 | if encoding != "utf-8": |
| 984 | xmlheader = "<?xml version='1.0' encoding='%s'?>\n" % str(encoding) |
| 985 | else: |
| 986 | xmlheader = "<?xml version='1.0'?>\n" # utf-8 is default |
| 987 | |
| 988 | # standard XML-RPC wrappings |
| 989 | if methodname: |
| 990 | # a method call |
| 991 | data = ( |
| 992 | xmlheader, |
| 993 | "<methodCall>\n" |
| 994 | "<methodName>", methodname, "</methodName>\n", |
| 995 | data, |
| 996 | "</methodCall>\n" |
| 997 | ) |
| 998 | elif methodresponse: |
| 999 | # a method response, or a fault structure |
| 1000 | data = ( |
| 1001 | xmlheader, |
no test coverage detected