[Checkins] SVN: Products.ExternalEditor/trunk/ - Add a simple
callback registry that can be used to add extra
Sidnei da Silva
sidnei at enfoldsystems.com
Mon Jul 10 09:03:24 EDT 2006
Log message for revision 69071:
- Add a simple callback registry that can be used to add extra
metadata headers or set special response headers when a file is
edited through External Editor.
- Use rfc822.Message for parsing the metadata of the file being
edited.
Changed:
U Products.ExternalEditor/trunk/CHANGES.txt
U Products.ExternalEditor/trunk/ExternalEditor.py
U Products.ExternalEditor/trunk/zopeedit.py
-=-
Modified: Products.ExternalEditor/trunk/CHANGES.txt
===================================================================
--- Products.ExternalEditor/trunk/CHANGES.txt 2006-07-10 12:59:10 UTC (rev 69070)
+++ Products.ExternalEditor/trunk/CHANGES.txt 2006-07-10 13:03:23 UTC (rev 69071)
@@ -2,6 +2,13 @@
mm/dd/yyyy
+ - Add a simple callback registry that can be used to add extra
+ metadata headers or set special response headers when a file is
+ edited through External Editor.
+
+ - Use rfc822.Message for parsing the metadata of the file being
+ edited.
+
- Don't emit a warning about deprecated 'methods' in Zope >= 2.10.
6/23/2005 - 0.9.1 Release
@@ -12,7 +19,7 @@
6/20/2005 - 0.9 Release
- When using the Excel plugin, errors were seen by users like
- "TypeError: This object does not support enumeration". We no
+ "TypeError: This object does not support enumeration". We now
make the user deal with these.
- When using the Excel plugin, errors were intermittently raised to the
Modified: Products.ExternalEditor/trunk/ExternalEditor.py
===================================================================
--- Products.ExternalEditor/trunk/ExternalEditor.py 2006-07-10 12:59:10 UTC (rev 69070)
+++ Products.ExternalEditor/trunk/ExternalEditor.py 2006-07-10 13:03:23 UTC (rev 69071)
@@ -40,6 +40,26 @@
ExternalEditorPermission = 'Use external editor'
+_callbacks = []
+
+def registerCallback(cb):
+ """Register a callback to be called by the External Editor when
+ it's about to be finished with collecting metadata for the
+ to-be-edited file to allow actions to be taken, like for example
+ inserting more metadata headers or enabling response compression
+ or anything.
+ """
+ _callbacks.append(cb)
+
+def applyCallbacks(ob, metadata, request, response):
+ """Apply the registered callbacks in the order they were
+ registered. The callbacks are free to perform any operation,
+ including appending new metadata attributes and setting response
+ headers.
+ """
+ for cb in _callbacks:
+ cb(ob, metadata, request, response)
+
class ExternalEditor(Acquisition.Implicit):
"""Create a response that encapsulates the data needed by the
ZopeEdit helper application
@@ -120,6 +140,9 @@
r.append('borrow_lock:1')
break
+ # Apply any extra callbacks that might have been registered.
+ applyCallbacks(ob, r, REQUEST, RESPONSE)
+
r.append('')
streamiterator = None
Modified: Products.ExternalEditor/trunk/zopeedit.py
===================================================================
--- Products.ExternalEditor/trunk/zopeedit.py 2006-07-10 12:59:10 UTC (rev 69070)
+++ Products.ExternalEditor/trunk/zopeedit.py 2006-07-10 13:03:23 UTC (rev 69071)
@@ -28,6 +28,7 @@
warnings.filterwarnings('ignore')
import os, re
+import rfc822
import traceback
from tempfile import mktemp
from ConfigParser import ConfigParser
@@ -109,17 +110,10 @@
self.config = Configuration(config_path)
# Open the input file and read the metadata headers
- in_f = open(input_file, 'rb')
- metadata = {}
+ in_f = open(input_file, 'rU')
+ m = rfc822.Message(in_f)
- while 1:
- line = in_f.readline()[:-1]
- if not line: break
- sep = line.find(':')
- key = line[:sep]
- val = line[sep+1:]
- metadata[key] = val
- self.metadata = metadata
+ self.metadata = metadata = m.dict.copy()
# parse the incoming url
scheme, self.host, self.path = urlparse(metadata['url'])[:3]
More information about the Checkins
mailing list