[CMF-checkins] CVS: Products/CMFDefault - utils.py:1.26.2.3

Tres Seaver tseaver at palladion.com
Thu Jul 7 16:19:38 EDT 2005


Update of /cvs-repository/Products/CMFDefault
In directory cvs.zope.org:/tmp/cvs-serv5358/CMFDefault

Modified Files:
      Tag: CMF-1_5-branch
	utils.py 
Log Message:


 - CMFDefault.utils.parseHeadersBody:  use standard library's 'rfc822'
   module to parse metadata headers, to take advantage of better handling
   of edge cases.


=== Products/CMFDefault/utils.py 1.26.2.2 => 1.26.2.3 ===
--- Products/CMFDefault/utils.py:1.26.2.2	Thu Jul  7 16:04:32 2005
+++ Products/CMFDefault/utils.py	Thu Jul  7 16:19:08 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