Back to index

plone3  3.1.7
Public Member Functions
Marshall.handlers.simple.SimpleXMLMarshaller Class Reference
Inheritance diagram for Marshall.handlers.simple.SimpleXMLMarshaller:
Inheritance graph
[legend]
Collaboration diagram for Marshall.handlers.simple.SimpleXMLMarshaller:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def demarshall
def marshall

Detailed Description

Definition at line 39 of file simple.py.


Member Function Documentation

def Marshall.handlers.simple.SimpleXMLMarshaller.demarshall (   self,
  instance,
  data,
  kwargs 
)

Definition at line 41 of file simple.py.

00041 
00042     def demarshall(self, instance, data, **kwargs):
00043         doc = libxml2.parseDoc(data)
00044         p = instance.getPrimaryField()
00045         pname = p and p.getName() or None
00046         try:
00047             fields = [f for f in instance.Schema().fields()
00048                       if f.getName() != pname]
00049             for f in fields:
00050                 items = doc.xpathEval('/*/%s' % f.getName())
00051                 if not len(items): continue
00052                 # Note that we ignore all but the first element if
00053                 # we get more than one
00054                 value = items[0].children
00055                 if not value:
00056                     continue
00057                 mutator = f.getMutator(instance)
00058                 if mutator is not None:
00059                     mutator(value.content.strip())
00060         finally:
00061             doc.freeDoc()

def Marshall.handlers.simple.SimpleXMLMarshaller.marshall (   self,
  instance,
  kwargs 
)

Definition at line 62 of file simple.py.

00062 
00063     def marshall(self, instance, **kwargs):
00064         response = minidom.Document()
00065         doc = response.createElement(instance.portal_type.lower())
00066         response.appendChild(doc)
00067 
00068         p = instance.getPrimaryField()
00069         pname = p and p.getName() or None
00070         fields = [f for f in instance.Schema().fields()
00071                   if f.getName() != pname]
00072 
00073         for f in fields:
00074             value = instance[f.getName()]
00075             values = [value]
00076             if type(value) in [ListType, TupleType]:
00077                 values = [str(v) for v in value]
00078             elm = response.createElement(f.getName())
00079             for value in values:
00080                 value = response.createTextNode(str(value))
00081                 elm.appendChild(value)
00082             doc.appendChild(elm)
00083 
00084         content_type = 'text/xml'
00085         data = response.toprettyxml().encode('utf-8')
00086         length = len(data)
00087 
00088         return (content_type, length, data)

Here is the call graph for this function:


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