Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes
Marshall.handlers.primaryfield.PrimaryFieldMarshaller Class Reference
Inheritance diagram for Marshall.handlers.primaryfield.PrimaryFieldMarshaller:
Inheritance graph
[legend]
Collaboration diagram for Marshall.handlers.primaryfield.PrimaryFieldMarshaller:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def demarshall
def marshall

Static Public Attributes

tuple security = ClassSecurityInfo()

Detailed Description

Definition at line 59 of file primaryfield.py.


Member Function Documentation

def Marshall.handlers.primaryfield.PrimaryFieldMarshaller.demarshall (   self,
  instance,
  data,
  file = None,
  kwargs 
)

Definition at line 65 of file primaryfield.py.

00065 
00066     def demarshall(self, instance, data, file=None, **kwargs):
00067         p = instance.getPrimaryField()
00068         # XXX Hardcoding field types is bad. :(
00069         if isinstance(p, (FileField, TextField)) and file:
00070             data = file
00071         mutator = p.getMutator(instance)
00072         mutator(data, **kwargs)

def Marshall.handlers.primaryfield.PrimaryFieldMarshaller.marshall (   self,
  instance,
  kwargs 
)

Definition at line 73 of file primaryfield.py.

00073 
00074     def marshall(self, instance, **kwargs):
00075         p = instance.getPrimaryField()
00076         if not p:
00077             raise TypeError, 'Primary Field could not be found.'
00078         data = p and instance[p.getName()] or ''
00079         content_type = length = None
00080         # Gather/Guess content type
00081         if IBaseUnit.isImplementedBy(data):
00082             content_type = data.getContentType()
00083             length = data.get_size()
00084             data   = data.getRaw()
00085         elif isinstance(data, File):
00086             content_type = data.content_type
00087             length = data.get_size()
00088             data = data.data
00089         else:
00090             log('WARNING: PrimaryFieldMarshaller(%r): '
00091                 'field %r does not return a IBaseUnit '
00092                 'instance.' % (instance, p.getName()))
00093             if hasattr(p, 'getContentType'):
00094                 content_type = p.getContentType(instance) or 'text/plain'
00095             else:
00096                 content_type = (data and guess_content_type(data)
00097                                 or 'text/plain')
00098 
00099             # DM 2004-12-01: "FileField"s represent a major field class
00100             #  that does not use "IBaseUnit" yet.
00101             #  Ensure, the used "File" objects get the correct length.
00102             if hasattr(p, 'get_size'):
00103                 length = p.get_size(instance)
00104             else:
00105                 # DM: this almost surely is stupid!
00106                 length = len(data)
00107 
00108             # ObjectField without IBaseUnit?
00109             if shasattr(data, 'data'):
00110                 data = data.data
00111             else:
00112                 data = str(data)
00113                 # DM 2004-12-01: recompute 'length' as we now know it
00114                 # definitely
00115                 length = len(data)
00116 
00117         return (content_type, length, data)
00118 
00119 InitializeClass(PrimaryFieldMarshaller)

Here is the call graph for this function:


Member Data Documentation

Definition at line 61 of file primaryfield.py.


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