MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / Marshaller

Class Marshaller

tools/python-3.11.9-amd64/Lib/xmlrpc/client.py:472–632  ·  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

Source from the content-addressed store, hash-verified

470# @see dumps
471
472class Marshaller:
473 """Generate an XML-RPC params chunk from a Python data structure.
474
475 Create a Marshaller instance for each set of parameters, and use
476 the "dumps" method to convert your data (represented as a tuple)
477 to an XML-RPC params chunk. To write a fault response, pass a
478 Fault instance instead. You may prefer to use the "dumps" module
479 function for this purpose.
480 """
481
482 # by the way, if you don't understand what's going on in here,
483 # that's perfectly ok.
484
485 def __init__(self, encoding=None, allow_none=False):
486 self.memo = {}
487 self.data = None
488 self.encoding = encoding
489 self.allow_none = allow_none
490
491 dispatch = {}
492
493 def dumps(self, values):
494 out = []
495 write = out.append
496 dump = self.__dump
497 if isinstance(values, Fault):
498 # fault instance
499 write("<fault>\n")
500 dump({'faultCode': values.faultCode,
501 'faultString': values.faultString},
502 write)
503 write("</fault>\n")
504 else:
505 # parameter block
506 # FIXME: the xml-rpc specification allows us to leave out
507 # the entire <params> block if there are no parameters.
508 # however, changing this may break older code (including
509 # old versions of xmlrpclib.py), so this is better left as
510 # is for now. See @XMLRPC3 for more information. /F
511 write("<params>\n")
512 for v in values:
513 write("<param>\n")
514 dump(v, write)
515 write("</param>\n")
516 write("</params>\n")
517 result = "".join(out)
518 return result
519
520 def __dump(self, value, write):
521 try:
522 f = self.dispatch[type(value)]
523 except KeyError:
524 # check if this object can be marshalled as a structure
525 if not hasattr(value, '__dict__'):
526 raise TypeError("cannot marshal %s objects" % type(value))
527 # check if this class is a sub-class of a basic type,
528 # because we don't know how to marshal these types
529 # (e.g. a string sub-class)

Callers 1

dumpsFunction · 0.85

Calls 1

typeClass · 0.50

Tested by

no test coverage detected