Back to index

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

List of all members.

Public Member Functions

def demarshall
def marshall
def initializeInstance
def cleanupInstance
def initializeField
def cleanupField

Public Attributes

 demarshall_hook
 marshall_hook

Static Public Attributes

tuple security = ClassSecurityInfo()

Detailed Description

Definition at line 144 of file Marshall.py.


Member Function Documentation

def Archetypes.Marshall.Marshaller.cleanupField (   self,
  instance,
  field 
) [inherited]

Definition at line 139 of file Marshall.py.

00139 
00140     def cleanupField(self, instance, field):
00141         pass
00142 
00143 InitializeClass(Marshaller)

def Archetypes.Marshall.Marshaller.cleanupInstance (   self,
  instance,
  item = None,
  container = None 
) [inherited]

Definition at line 124 of file Marshall.py.

00124 
00125     def cleanupInstance(self, instance, item=None, container=None):
00126         if hasattr(aq_base(instance), 'demarshall_hook'):
00127             delattr(instance, 'demarshall_hook')
00128         if hasattr(aq_base(instance), 'marshall_hook'):
00129             delattr(instance, 'marshall_hook')

def Archetypes.Marshall.PrimaryFieldMarshaller.demarshall (   self,
  instance,
  data,
  kwargs 
)

Reimplemented from Archetypes.Marshall.Marshaller.

Definition at line 150 of file Marshall.py.

00150 
00151     def demarshall(self, instance, data, **kwargs):
00152         p = instance.getPrimaryField()
00153         file = kwargs.get('file')
00154         # TODO Hardcoding field types is bad. :(
00155         if isinstance(p, (FileField, TextField)) and file:
00156             data = file
00157             del kwargs['file']
00158         mutator = p.getMutator(instance)
00159         mutator(data, **kwargs)

def Archetypes.Marshall.Marshaller.initializeField (   self,
  instance,
  field 
) [inherited]

Definition at line 136 of file Marshall.py.

00136 
00137     def initializeField(self, instance, field):
00138         pass

def Archetypes.Marshall.Marshaller.initializeInstance (   self,
  instance,
  item = None,
  container = None 
) [inherited]

Definition at line 114 of file Marshall.py.

00114 
00115     def initializeInstance(self, instance, item=None, container=None):
00116         dm_hook = None
00117         m_hook = None
00118         if self.demarshall_hook is not None:
00119             dm_hook = getattr(instance, self.demarshall_hook, None)
00120         if self.marshall_hook is not None:
00121             m_hook = getattr(instance, self.marshall_hook, None)
00122         instance.demarshall_hook = dm_hook
00123         instance.marshall_hook = m_hook

def Archetypes.Marshall.PrimaryFieldMarshaller.marshall (   self,
  instance,
  kwargs 
)

Reimplemented from Archetypes.Marshall.Marshaller.

Definition at line 160 of file Marshall.py.

00160 
00161     def marshall(self, instance, **kwargs):
00162         p = instance.getPrimaryField()
00163         if not p:
00164             raise TypeError, 'Primary Field could not be found.'
00165         data = p and instance[p.getName()] or ''
00166         content_type = length = None
00167         # Gather/Guess content type
00168         if IBaseUnit.isImplementedBy(data):
00169             content_type = data.getContentType()
00170             length = data.get_size()
00171             data   = data.getRaw()
00172         elif isinstance(data, File):
00173             content_type = data.content_type
00174             length = data.get_size()
00175             data = data.data
00176         else:
00177             log('WARNING: PrimaryFieldMarshaller(%r): '
00178                 'field %r does not return a IBaseUnit '
00179                 'instance.' % (instance, p.getName()))
00180             if hasattr(p, 'getContentType'):
00181                 content_type = p.getContentType(instance) or 'text/plain'
00182             else:
00183                 content_type = (data and guess_content_type(data)
00184                                 or 'text/plain')
00185 
00186             # DM 2004-12-01: "FileField"s represent a major field class
00187             #  that does not use "IBaseUnit" yet.
00188             #  Ensure, the used "File" objects get the correct length.
00189             if hasattr(p, 'get_size'):
00190                 length = p.get_size(instance)
00191             else:
00192                 # DM: this almost surely is stupid!
00193                 length = len(data)
00194 
00195             # ObjectField without IBaseUnit?
00196             if shasattr(data, 'data'):
00197                 data = data.data
00198             else:
00199                 data = str(data)
00200                 # DM 2004-12-01: recompute 'length' as we now know it
00201                 # definitely
00202                 length = len(data)
00203 
00204         return (content_type, length, data)
00205 
00206 InitializeClass(PrimaryFieldMarshaller)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 111 of file Marshall.py.

Definition at line 112 of file Marshall.py.

tuple Archetypes.Marshall.PrimaryFieldMarshaller.security = ClassSecurityInfo() [static]

Reimplemented from Archetypes.Marshall.Marshaller.

Definition at line 146 of file Marshall.py.


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