Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes
Marshall.handlers.rfc822header.RFC822Marshaller Class Reference
Inheritance diagram for Marshall.handlers.rfc822header.RFC822Marshaller:
Inheritance graph
[legend]
Collaboration diagram for Marshall.handlers.rfc822header.RFC822Marshaller:
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 142 of file rfc822header.py.


Member Function Documentation

def Marshall.handlers.rfc822header.RFC822Marshaller.demarshall (   self,
  instance,
  data,
  kwargs 
)

Definition at line 148 of file rfc822header.py.

00148 
00149     def demarshall(self, instance, data, **kwargs):
00150         # We don't want to pass file forward.
00151         if kwargs.has_key('file'):
00152             if not data:
00153                 # XXX Yuck! Shouldn't read the whole file, never.
00154                 # OTOH, if you care about large files, you should be
00155                 # using the PrimaryFieldMarshaller or something
00156                 # similar.
00157                 data = kwargs['file'].read()
00158             del kwargs['file']
00159         headers, body = parseRFC822(data)
00160         for k, v in headers.items():
00161             if v.strip() == 'None':
00162                 v = None
00163             field = instance.getField(k)
00164             if field is not None:
00165                 mutator = field.getMutator(instance)
00166                 if mutator is not None:
00167                     mutator(v)
00168         content_type = headers.get('Content-Type')
00169         if not kwargs.get('mimetype', None):
00170             kwargs.update({'mimetype': content_type})
00171         p = instance.getPrimaryField()
00172         if p is not None:
00173             mutator = p.getMutator(instance)
00174             if mutator is not None:
00175                 mutator(body, **kwargs)

Here is the call graph for this function:

def Marshall.handlers.rfc822header.RFC822Marshaller.marshall (   self,
  instance,
  kwargs 
)

Definition at line 176 of file rfc822header.py.

00176 
00177     def marshall(self, instance, **kwargs):
00178         p = instance.getPrimaryField()
00179         body = p and instance[p.getName()] or ''
00180         pname = p and p.getName() or None
00181         content_type = length = None
00182         # Gather/Guess content type
00183         if IBaseUnit.isImplementedBy(body):
00184             content_type = str(body.getContentType())
00185             body   = body.getRaw()
00186         else:
00187             if p and hasattr(p, 'getContentType'):
00188                 content_type = p.getContentType(instance) or 'text/plain'
00189             else:
00190                 content_type = body and guess_content_type(body) or 'text/plain'
00191 
00192         headers = []
00193         fields = [f for f in instance.Schema().fields()
00194                   if f.getName() != pname]
00195         for field in fields:
00196             if field.type in ('file', 'image', 'object'):
00197                 continue
00198             accessor = field.getEditAccessor(instance)
00199             if not accessor:
00200                 continue
00201             kw = {'raw':1, 'field': field.__name__}
00202             value = mapply(accessor, **kw)
00203             if type(value) in [ListType, TupleType]:
00204                 value = '\n'.join([str(v) for v in value])
00205             headers.append((field.getName(), str(value)))
00206 
00207         headers.append(('Content-Type', content_type or 'text/plain'))
00208 
00209         header = formatRFC822Headers(headers)
00210         data = '%s\n\n%s' % (header, body)
00211         length = len(data)
00212 
00213         return (content_type, length, data)
00214 
00215 InitializeClass(RFC822Marshaller)

Here is the call graph for this function:


Member Data Documentation

tuple Marshall.handlers.rfc822header.RFC822Marshaller.security = ClassSecurityInfo() [static]

Definition at line 144 of file rfc822header.py.


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