Back to index

plone3  3.1.7
Classes | Functions | Variables
Marshall.handlers.rfc822header Namespace Reference

Classes

class  NonLoweringMessage
class  RFC822Marshaller

Functions

def formatRFC822Headers
def parseRFC822

Variables

string sample_data = r""

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 94 of file rfc822header.py.

00094 
00095 def formatRFC822Headers( headers ):
00096 
00097     """ Convert the key-value pairs in 'headers' to valid RFC822-style
00098         headers, including adding leading whitespace to elements which
00099         contain newlines in order to preserve continuation-line semantics.
00100 
00101         code based on old cmf1.4 impl 
00102     """
00103     munged = []
00104     linesplit = re.compile( r'[\n\r]+?' )
00105 
00106     for key, value in headers:
00107 
00108         vallines = linesplit.split( value )
00109         munged.append( '%s: %s' % ( key, '\r\n  '.join( vallines ) ) )
00110 
00111     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 112 of file rfc822header.py.

00112 
00113 def parseRFC822(body):
00114     """Parse a RFC 822 (email) style string
00115     
00116     The code is mostly based on CMFDefault.utils.parseHeadersBody. It doesn't
00117     capitalize the headers as the CMF function.
00118     
00119     >>> headers, body = parseRFC822(sample_data)
00120     >>> keys = headers.keys(); keys.sort()
00121     >>> for key in keys:
00122     ...     key, headers[key]
00123     
00124     
00125     ('content-type', 'text/plain')
00126     ('keywords', 'foo')
00127     ('mixedCase', 'a MiXeD case keyword')
00128     ('title', 'a title')
00129     
00130     >>> print body
00131     This is the body.
00132     <BLANKLINE>
00133     """
00134     buffer = StringIO(body)
00135     message = NonLoweringMessage(buffer)
00136     headers = {}
00137 
00138     for key in message.keys():
00139         headers[key] = '\n'.join(message.getheaders(key))
00140 
00141     return headers, buffer.read() 

Here is the caller graph for this function:


Variable Documentation

Definition at line 57 of file rfc822header.py.