MCPcopy Index your code
hub / github.com/python/cpython / Marshaller

Class Marshaller

Lib/xmlrpc/client.py:446–606  ·  view source on GitHub ↗

Generate an XML-RPC params chunk from a Python data structure. Create a Marshaller instance for each set of parameters, and use the "dumps" method to convert your data (represented as a tuple) to an XML-RPC params chunk. To write a fault response, pass a Fault instance instead. Yo

Source from the content-addressed store, hash-verified

444# @see dumps
445
446class Marshaller:
447 """Generate an XML-RPC params chunk from a Python data structure.
448
449 Create a Marshaller instance for each set of parameters, and use
450 the "dumps" method to convert your data (represented as a tuple)
451 to an XML-RPC params chunk. To write a fault response, pass a
452 Fault instance instead. You may prefer to use the "dumps" module
453 function for this purpose.
454 """
455
456 # by the way, if you don't understand what's going on in here,
457 # that's perfectly ok.
458
459 def __init__(self, encoding=None, allow_none=False):
460 self.memo = {}
461 self.data = None
462 self.encoding = encoding
463 self.allow_none = allow_none
464
465 dispatch = {}
466
467 def dumps(self, values):
468 out = []
469 write = out.append
470 dump = self.__dump
471 if isinstance(values, Fault):
472 # fault instance
473 write("<fault>\n")
474 dump({'faultCode': values.faultCode,
475 'faultString': values.faultString},
476 write)
477 write("</fault>\n")
478 else:
479 # parameter block
480 # FIXME: the xml-rpc specification allows us to leave out
481 # the entire <params> block if there are no parameters.
482 # however, changing this may break older code (including
483 # old versions of xmlrpclib.py), so this is better left as
484 # is for now. See @XMLRPC3 for more information. /F
485 write("<params>\n")
486 for v in values:
487 write("<param>\n")
488 dump(v, write)
489 write("</param>\n")
490 write("</params>\n")
491 result = "".join(out)
492 return result
493
494 def __dump(self, value, write):
495 try:
496 f = self.dispatch[type(value)]
497 except KeyError:
498 # check if this object can be marshalled as a structure
499 if not hasattr(value, '__dict__'):
500 raise TypeError("cannot marshal %s objects" % type(value))
501 # check if this class is a sub-class of a basic type,
502 # because we don't know how to marshal these types
503 # (e.g. a string sub-class)

Callers 1

dumpsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…