Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes
Archetypes.Marshall.RFC822Marshaller Class Reference
Inheritance diagram for Archetypes.Marshall.RFC822Marshaller:
Inheritance graph
[legend]
Collaboration diagram for Archetypes.Marshall.RFC822Marshaller:
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 207 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.RFC822Marshaller.demarshall (   self,
  instance,
  data,
  kwargs 
)

Reimplemented from Archetypes.Marshall.Marshaller.

Definition at line 213 of file Marshall.py.

00213 
00214     def demarshall(self, instance, data, **kwargs):
00215         # We don't want to pass file forward.
00216         if kwargs.has_key('file'):
00217             if not data:
00218                 # TODO Yuck! Shouldn't read the whole file, never.
00219                 # OTOH, if you care about large files, you should be
00220                 # using the PrimaryFieldMarshaller or something
00221                 # similar.
00222                 data = kwargs['file'].read()
00223             del kwargs['file']
00224         headers, body = parseRFC822(data)
00225         for k, v in headers.items():
00226             if v.strip() == 'None':
00227                 v = None
00228             field = instance.getField(k)
00229             if field is not None:
00230                 mutator = field.getMutator(instance)
00231                 if mutator is not None:
00232                     mutator(v)
00233         content_type = headers.get('Content-Type')
00234         if not kwargs.get('mimetype', None):
00235             kwargs.update({'mimetype': content_type})
00236         p = instance.getPrimaryField()
00237         if p is not None:
00238             mutator = p.getMutator(instance)
00239             if mutator is not None:
00240                 mutator(body, **kwargs)

Here is the call graph for this function:

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.RFC822Marshaller.marshall (   self,
  instance,
  kwargs 
)

Reimplemented from Archetypes.Marshall.Marshaller.

Definition at line 241 of file Marshall.py.

00241 
00242     def marshall(self, instance, **kwargs):
00243         p = instance.getPrimaryField()
00244         body = p and instance[p.getName()] or ''
00245         pname = p and p.getName() or None
00246         content_type = length = None
00247         # Gather/Guess content type
00248         if IBaseUnit.isImplementedBy(body):
00249             content_type = str(body.getContentType())
00250             body   = body.getRaw()
00251         else:
00252             if p and hasattr(p, 'getContentType'):
00253                 content_type = p.getContentType(instance) or 'text/plain'
00254             else:
00255                 content_type = body and guess_content_type(body) or 'text/plain'
00256 
00257         headers = []
00258         fields = [f for f in instance.Schema().fields()
00259                   if f.getName() != pname]
00260         for field in fields:
00261             if field.type in ('file', 'image', 'object'):
00262                 continue
00263             accessor = field.getEditAccessor(instance)
00264             if not accessor:
00265                 continue
00266             kw = {'raw':1, 'field': field.__name__}
00267             value = mapply(accessor, **kw)
00268             if type(value) in [ListType, TupleType]:
00269                 value = '\n'.join([str(v) for v in value])
00270             headers.append((field.getName(), str(value)))
00271 
00272         headers.append(('Content-Type', content_type or 'text/plain'))
00273 
00274         header = formatRFC822Headers(headers)
00275         data = '%s\n\n%s' % (header, body)
00276         length = len(data)
00277 
00278         return (content_type, length, data)
00279 
00280 InitializeClass(RFC822Marshaller)

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.RFC822Marshaller.security = ClassSecurityInfo() [static]

Reimplemented from Archetypes.Marshall.Marshaller.

Definition at line 209 of file Marshall.py.


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