[GeneralDiscussion] applied to unstable: preserve unicode when evaluating DTML (#1411)

[email protected] (unstable-repo)
Newsgroups gmane.comp.web.zope.zwiki
Message-ID <20080502155553.6A0BB465DD2__33246.1839112968$1209743881$gmane$org@mail.joyful.com>
Fri May  2 08:54:38 PDT 2008  Simon Michael <[email protected]>
  * preserve unicode when evaluating DTML (#1411)
diff -rN -u old-ZWiki-unstable/Admin.py new-ZWiki-unstable/Admin.py
--- old-ZWiki-unstable/Admin.py	2008-05-02 08:55:50.000000000 -0700
+++ new-ZWiki-unstable/Admin.py	2008-05-02 08:55:51.000000000 -0700
@@ -489,10 +489,10 @@
 
     def fixEncoding(self, enc=None, REQUEST=None):
         """Try to fix character encoding problems in this page's name,
-        text, or parents property.  From 0.60, we store text as unicode,
+        text, or parents property.  We now store text as unicode,
         so this just tries to convert any non-unicode text to unicode
         using the standard encoding - currently utf-8, which will work for
-        most zwikis.  Some wikis have other encodings, so we also check
+        most zwikis.  Some (ancient) zwikis might have other encodings, so we also check
         for the common iso8859-1 encoding, or another specified with the
         enc argument. (Ideally this would fix anything without such a
         hint.)  Returns True if changes were made.
diff -rN -u old-ZWiki-unstable/Utils.py new-ZWiki-unstable/Utils.py
--- old-ZWiki-unstable/Utils.py	2008-05-02 08:55:50.000000000 -0700
+++ new-ZWiki-unstable/Utils.py	2008-05-02 08:55:51.000000000 -0700
@@ -550,7 +550,7 @@
 
     def talsafe(self,s):
         """
-        Sanitize a string for use with TAL's structure keyword.
+        Make a string safe for use with TAL's structure keyword.
 
         Zope versions before 2.10 expect such data to be an ordinary
         string.  Zope 2.10 expects it to be unicode, or to at least be
@@ -585,6 +585,8 @@
         """
         return tounicode(s,enc or self.encoding())
 
+InitializeClass(PageUtils)
+
 def toencoded(s,enc='utf8'):
     """Safely convert a unicode string to an encoded ordinary string.
     UTF8 is used by default."""
@@ -598,8 +600,6 @@
     else:            return s.decode(enc)
 
 
-InitializeClass(PageUtils)
-
 
 # generic utilities
 
diff -rN -u old-ZWiki-unstable/ZWikiPage.py new-ZWiki-unstable/ZWikiPage.py
--- old-ZWiki-unstable/ZWikiPage.py	2008-05-02 08:55:50.000000000 -0700
+++ new-ZWiki-unstable/ZWikiPage.py	2008-05-02 08:55:51.000000000 -0700
@@ -283,8 +283,9 @@
         Pre-parse this page's text (the pre-rendered, if available) for DTML.
         """
         t = self.preRendered() or self.read()
-        # dtml can break with a unicode string here, depending on default
-        # encoding ?  Convert to a normal string. Hmm, lossage here ? XXX
+        # dtml can break with a unicode string here (eg
+        # test_dtml_in_rst); we'll encode it and decode again in
+        # evaluatePreRenderedAsDtml
         t = self.toencoded(t)
         cooklock.acquire()
         try:
@@ -298,12 +299,15 @@
         # optimization: to save memory, avoid unnecessarily calling DTML
         # and generating _v_blocks data
         if not self.hasDynamicContent(): return self.preRendered()
-        return DTMLDocument.__call__(
+        t = DTMLDocument.__call__(
             self.__of__(self.folder()), # ensure dtml in pages can acquire
             client,
             REQUEST,
             RESPONSE,
             **kw)
+        # cook encoded it for safe passage through the DTML monster
+        t = self.tounicode(t)
+        return t
     
     def renderMidsectionIn(self, text, **kw):
         """

--
forwarded from http://zwiki.org/GeneralDiscussion#[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.