Back to index

plone3  3.1.7
Public Member Functions | Public Attributes
Marshall.marshaller.ControlledMarshaller Class Reference
Inheritance diagram for Marshall.marshaller.ControlledMarshaller:
Inheritance graph
[legend]
Collaboration diagram for Marshall.marshaller.ControlledMarshaller:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def delegate
def marshall
def demarshall

Public Attributes

 fallback

Detailed Description

Definition at line 36 of file marshaller.py.


Constructor & Destructor Documentation

def Marshall.marshaller.ControlledMarshaller.__init__ (   self,
  fallback = None,
  demarshall_hook = None,
  marshall_hook = None 
)

Definition at line 39 of file marshaller.py.

00039 
00040                  marshall_hook=None):
00041         Marshaller.__init__(self, demarshall_hook, marshall_hook)
00042         self.fallback = fallback


Member Function Documentation

def Marshall.marshaller.ControlledMarshaller.delegate (   self,
  method,
  obj,
  data = None,
  file = None,
  kw 
)

Definition at line 43 of file marshaller.py.

00043 
00044     def delegate(self, method, obj, data=None, file=None, **kw):
00045         if file is not None:
00046             kw['file'] = file
00047         __traceback_info__ = (method, obj, kw)
00048         context = getContext(obj, kw.get('REQUEST'))
00049         if context is not obj:
00050             # If the object is being created by means of a PUT
00051             # then it has no context, and some of the stuff
00052             # we are doing here may require a context.
00053             # Wrapping it in an ImplicitAcquisitionWrapper should
00054             # be safe as long as nothing tries to persist
00055             # a reference to the wrapped object.
00056             obj = ImplicitAcquisitionWrapper(obj, context)
00057         tool = getToolByName(obj, TOOL_ID, None)
00058         components = None
00059         if tool is not None:
00060             info = kw.copy()
00061             info['data'] = data
00062             info['mode'] = method
00063             components = tool.getMarshallersFor(obj, **info)
00064         else:
00065             # Couldn't find a context to get
00066             # hold of the tool or the tool is not installed.
00067             log('Could not find the marshaller tool. '
00068                 'It might not be installed or you might not '
00069                 'be providing enough context to find it.')
00070         # We just use the first component, if one is returned.
00071         if components:
00072             marshaller = getComponent(components[0])
00073         else:
00074             # If no default marshaller was provided then we complain.
00075             if self.fallback is None:
00076                 raise MarshallingException(
00077                     "Couldn't get a marshaller for %r, %r" % (obj, kw))
00078             # Otherwise, use the default marshaller provided. Note it
00079             # must be an instance, not a factory.
00080             marshaller = self.fallback
00081         __traceback_info__ = (marshaller, method, obj, kw)
00082         args = (obj,)
00083         if method == 'demarshall':
00084             args += (data,)
00085         method = getattr(marshaller, method)
00086         return method(*args, **kw)

Here is the call graph for this function:

Here is the caller graph for this function:

def Marshall.marshaller.ControlledMarshaller.demarshall (   self,
  obj,
  data,
  kw 
)

Definition at line 92 of file marshaller.py.

00092 
00093     def demarshall(self, obj, data, **kw):
00094         if kw.has_key('file'):
00095             if not data:
00096                 # XXX Yuck! Shouldn't read the whole file, never.
00097                 # OTOH, if you care about large files, you should be
00098                 # using the PrimaryFieldMarshaller or something
00099                 # similar.
00100                 data = kw['file'].read()
00101             del kw['file']
00102 
00103         return self.delegate('demarshall', obj, data, **kw)

Here is the call graph for this function:

def Marshall.marshaller.ControlledMarshaller.marshall (   self,
  obj,
  kw 
)

Definition at line 87 of file marshaller.py.

00087 
00088     def marshall(self, obj, **kw):
00089         if not 'data' in kw:
00090             kw['data'] = ''
00091         return self.delegate('marshall', obj, **kw)

Here is the call graph for this function:


Member Data Documentation

Definition at line 41 of file marshaller.py.


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