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


From: Fernando Lalo Martins
Subject: [OpenTAL-checkins] opental/OpenTAL tal_handler.py
Date: Wed, 26 Feb 2003 15:01:23 -0500

CVSROOT:        /cvsroot/opental
Module name:    opental
Changes by:     Fernando Lalo Martins <address@hidden>  03/02/26 15:01:23

Modified files:
        OpenTAL        : tal_handler.py 

Log message:
        support tal:on-error

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/OpenTAL/tal_handler.py.diff?tr1=1.28&tr2=1.29&r1=text&r2=text

Patches:
Index: opental/OpenTAL/tal_handler.py
diff -u opental/OpenTAL/tal_handler.py:1.28 opental/OpenTAL/tal_handler.py:1.29
--- opental/OpenTAL/tal_handler.py:1.28 Thu Jan 30 11:32:27 2003
+++ opental/OpenTAL/tal_handler.py      Wed Feb 26 15:01:22 2003
@@ -23,7 +23,22 @@
      AttributeCompiler, StopTransform
 from pax import XML, Literal
 from pax.backwards_compatibility import *
-import re
+import re, sys
+
+class ErrorObject(object):
+    __allow_access_to_unprotected_subobjects__ = 1
+    def __init__(self):
+        self.type, self.value, self.tb = sys.exc_info()
+
+class ErrorHandler(object):
+    def __init__(self, element, context, value):
+        self.element = element
+        self.context = context
+        self.value = value
+
+    def __call__(self):
+        self.context.setLocal('error', ErrorObject())
+        return handle_content(self.element, self.context, self.value)
 
 def normalize(text):
     return ' '.join(text.split())
@@ -122,6 +137,10 @@
         return element
     return element.children
 
+def handle_on_error(element, context, value):
+    context.error_handler = ErrorHandler(element, context, value)
+    return element
+
 def tal_start(element, context):
     context.beginScope()
     context.setLocal('attrs', element.attributes.get(element.ns, {}))
@@ -148,7 +167,7 @@
 
 
 tal_handler = CompiledInformationHandler('tal', tal_ns)
-#tal_handler.add_handler('on_error', handle_on_error)
+tal_handler.add_handler('on-error', handle_on_error)
 tal_handler.add_handler('define', handle_define)
 tal_handler.add_handler('condition', handle_condition)
 tal_handler.add_handler('repeat', handle_repeat)
@@ -182,7 +201,7 @@
     name, value = value.split(None, 1)
     return name, context.compile(value)
 
-def compile_replace_or_content(element, context, value):
+def compile_simple_expr(element, context, value):
     mode, value = text_or_structure(value)
     return mode == 'structure', context.compile(value)
 
@@ -224,19 +243,19 @@
 
 
 tal_compiler = AttributeCompiler('tal', tal_ns)
-#tal_compiler.add_handler('on_error', compile_on_error)
+tal_compiler.add_handler('on-error', compile_simple_expr)
 tal_compiler.add_handler('define', compile_define)
 tal_compiler.add_handler('condition', compile_condition)
 tal_compiler.add_handler('repeat', compile_repeat)
-tal_compiler.add_handler('content', compile_replace_or_content)
-tal_compiler.add_handler('replace', compile_replace_or_content)
+tal_compiler.add_handler('content', compile_simple_expr)
+tal_compiler.add_handler('replace', compile_simple_expr)
 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
 
 
-__all__ = ('tal_handler', 'tal_compiler')
+__all__ = ('tal_ns', 'tal_handler', 'tal_compiler')
 
 if __name__ == '__main__':
     import sys, pax, pax.paxtransform




reply via email to

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