[Zope-CVS] CVS: Products/ExternalEditor - CHANGES.txt:1.58
ExternalEditor.py:1.25
Chris McDonough
chrism at plope.com
Tue Aug 31 14:06:35 EDT 2004
Update of /cvs-repository/Products/ExternalEditor
In directory cvs.zope.org:/tmp/cvs-serv853
Modified Files:
CHANGES.txt ExternalEditor.py
Log Message:
Provide compatibility with filestream iterators returned from content objects.
=== Products/ExternalEditor/CHANGES.txt 1.57 => 1.58 ===
--- Products/ExternalEditor/CHANGES.txt:1.57 Thu Aug 19 17:37:42 2004
+++ Products/ExternalEditor/CHANGES.txt Tue Aug 31 14:06:35 2004
@@ -1,7 +1,12 @@
External Editor Change Log
Next Release
-
+
+ - External Editor now compatible with objects that return a
+ "filestream iterator" in Zope 2.7.1+. (if upgrading: this fix
+ does not require an update to EE client, just the EE Zope
+ product).
+
- Properly escape hyphens in man page. Thanks to Federico Sevilla III.
- Check if the editor was launched before locking the file in Zope. This
=== Products/ExternalEditor/ExternalEditor.py 1.24 => 1.25 ===
--- Products/ExternalEditor/ExternalEditor.py:1.24 Wed Jul 7 16:08:36 2004
+++ Products/ExternalEditor/ExternalEditor.py Tue Aug 31 14:06:35 2004
@@ -17,6 +17,7 @@
# Zope External Editor Product by Casey Duncan
from string import join # For Zope 2.3 compatibility
+import types
import re
import urllib
import Acquisition
@@ -31,7 +32,12 @@
# webdav module not available
def wl_isLocked(ob):
return 0
-
+try:
+ from ZPublisher.Iterators import IStreamIterator
+except ImportError:
+ # pre-2.7.1 Zope without stream iterators
+ IStreamIterator = None
+
ExternalEditorPermission = 'Use external editor'
class ExternalEditor(Acquisition.Implicit):
@@ -107,6 +113,7 @@
break
r.append('')
+ streamiterator = None
# Using RESPONSE.setHeader('Pragma', 'no-cache') would be better, but
# this chokes crappy most MSIE versions when downloads happen on SSL.
@@ -130,21 +137,38 @@
return ''
if hasattr(ob, 'manage_FTPget'):
try:
- r.append(ob.manage_FTPget())
+ body = ob.manage_FTPget()
except TypeError: # some need the R/R pair!
- r.append(ob.manage_FTPget(REQUEST, RESPONSE))
+ body = ob.manage_FTPget(REQUEST, RESPONSE)
elif hasattr(ob, 'EditableBody'):
- r.append(ob.EditableBody())
+ body = ob.EditableBody()
elif hasattr(ob, 'document_src'):
- r.append(ob.document_src(REQUEST, RESPONSE))
+ body = ob.document_src(REQUEST, RESPONSE)
elif hasattr(ob, 'read'):
- r.append(ob.read())
+ body = ob.read()
else:
# can't read it!
raise 'BadRequest', 'Object does not support external editing'
- RESPONSE.setHeader('Content-Type', 'application/x-zope-edit')
- return join(r, '\n')
+ RESPONSE.setHeader('Content-Type', 'application/x-zope-edit')
+
+ if (IStreamIterator is not None and
+ IStreamIterator.isImplementedBy(body)):
+ # We need to manage our content-length because we're streaming.
+ # The content-length should have been set in the response by
+ # the method that returns the iterator, but we need to fix it up
+ # here because we insert metadata before the body.
+ clen = RESPONSE.headers.get('content-length', None)
+ assert clen is not None
+ metadata = join(r, '\n')
+ RESPONSE.setHeader('Content-Length', len(metadata) + int(clen) + 1)
+ RESPONSE.write(metadata)
+ RESPONSE.write('\n')
+ for data in body:
+ RESPONSE.write(data)
+ else:
+ r.append(body)
+ return join(r, '\n')
InitializeClass(ExternalEditor)
@@ -190,3 +214,4 @@
['%s=%s' % (name, val) for name, val in d.items()])
else:
return ''
+
More information about the Zope-CVS
mailing list