Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
xmlrpc.client.Marshaller Class Reference

XML-RPC marshaller. More...

List of all members.

Public Member Functions

def __init__
def dumps
def dump_nil
def dump_int
def dump_bool
def dump_long
def dump_double
def dump_string
def dump_unicode
def dump_array
def dump_struct
def dump_datetime
def dump_instance

Public Attributes

 memo
 data
 encoding
 allow_none
 write

Static Public Attributes

dictionary dispatch = {}

Private Member Functions

def __dump

Detailed Description

XML-RPC marshaller.

Parameters:
encodingDefault encoding for 8-bit strings. The default value is None (interpreted as UTF-8).
See also:
dumps
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.  You may prefer to use the "dumps" module
function for this purpose.

Definition at line 464 of file client.py.


Constructor & Destructor Documentation

def xmlrpc.client.Marshaller.__init__ (   self,
  encoding = None,
  allow_none = False 
)

Definition at line 477 of file client.py.

00477 
00478     def __init__(self, encoding=None, allow_none=False):
00479         self.memo = {}
00480         self.data = None
00481         self.encoding = encoding
00482         self.allow_none = allow_none

Here is the caller graph for this function:


Member Function Documentation

def xmlrpc.client.Marshaller.__dump (   self,
  value,
  write 
) [private]

Definition at line 512 of file client.py.

00512 
00513     def __dump(self, value, write):
00514         try:
00515             f = self.dispatch[type(value)]
00516         except KeyError:
00517             # check if this object can be marshalled as a structure
00518             try:
00519                 value.__dict__
00520             except:
00521                 raise TypeError("cannot marshal %s objects" % type(value))
00522             # check if this class is a sub-class of a basic type,
00523             # because we don't know how to marshal these types
00524             # (e.g. a string sub-class)
00525             for type_ in type(value).__mro__:
00526                 if type_ in self.dispatch.keys():
00527                     raise TypeError("cannot marshal %s objects" % type(value))
00528             # XXX(twouters): using "_arbitrary_instance" as key as a quick-fix
00529             # for the p3yk merge, this should probably be fixed more neatly.
00530             f = self.dispatch["_arbitrary_instance"]
00531         f(self, value, write)

Here is the caller graph for this function:

def xmlrpc.client.Marshaller.dump_array (   self,
  value,
  write 
)

Definition at line 579 of file client.py.

00579 
00580     def dump_array(self, value, write):
00581         i = id(value)
00582         if i in self.memo:
00583             raise TypeError("cannot marshal recursive sequences")
00584         self.memo[i] = None
00585         dump = self.__dump
00586         write("<value><array><data>\n")
00587         for v in value:
00588             dump(v, write)
00589         write("</data></array></value>\n")
        del self.memo[i]

Here is the call graph for this function:

def xmlrpc.client.Marshaller.dump_bool (   self,
  value,
  write 
)

Definition at line 547 of file client.py.

00547 
00548     def dump_bool(self, value, write):
00549         write("<value><boolean>")
00550         write(value and "1" or "0")
        write("</boolean></value>\n")
def xmlrpc.client.Marshaller.dump_datetime (   self,
  value,
  write 
)

Definition at line 612 of file client.py.

00612 
00613         def dump_datetime(self, value, write):
00614             write("<value><dateTime.iso8601>")
00615             write(_strftime(value))
            write("</dateTime.iso8601></value>\n")

Here is the call graph for this function:

def xmlrpc.client.Marshaller.dump_double (   self,
  value,
  write 
)

Definition at line 561 of file client.py.

00561 
00562     def dump_double(self, value, write):
00563         write("<value><double>")
00564         write(repr(value))
        write("</double></value>\n")
def xmlrpc.client.Marshaller.dump_instance (   self,
  value,
  write 
)

Definition at line 618 of file client.py.

00618 
00619     def dump_instance(self, value, write):
00620         # check for special wrappers
00621         if value.__class__ in WRAPPERS:
00622             self.write = write
00623             value.encode(self)
00624             del self.write
00625         else:
00626             # store instance attributes as a struct (really?)
            self.dump_struct(value.__dict__, write)
def xmlrpc.client.Marshaller.dump_int (   self,
  value,
  write 
)

Definition at line 538 of file client.py.

00538 
00539     def dump_int(self, value, write):
00540         # in case ints are > 32 bits
00541         if value > MAXINT or value < MININT:
00542             raise OverflowError("int exceeds XML-RPC limits")
00543         write("<value><int>")
00544         write(str(value))
        write("</int></value>\n")
def xmlrpc.client.Marshaller.dump_long (   self,
  value,
  write 
)

Definition at line 553 of file client.py.

00553 
00554     def dump_long(self, value, write):
00555         if value > MAXINT or value < MININT:
00556             raise OverflowError("long int exceeds XML-RPC limits")
00557         write("<value><int>")
00558         write(str(int(value)))
        write("</int></value>\n")
def xmlrpc.client.Marshaller.dump_nil (   self,
  value,
  write 
)

Definition at line 532 of file client.py.

00532 
00533     def dump_nil (self, value, write):
00534         if not self.allow_none:
00535             raise TypeError("cannot marshal None unless allow_none is enabled")
        write("<value><nil/></value>")
def xmlrpc.client.Marshaller.dump_string (   self,
  value,
  write,
  escape = escape 
)

Definition at line 567 of file client.py.

00567 
00568     def dump_string(self, value, write, escape=escape):
00569         write("<value><string>")
00570         write(escape(value))
        write("</string></value>\n")

Here is the call graph for this function:

def xmlrpc.client.Marshaller.dump_struct (   self,
  value,
  write,
  escape = escape 
)

Definition at line 593 of file client.py.

00593 
00594     def dump_struct(self, value, write, escape=escape):
00595         i = id(value)
00596         if i in self.memo:
00597             raise TypeError("cannot marshal recursive dictionaries")
00598         self.memo[i] = None
00599         dump = self.__dump
00600         write("<value><struct>\n")
00601         for k, v in value.items():
00602             write("<member>\n")
00603             if not isinstance(k, str):
00604                 raise TypeError("dictionary key must be string")
00605             write("<name>%s</name>\n" % escape(k))
00606             dump(v, write)
00607             write("</member>\n")
00608         write("</struct></value>\n")
        del self.memo[i]

Here is the call graph for this function:

def xmlrpc.client.Marshaller.dump_unicode (   self,
  value,
  write,
  escape = escape 
)

Definition at line 573 of file client.py.

00573 
00574     def dump_unicode(self, value, write, escape=escape):
00575         write("<value><string>")
00576         write(escape(value))
        write("</string></value>\n")

Here is the call graph for this function:

def xmlrpc.client.Marshaller.dumps (   self,
  values 
)

Definition at line 485 of file client.py.

00485 
00486     def dumps(self, values):
00487         out = []
00488         write = out.append
00489         dump = self.__dump
00490         if isinstance(values, Fault):
00491             # fault instance
00492             write("<fault>\n")
00493             dump({'faultCode': values.faultCode,
00494                   'faultString': values.faultString},
00495                  write)
00496             write("</fault>\n")
00497         else:
00498             # parameter block
00499             # FIXME: the xml-rpc specification allows us to leave out
00500             # the entire <params> block if there are no parameters.
00501             # however, changing this may break older code (including
00502             # old versions of xmlrpclib.py), so this is better left as
00503             # is for now.  See @XMLRPC3 for more information. /F
00504             write("<params>\n")
00505             for v in values:
00506                 write("<param>\n")
00507                 dump(v, write)
00508                 write("</param>\n")
00509             write("</params>\n")
00510         result = "".join(out)
00511         return result

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 481 of file client.py.

Definition at line 479 of file client.py.

Definition at line 483 of file client.py.

Definition at line 480 of file client.py.

Definition at line 478 of file client.py.

Definition at line 621 of file client.py.


The documentation for this class was generated from the following file: