[Checkins] SVN: Products.ExternalEditor/trunk/Products/ExternalEditor/ExternalEditor.py make stream iterators work with both pre and post 2.12 IStreamIterator

Laurence Rowe l at lrowe.co.uk
Tue May 20 12:55:20 EDT 2008


Log message for revision 86856:
  make stream iterators work with both pre and post 2.12 IStreamIterator

Changed:
  U   Products.ExternalEditor/trunk/Products/ExternalEditor/ExternalEditor.py

-=-
Modified: Products.ExternalEditor/trunk/Products/ExternalEditor/ExternalEditor.py
===================================================================
--- Products.ExternalEditor/trunk/Products/ExternalEditor/ExternalEditor.py	2008-05-20 16:38:05 UTC (rev 86855)
+++ Products.ExternalEditor/trunk/Products/ExternalEditor/ExternalEditor.py	2008-05-20 16:55:20 UTC (rev 86856)
@@ -32,20 +32,21 @@
     # 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
 
+from ZPublisher.Iterators import IStreamIterator
+from zope.interface import implements, Interface
+HAVE_Z3_IFACE = issubclass(IStreamIterator, Interface)
+
 ExternalEditorPermission = 'Use external editor'
 
 _callbacks = []
 
 class PDataStreamIterator:
+    if HAVE_Z3_IFACE:
+        implements(IStreamIterator)
+    else:
+        __implements__ = IStreamIterator
 
-    __implements__ = (IStreamIterator,)
-
     def __init__(self, data):
         self.data = data
 
@@ -213,8 +214,8 @@
             # can't read it!
             raise 'BadRequest', 'Object does not support external editing'
 
-        if (IStreamIterator is not None and
-            IStreamIterator.implementedBy(body)):
+        if (HAVE_Z3_IFACE and IStreamIterator.providedBy(body) or
+            not HAVE_Z3_IFACE 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



More information about the Checkins mailing list