[CMF-checkins] CVS: CMF/CMFCollector - WebTextDocument.py:1.7
Ken Manheimer
klm@zope.com
Mon, 24 Dec 2001 12:20:29 -0500
Update of /cvs-repository/CMF/CMFCollector
In directory cvs.zope.org:/tmp/cvs-serv3653
Modified Files:
WebTextDocument.py
Log Message:
Adapt to new CMFDefault.Document architecture. This will work with
latest CMF checkins, and i believe with what will be released in 1.2.
(I'm leaving handleText() in, in case it may be sufficient for
backwards compatablility, but i'm not confident it is.)
.edit(): Removed. Document now uses ._edit() for hooking in special
text cooking processes.
._edit(): Added, to override the Document default cooking procedure.
(It would be nice if Document exposed a .cookText() or something like
that, so i could just override that, and benefit form the rest of
._edit().)
.cookText(): Does the actual cooking, and there if Document ever does
things this way.
.handleText(): Obsolete, may be useful for backwards compatability,
but i'm not confident it's sufficient.
=== CMF/CMFCollector/WebTextDocument.py 1.6 => 1.7 ===
return Document.guessFormat(self, text)
- def edit(self, text_format, text, file='', safety_belt=''):
- got = Document.edit(self, text_format or self.text_format,
- text=text, file=file, safety_belt=safety_belt)
- # The document stubbornly insists on a text format it likes, despite
- # our explicit specification - set it back:
- self.text_format = text_format or self.TEXT_FORMAT
+ def _edit(self, text, text_format='', safety_belt=''):
+ """ Edit the Document - Parses headers and cooks the body"""
+ headers = {}
+ if not text_format:
+ text_format = self.text_format
+ if not safety_belt:
+ safety_belt = headers.get('SafetyBelt', '')
+ if not self._safety_belt_update(safety_belt=safety_belt):
+ msg = ("Intervening changes from elsewhere detected."
+ " Please refetch the document and reapply your changes."
+ " (You may be able to recover your version using the"
+ " browser 'back' button, but will have to apply them"
+ " to a freshly fetched copy.)")
+ raise 'EditingConflict', msg
+ self.cooked_text = self.cookText(text)
+ self.text = text
+ def cookText(self, text):
+ return util.format_webtext(text)
+
+ # XXX This is obsolete for CMF 1.2 Document. It may be sufficient for
+ # compatability with pre-CMF-1.2 Document architecture, but that's
+ # untested.
security.declarePrivate('handleText')
def handleText(self, text, format=None, stx_level=None):
"""Handle the raw text, returning headers, body, cooked, format"""
- if not format:
- format = self.guessFormat(text)
- if format != self.TEXT_FORMAT:
- return Document.handleText(self, text, format=format,
- stx_level=stx_level or self._stx_level)
- else:
- body = text
- cooked = util.format_webtext(body)
- headers = {}
- return headers, body, cooked, format
+ body = text
+ cooked = self.cookText(text)
+ headers = {}
+ return headers, body, cooked, self.TEXT_FORMAT
InitializeClass(WebTextDocument)