opental-checkins
[Top][All Lists]
Advanced

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

[OpenTAL-checkins] opental OpenPT/OpenPTBase.py OpenTAL/Context.py...


From: Fernando Lalo Martins
Subject: [OpenTAL-checkins] opental OpenPT/OpenPTBase.py OpenTAL/Context.py...
Date: Thu, 20 Feb 2003 05:37:42 -0500

CVSROOT:        /cvsroot/opental
Module name:    opental
Changes by:     Fernando Lalo Martins <address@hidden>  03/02/20 05:37:41

Modified files:
        OpenPT         : OpenPTBase.py 
        OpenTAL        : Context.py metal_handler.py 
Added files:
        OpenPT         : Zpax.py 

Log message:
        PAX trees can now be persistent; getting rid of all the pickle/unpickle 
crap

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/OpenPT/Zpax.py?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/OpenPT/OpenPTBase.py.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/OpenTAL/Context.py.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/OpenTAL/metal_handler.py.diff?tr1=1.16&tr2=1.17&r1=text&r2=text

Patches:
Index: opental/OpenPT/OpenPTBase.py
diff -u opental/OpenPT/OpenPTBase.py:1.7 opental/OpenPT/OpenPTBase.py:1.8
--- opental/OpenPT/OpenPTBase.py:1.7    Mon Feb  3 11:16:31 2003
+++ opental/OpenPT/OpenPTBase.py        Thu Feb 20 05:37:40 2003
@@ -15,15 +15,15 @@
 #    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.7 $'[11:-2]
+__version__='$Revision: 1.8 $'[11:-2]
 
 # ugh, this import list needs to be cleaned up
-import OpenTAL, pax, PTmetal_handler, pax.paxtransform
+import OpenTAL, pax, PTmetal_handler, pax.paxtransform, Zpax
 from pax.backwards_compatibility import *
 from ZPythonExpr import PythonExpr, SecureModuleImporter
 import cPickle as pickle
 #import pickle
-import AccessControl, Acquisition, sys
+import AccessControl, Acquisition, sys, types
 from Acquisition import aq_base
 from Globals import DTMLFile, ImageFile, MessageDialog, package_home
 from zLOG import LOG, PROBLEM, ERROR, INFO
@@ -104,7 +104,7 @@
     col = template.macros
     col.clear()
     for name, macro in macros.items():
-        col[name] = pickle.dumps(macro)
+        col[name] = macro
     return tree
 
 
@@ -260,7 +260,7 @@
     _warnings = ()
     _text = '<opental />'
     _error_start = '<!-- Page Template Diagnostics'
-    _paxtree = pickle.dumps(pax.text2pax(_text))
+    _paxtree = pax.text2pax(_text)
     meta_type = 'Page Template (OpenPT)'
     _icon = 'misc_/OpenPT/opt.png'
     # overridding this allows a subclass to run unrestricted, for example
@@ -323,9 +323,9 @@
 
     def paxtree(self):
         'fetch the pax tree from the zodb'
-        if not hasattr(self, '_v_paxtree'):
-            self._v_paxtree = pickle.loads(self._paxtree)
-        return self._v_paxtree
+        if type(self._paxtree) in (types.StringType, types.UnicodeType):
+            self._paxtree = pickle.loads(self._paxtree)
+        return self._paxtree
 
     security.declareProtected('View management screens', 'uread')
     def uread(self, *args, **kw):
@@ -342,7 +342,7 @@
 
     def write(self, text, do_config=True):
         self.ZCacheable_invalidate()
-        assert type(text) in (type(''), type(u''))
+        assert type(text) in (types.StringType, types.UnicodeType)
 
         if do_config and text.startswith('<!--pt_encoding'):
             comment, text = text.split('-->\n', 1)
@@ -361,7 +361,7 @@
 
         self._errors = ()
         try:
-            tree = parser(text, PT_initial_namespaces(), self.encoding)
+            tree = parser(text, PT_initial_namespaces(), self.encoding, 
module=Zpax)
             tr_engine = pax.paxtransform.Engine()
             for handler in compiler_registry:
                 tr_engine.add_handler(handler)
@@ -377,7 +377,7 @@
             tree = tr_engine.transform(tree, context)
             for handler in postcompiler_registry:
                 tree = handler(self, tree, context)
-            self._paxtree = pickle.dumps(tree)
+            self._paxtree = tree
             # check for tal:config in the context
             if do_config and hasattr(context, 'tal_configuration'):
                 self._prop_config(context.tal_configuration)
@@ -385,9 +385,6 @@
                 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
         except:
             import traceback, zLOG
             #zLOG.LOG('OpenPT', 0, 'Compilation error',
Index: opental/OpenTAL/Context.py
diff -u opental/OpenTAL/Context.py:1.3 opental/OpenTAL/Context.py:1.4
--- opental/OpenTAL/Context.py:1.3      Tue Feb  4 21:47:51 2003
+++ opental/OpenTAL/Context.py  Thu Feb 20 05:37:41 2003
@@ -18,7 +18,7 @@
 """TALES Context
 """
 
-__version__='$Revision: 1.3 $'[11:-2]
+__version__='$Revision: 1.4 $'[11:-2]
 
 import re, sys
 import cPickle as pickle
@@ -203,20 +203,7 @@
     def evaluateMacro(self, expr):
         # XXX Should return None or a macro definition
         macro = self.evaluate(expr)
-        if type(macro) is type(u''):
-            try:
-                macro = str(macro)
-            except UnicodeError:
-                print 'bad macro', repr(macro.encode('latin1')[:50])
-                raise TypeError, 'invalid pickle data in macro'
-        try:
-            return pickle.loads(macro)
-        except TypeError:
-            if hasattr(macro, '__class__'):
-                t = macro.__class__
-            else:
-                t = type(macro)
-            raise MetalError, 'macro %s is a %s, should be a (pickle) string' 
% (expr, t.__name__)
+    evaluateMacro = evaluate
 
     def getDefault(self):
         return Default
Index: opental/OpenTAL/metal_handler.py
diff -u opental/OpenTAL/metal_handler.py:1.16 
opental/OpenTAL/metal_handler.py:1.17
--- opental/OpenTAL/metal_handler.py:1.16       Thu Jan 16 17:52:46 2003
+++ opental/OpenTAL/metal_handler.py    Thu Feb 20 05:37:41 2003
@@ -22,7 +22,7 @@
 from pax.backwards_compatibility import *
 from pax.paxtransform import AttributeHandler
 from xml.sax.saxutils import escape as html_quote
-from pax import XML, Element
+from pax import XML
 import pax
 try:
     from tal_handler import tal_ns
@@ -94,9 +94,11 @@
 def handle_use_macro(element, context, value):
     value = getattr(element, 'metal_macro', value)
     macro = context.evaluateMacro(value)
-    if not isinstance(macro, Element):
-        raise MetalError, ('trying to use a PageTemplate macro in an 
AltPageTemplate: ' +
-                           value)
+    try:
+        [a for a in macro.children]
+    except:
+        raise MetalError, ('trying to use an incompatible object as a macro: ' 
+
+                           repr(value))
     if hasattr(context, 'getDefault') and macro is context.getDefault():
         return element
     context.metal_slot_stack[-1] = fish_slots(element)




reply via email to

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