opental-checkins
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[OpenTAL-checkins] opental OpenTAL/tal_handler.py OpenPT/FSOPT.py ...


From: Fernando Lalo Martins
Subject: [OpenTAL-checkins] opental OpenTAL/tal_handler.py OpenPT/FSOPT.py ...
Date: Thu, 30 Jan 2003 11:32:28 -0500

CVSROOT:        /cvsroot/opental
Module name:    opental
Changes by:     Fernando Lalo Martins <address@hidden>  03/01/30 11:32:28

Modified files:
        OpenTAL        : tal_handler.py 
        OpenPT         : FSOPT.py OpenPTBase.py ZOPT.py __init__.py 
        OpenPT/www     : ptEdit.pt 
Added files:
        OpenPT/www     : fsptCustomize.pt 

Log message:
        OpenTAL can now read template configuration in the form
        <tal:config property="value" multiproperty="value1;value2" />
        OpenPT uses this to possibly set properties (like encoding, handlers,
        preferred output encodings) via source; useful for webdav/ftp editing.
        
        OpenPT also looks for a first line in the format
        <!--pt_encoding foo-->
        If found, this line is stripped and the rest of the text is
        interpreted using the encoding "foo".  I tested this with a chinese
        page encoded in utf16 and it is great.
        
        Some changes to FSOPT were necessary to make use of all the new
        encoding goodies.  In particular, now the customize zmi is a OpenPTFile.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/OpenTAL/tal_handler.py.diff?tr1=1.27&tr2=1.28&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/OpenPT/FSOPT.py.diff?tr1=1.11&tr2=1.12&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/OpenPT/OpenPTBase.py.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/OpenPT/ZOPT.py.diff?tr1=1.42&tr2=1.43&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/OpenPT/__init__.py.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/OpenPT/www/fsptCustomize.pt?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/OpenPT/www/ptEdit.pt.diff?tr1=1.2&tr2=1.3&r1=text&r2=text

Patches:
Index: opental/OpenPT/FSOPT.py
diff -u opental/OpenPT/FSOPT.py:1.11 opental/OpenPT/FSOPT.py:1.12
--- opental/OpenPT/FSOPT.py:1.11        Mon Jan 27 00:11:10 2003
+++ opental/OpenPT/FSOPT.py     Thu Jan 30 11:32:28 2003
@@ -15,11 +15,13 @@
 #    You should have received a copy of the GNU General Public License
 #    along with this program; if not, write to the Free Software
 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA
-__version__='$Revision: 1.11 $'[11:-2]
+__version__='$Revision: 1.12 $'[11:-2]
 
-from Products.CMFCore import FSPageTemplate as cmfFSPT
-from Products.CMFCore.FSPageTemplate import *
-from OpenPTBase import OpenPageTemplate, compiler_registry
+from Products.CMFCore.FSObject import FSObject
+from Products.CMFCore.DirectoryView import registerFileExtension, 
registerMetaType, expandpath
+from Products.CMFCore.CMFCorePermissions import View, ViewManagementScreens
+from OpenPTBase import OpenPageTemplate, compiler_registry, my_home
+from OpenPTFile import OpenPTFile
 from ZOPT import ZopePageTemplate # for zodb clones
 from Products.CMFCore import utils
 from OFS.SimpleItem import SimpleItem
@@ -27,7 +29,7 @@
 from ZODB.PersistentMapping import PersistentMapping
 from Acquisition import Explicit
 
-FSPT = FSPageTemplate
+#FSPT = FSPageTemplate
 
 class MacroCollection(PersistentMapping, Explicit):
     def __getitem__(self, name):
@@ -44,8 +46,6 @@
     _icon = 'misc_/OpenPT/fsopt.png'
     icon = _icon
     _compiled = None
-    # FIXME: get metadata from file, or .props
-    encoding = 'latin1'
 
     manage_options=(
         (
@@ -54,11 +54,11 @@
             )
         )
 
-    security = ClassSecurityInfo()
+    security = AccessControl.ClassSecurityInfo()
     security.declareObjectProtected(View)
 
     security.declareProtected(ViewManagementScreens, 'manage_main')
-    manage_main = FSPT.manage_main
+    manage_main = OpenPTFile('manage_main', my_home, 'www', 'fsptCustomize.pt')
 
     # Declare security for unprotected PageTemplate methods.
     security.declarePrivate('pt_edit', 'write', 'pt_editForm',
@@ -79,8 +79,11 @@
 
     def _createZODBClone(self):
         """Create a ZODB (editable) equivalent of this object."""
-        t = ZopePageTemplate(self.getId(), self.read())
+        self._updateFromFS()
+        t = ZopePageTemplate(self.getId(), None)
         t.handlers = self.handlers
+        t.encoding = self.encoding
+        t.write(self.uread())
         return t
 
     # unneeded, since this doesn't inherit from Cacheable, but won't hurt
@@ -124,6 +127,9 @@
         return OpenPageTemplate.paxtree(self)
 Globals.InitializeClass(FSPageTemplate)
 #cmfFSPT.FSPageTemplate = FSPageTemplate
+
+# nasty trick: import this so that it isn't imported again later
+from Products.CMFCore.FSPageTemplate import d
 
 registerFileExtension('pt', FSPageTemplate)
 registerFileExtension('html', FSPageTemplate)
Index: opental/OpenPT/OpenPTBase.py
diff -u opental/OpenPT/OpenPTBase.py:1.4 opental/OpenPT/OpenPTBase.py:1.5
--- opental/OpenPT/OpenPTBase.py:1.4    Wed Jan 29 17:40:24 2003
+++ opental/OpenPT/OpenPTBase.py        Thu Jan 30 11:32:28 2003
@@ -15,7 +15,7 @@
 #    You should have received a copy of the GNU General Public License
 #    along with this program; if not, write to the Free Software
 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA
-__version__='$Revision: 1.4 $'[11:-2]
+__version__='$Revision: 1.5 $'[11:-2]
 
 # ugh, this import list needs to be cleaned up
 import OpenTAL, pax, PTmetal_handler, pax.paxtransform
@@ -50,6 +50,8 @@
 from encodings.aliases import aliases as encoding_aliases
 from DocumentTemplate.DT_Util import TemplateDict, InstanceDict
 from AccessControl.DTML import RestrictedDTML
+my_home = package_home(globals())
+
 class Rtd(RestrictedDTML, TemplateDict):
     this = None
 
@@ -158,7 +160,6 @@
             self.preferred = ('utf_8', 'utf_16')
         else:
             self.preferred = self.purify(preferred)
-        self.log('Initializing with %s' % self.preferred)
         self.acceptable = sets.Set(self.preferred)
         self.clients = []
 
@@ -178,16 +179,11 @@
         if client_id not in self.clients:
             self.clients.append(client_id)
             encodings = self.purify(encodings)
-            self.log('restricting with %s due to %s' % (encodings, client))
             self.acceptable.intersection_update(sets.Set(encodings))
-            self.log('now: %s' % self.acceptable)
-        else:
-            self.log('client %s already cached' % client)
 
     security.declarePublic('force')
     def force(self, encoding):
         "force one encoding.  If it's called multiple times, bad luck, last 
one wins."
-        self.log('forcing %s' % encoding)
         self.forced = encoding
 
     def encode(self, text):
@@ -316,6 +312,10 @@
             return OpenPageTemplate.inheritedAttribute('_getContext')(self)
         return self
 
+    def _prop_config(self, dict):
+        "update properties from dict"
+        self.__dict__.update(dict)
+
     security = AccessControl.ClassSecurityInfo()
 
     security.declareObjectProtected('View')
@@ -327,6 +327,11 @@
             self._v_paxtree = pickle.loads(self._paxtree)
         return self._v_paxtree
 
+    security.declareProtected('View management screens', 'uread')
+    def uread(self, *args, **kw):
+        return unicode(self.read(), self.encoding)
+
+    security.declareProtected('View management screens', 'read')
     def read(self, *args, **kw):
         if not self._errors:
             return self._text
@@ -335,13 +340,19 @@
                                       join(self._errors, '\n '),
                                       self._text))
 
-    def write(self, text):
+    def write(self, text, do_config=True):
         self.ZCacheable_invalidate()
         assert type(text) in (type(''), type(u''))
+
+        if do_config and text.startswith('<!--pt_encoding'):
+            comment, text = text.split('-->\n', 1)
+            self.encoding = comment[16:].strip()
+
         if text.startswith(self._error_start):
             errend = text.find('-->')
             if errend >= 0:
                 text = text[errend + 4:]
+
         if self._text != text:
             self._text = text
 
@@ -367,6 +378,13 @@
             for handler in postcompiler_registry:
                 tree = handler(self, tree, context)
             self._paxtree = pickle.dumps(tree)
+            # check for tal:config in the context
+            if do_config and hasattr(context, 'tal_configuration'):
+                self._prop_config(context.tal_configuration)
+                # sigh, encoding or source type may have changed
+                if (context.tal_configuration.has_key('encoding') or
+                    context.tal_configuration.has_key('source_type')):
+                    self.write(text, do_config=False)
             if hasattr(self, '_v_paxtree'):
                 # remove cached (unpickled) tree
                 del self._v_paxtree
Index: opental/OpenPT/ZOPT.py
diff -u opental/OpenPT/ZOPT.py:1.42 opental/OpenPT/ZOPT.py:1.43
--- opental/OpenPT/ZOPT.py:1.42 Wed Jan 29 17:40:24 2003
+++ opental/OpenPT/ZOPT.py      Thu Jan 30 11:32:28 2003
@@ -15,7 +15,7 @@
 #    You should have received a copy of the GNU General Public License
 #    along with this program; if not, write to the Free Software
 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA
-__version__='$Revision: 1.42 $'[11:-2]
+__version__='$Revision: 1.43 $'[11:-2]
 
 # FIXME: determine what exactly has to be imported.
 # some imports probably aren't needed by Base anymore.
@@ -23,7 +23,6 @@
 from OpenPTFile import OpenPTFile
 import os
 
-my_home = package_home(globals())
 default_text_dir = os.path.join(my_home, 'default_text')
 
 class ZopePageTemplate(OpenPageTemplate, PropertyManager):
Index: opental/OpenPT/__init__.py
diff -u opental/OpenPT/__init__.py:1.6 opental/OpenPT/__init__.py:1.7
--- opental/OpenPT/__init__.py:1.6      Mon Jan 27 00:11:10 2003
+++ opental/OpenPT/__init__.py  Thu Jan 30 11:32:28 2003
@@ -15,7 +15,7 @@
 #    You should have received a copy of the GNU General Public License
 #    along with this program; if not, write to the Free Software
 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA
-__version__='$Revision: 1.6 $'[11:-2]
+__version__='$Revision: 1.7 $'[11:-2]
 
 from ZOPT import ZopePageTemplate, default_text_dir, \
      manage_addPageTemplateForm, manage_addPageTemplate
@@ -46,4 +46,5 @@
         import FSOPT
         FSOPT.initialize(context)
     except ImportError:
+        # CMF not installed (or so we hope)
         pass
Index: opental/OpenPT/www/ptEdit.pt
diff -u opental/OpenPT/www/ptEdit.pt:1.2 opental/OpenPT/www/ptEdit.pt:1.3
--- opental/OpenPT/www/ptEdit.pt:1.2    Wed Jan 29 17:40:24 2003
+++ opental/OpenPT/www/ptEdit.pt        Thu Jan 30 11:32:28 2003
@@ -6,7 +6,7 @@
 
 <tal:block define="global body request/other/text | request/form/text
 | here/read" /> 
-<form action="" method="post" tal:attributes="action request/URL1">
+<form action="" method="post" tal:attributes="action request/URL1; 
accept-charset here/encoding">
 <input type="hidden" name=":default_method" value="pt_changePrefs">
 <table width="100%" cellspacing="0" cellpadding="2" border="0">
   <tr>
Index: opental/OpenTAL/tal_handler.py
diff -u opental/OpenTAL/tal_handler.py:1.27 opental/OpenTAL/tal_handler.py:1.28
--- opental/OpenTAL/tal_handler.py:1.27 Mon Jan 27 14:50:36 2003
+++ opental/OpenTAL/tal_handler.py      Thu Jan 30 11:32:27 2003
@@ -170,6 +170,7 @@
     for item in split_multiple(value):
         scope, expr = split_spec(item, 'local', 'global')
 
+
         name, expr = expr.split(None, 1)
         data.append((scope=='global', name, context.compile(expr)))
     return data
@@ -204,8 +205,22 @@
 #def compile_tal_start(element, context):
 #    return element
 
-#def compile_tal_finish(element, context):
-#    return element
+def compile_tal_finish(element, context):
+    # handle configuration <tal:config prop="value" />
+    if getattr(element, 'ns', None) == tal_ns and element.name == 'config':
+        if not hasattr(context, 'tal_configuration'):
+            context.tal_configuration = {}
+        conf = context.tal_configuration
+        for property, value in element.attributes[tal_ns].items():
+            value = [sub.strip().replace(';;', ';') for sub in 
multiple_re.split(value)]
+            if len(value) == 1:
+                value = value[0]
+            elif len(value) > 1 and not value[-1].strip():
+                del value[-1] # It ended in a semicolon
+            conf[property] = value
+        # remove it from the compiled tree
+        return None
+    return element
 
 
 tal_compiler = AttributeCompiler('tal', tal_ns)
@@ -218,7 +233,7 @@
 tal_compiler.add_handler('attributes', compile_attributes)
 tal_compiler.add_handler('omit-tag', compile_omit_tag)
 #tal_compiler.preprocess = compile_tal_start
-#tal_compiler.postprocess = compile_tal_finish
+tal_compiler.postprocess = compile_tal_finish
 
 
 __all__ = ('tal_handler', 'tal_compiler')




reply via email to

[Prev in Thread] Current Thread [Next in Thread]