[CMF-checkins] CVS: Products/CMFDefault - utils.py:1.29
Tres Seaver
tseaver at palladion.com
Thu Jul 7 16:20:07 EDT 2005
Update of /cvs-repository/Products/CMFDefault
In directory cvs.zope.org:/tmp/cvs-serv5713/CMFDefault
Modified Files:
utils.py
Log Message:
- Forward-port use of real rfc922 parser from 1.5 branch.
=== Products/CMFDefault/utils.py 1.28 => 1.29 ===
--- Products/CMFDefault/utils.py:1.28 Thu Jul 7 16:08:13 2005
+++ Products/CMFDefault/utils.py Thu Jul 7 16:19:37 2005
@@ -17,6 +17,8 @@
import os
import re
+import StringIO
+import rfc822
from cgi import escape
from sgmllib import SGMLParser
@@ -91,39 +93,15 @@
Allow passing initial dictionary as headers.
"""
- # Split the lines apart, taking into account Mac|Unix|Windows endings
- lines = rc.split(body)
+ buffer = StringIO.StringIO(body)
+ message = rfc822.Message(buffer)
- i = 0
- if headers is None:
- headers = {}
- else:
- headers = headers.copy()
-
- hdrlist = []
-
- for line in lines:
-
- if not line:
- break
-
- tokens = line.split( ': ' )
-
- if len( tokens ) > 1:
- hdrlist.append( ( tokens[0], ': '.join( tokens[1:] ) ) )
- elif i == 0:
- return headers, body # no headers, just return those passed in.
- else: # continuation
- last, hdrlist = hdrlist[ -1 ], hdrlist[ :-1 ]
- hdrlist.append( ( last[ 0 ]
- , '\n'.join( ( last[1], line.lstrip() ) )
- ) )
- i = i + 1
+ headers = headers and headers.copy() or {}
- for hdr in hdrlist:
- headers[ hdr[0] ] = hdr[ 1 ]
+ for key in message.keys():
+ headers[key.capitalize()] = '\n'.join(message.getheaders(key))
- return headers, '\n'.join( lines[ i+1: ] )
+ return headers, buffer.read()
security.declarePublic('semi_split')
More information about the CMF-checkins
mailing list