Back to index

plone3  3.1.7
Classes | Functions | Variables
Archetypes.Marshall Namespace Reference

Classes

class  NonLoweringMessage
class  Marshaller
class  PrimaryFieldMarshaller
class  RFC822Marshaller

Functions

def formatRFC822Headers
def parseRFC822

Variables

string sample_data = r""
tuple __all__ = ('PrimaryFieldMarshaller', 'RFC822Marshaller', )

Function Documentation

Convert the key-value pairs in 'headers' to valid RFC822-style
    headers, including adding leading whitespace to elements which
    contain newlines in order to preserve continuation-line semantics.

    code based on old cmf1.4 impl 

Definition at line 57 of file Marshall.py.

00057 
00058 def formatRFC822Headers( headers ):
00059 
00060     """ Convert the key-value pairs in 'headers' to valid RFC822-style
00061         headers, including adding leading whitespace to elements which
00062         contain newlines in order to preserve continuation-line semantics.
00063 
00064         code based on old cmf1.4 impl 
00065     """
00066     munged = []
00067     linesplit = re.compile( r'[\n\r]+?' )
00068 
00069     for key, value in headers:
00070 
00071         vallines = linesplit.split( value )
00072         munged.append( '%s: %s' % ( key, '\r\n  '.join( vallines ) ) )
00073 
00074     return '\r\n'.join( munged )

Here is the caller graph for this function:

Parse a RFC 822 (email) style string

The code is mostly based on CMFDefault.utils.parseHeadersBody. It doesn't
capitalize the headers as the CMF function.

>>> headers, body = parseRFC822(sample_data)
>>> keys = headers.keys(); keys.sort()
>>> for key in keys:
...     key, headers[key]
('content-type', 'text/plain')
('keywords', 'foo')
('mixedCase', 'a MiXeD case keyword')
('title', 'a title')

>>> print body
This is the body.
<BLANKLINE>

Definition at line 75 of file Marshall.py.

00075 
00076 def parseRFC822(body):
00077     """Parse a RFC 822 (email) style string
00078     
00079     The code is mostly based on CMFDefault.utils.parseHeadersBody. It doesn't
00080     capitalize the headers as the CMF function.
00081     
00082     >>> headers, body = parseRFC822(sample_data)
00083     >>> keys = headers.keys(); keys.sort()
00084     >>> for key in keys:
00085     ...     key, headers[key]
00086     ('content-type', 'text/plain')
00087     ('keywords', 'foo')
00088     ('mixedCase', 'a MiXeD case keyword')
00089     ('title', 'a title')
00090     
00091     >>> print body
00092     This is the body.
00093     <BLANKLINE>
00094     """
00095     buffer = StringIO(body)
00096     message = NonLoweringMessage(buffer)
00097     headers = {}
00098 
00099     for key in message.keys():
00100         headers[key] = '\n'.join(message.getheaders(key))
00101 
00102     return headers, buffer.read()

Here is the caller graph for this function:


Variable Documentation

Definition at line 281 of file Marshall.py.

Definition at line 20 of file Marshall.py.