[CMF-checkins] CVS: CMF/CMFDefault - Document.py:1.39.2.3 Link.py:1.13.2.3 utils.py:1.8.4.1
Tres Seaver
tseaver@zope.com
Tue, 8 Jan 2002 13:25:57 -0500
Update of /cvs-repository/CMF/CMFDefault
In directory cvs.zope.org:/tmp/cvs-serv5291/CMFDefault
Modified Files:
Tag: CMF-1_2-branch
Document.py Link.py utils.py
Log Message:
- Merge fix for Tracker #407 from branch.
=== CMF/CMFDefault/Document.py 1.39.2.2 => 1.39.2.3 ===
from DublinCore import DefaultDublinCoreImpl
-from utils import parseHeadersBody, SimpleHTMLParser, bodyfinder, _dtmldir
+from utils import parseHeadersBody, formatRFC822Headers
+from utils import SimpleHTMLParser, bodyfinder, _dtmldir
factory_type_information = ( { 'id' : 'Document'
, 'meta_type' : 'Document'
@@ -403,9 +404,8 @@
'body': self.EditableBody(),
}
else:
- hdrtext = join(map(lambda x: '%s: %s' % (
- x[0], x[1]), hdrlist), '\n')
- bodytext = '%s\n\n%s' % ( hdrtext, self.text )
+ hdrtext = formatRFC822Headers( hdrlist )
+ bodytext = '%s\r\n\r\n%s' % ( hdrtext, self.text )
return bodytext
=== CMF/CMFDefault/Link.py 1.13.2.2 => 1.13.2.3 ===
from DublinCore import DefaultDublinCoreImpl
-from utils import parseHeadersBody, _dtmldir
+from utils import formatRFC822Headers, parseHeadersBody, _dtmldir
factory_type_information = ( { 'id' : 'Link'
, 'meta_type' : 'Link'
@@ -88,6 +88,7 @@
)
meta_type = 'Link'
+ URL_FORMAT = format = 'text/url'
effective_date = expiration_date = None
_isDiscussable = 1
@@ -160,7 +161,7 @@
lines = string.split( body, '\n' )
self.edit( lines[0] )
- headers['Format'] = 'text/url'
+ headers['Format'] = self.URL_FORMAT
new_subject = keywordsplitter(headers)
headers['Subject'] = new_subject or self.Subject()
haveheader = headers.has_key
@@ -199,8 +200,7 @@
join = string.join
lower = string.lower
hdrlist = self.getMetadataHeaders()
- hdrtext = join( map( lambda x: '%s: %s' % ( x[0], x[1] )
- , hdrlist), '\n' )
+ hdrtext = formatRFC822Headers( hdrlist )
bodytext = '%s\n\n%s' % ( hdrtext, self.getRemoteUrl() )
return bodytext
=== CMF/CMFDefault/utils.py 1.8 => 1.8.4.1 ===
_dtmldir = os.path.join( package_home( globals() ), 'dtml' )
+def formatRFC822Headers( headers ):
+ """
+ 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.
+ """
+ munged = []
+ linesplit = re.compile( r'[\n\r]+?' )
+
+ for key, value in headers:
+
+ vallines = linesplit.split( value )
+ munged.append( '%s: %s' % ( key, join( vallines, '\r\n ' ) ) )
+
+ return join( munged, '\r\n' )
+
+
def parseHeadersBody( body, headers=None ):
"""
Parse any leading 'RFC-822'-ish headers from an uploaded