/[opental]/opental/pax/paxtransform.py
ViewVC logotype

Diff of /opental/pax/paxtransform.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.28 by lalo, Mon Mar 24 21:06:11 2003 UTC revision 1.29 by lalo, Mon Apr 7 13:46:48 2003 UTC
# Line 27  class Engine(object): Line 27  class Engine(object):
27              handler = optional              handler = optional
28          self.handlers += ((ns, hash(ns), handler),)          self.handlers += ((ns, hash(ns), handler),)
29    
     def pop_error_handler(self, context):  
         if hasattr(context, 'error_handler'):  
             handler = context.error_handler  
             del context.error_handler  
             return handler  
   
30      def initialize(self, context):      def initialize(self, context):
31          context.tr_engine = self          context.tr_engine = self
32          context.postprocess_queue = []          context.postprocess_queue = []
# Line 54  class Engine(object): Line 48  class Engine(object):
48          processed = []          processed = []
49          context.postprocess_queue.append(processed)          context.postprocess_queue.append(processed)
50          try:          try:
51                error_handler = element.transform_error_handler
52                print
53            except AttributeError:
54                error_handler = None
55            try:
56              for ns, h, handler in self.handlers:              for ns, h, handler in self.handlers:
57                  if not hasattr(result, 'attributes'):                  if not hasattr(result, 'attributes'):
58                      break                      break
# Line 69  class Engine(object): Line 68  class Engine(object):
68                  # further mark it as "immutable"                  # further mark it as "immutable"
69                  result = tuple(result)                  result = tuple(result)
70          except:          except:
             error_handler = self.pop_error_handler(context)  
71              if error_handler:              if error_handler:
72                  result = error_handler()                  result = error_handler.catch(element, context)
73              else:              else:
74                  context.postprocess_queue.pop()                  context.postprocess_queue.pop()
75                  raise                  raise
76          else:          else:
77              if not hasattr(result, 'join'):              if not hasattr(result, 'join'):
                 error_handler = self.pop_error_handler(context)  
78                  try:                  try:
79                      for index, child in enumerate(result):                      for index, child in enumerate(result):
80                          result[index] = self.transform(child, context)                          result[index] = self.transform(child, context)
81                  except:                  except:
82                      if error_handler:                      if error_handler:
83                          result = error_handler()                          result = error_handler.catch(element, context)
84                      else:                      else:
85                          context.postprocess_queue.pop()                          context.postprocess_queue.pop()
86                          raise                          raise
# Line 94  class Engine(object): Line 91  class Engine(object):
91                  result = pack_list(result)                  result = pack_list(result)
92              except:              except:
93                  pass                  pass
         self.pop_error_handler(context)  
94          try:          try:
95              result = self.postprocess(result, context)              result = self.postprocess(result, context)
96          except StopTransform, data:          except StopTransform, data:
# Line 124  class RenderingEngine(Engine): Line 120  class RenderingEngine(Engine):
120          return Literal(XML(result, context.root_xmlns_map, context.encoding))          return Literal(XML(result, context.root_xmlns_map, context.encoding))
121    
122    
123    class TransformErrorHandler(object):
124        "Set a subclass of this on an element to capture transform errors"
125        def catch(self, element, context):
126            raise NotImplemented
127    
128    
129  class AttributeHandler(object):  class AttributeHandler(object):
130      "Handler that handles each attribute in turn"      "Handler that handles each attribute in turn"
131      def __init__(self, name=u'', ns=u''):      def __init__(self, name=u'', ns=u''):
# Line 175  class CompiledInformationHandler(object) Line 177  class CompiledInformationHandler(object)
177              result = self.preprocess(result, context)              result = self.preprocess(result, context)
178          for name, value in compiled:          for name, value in compiled:
179              __traceback_info__ = (name, value)              __traceback_info__ = (name, value)
180              result = self.handlers[name](result, context, value)              try:
181                    h = self.handlers[name]
182                except KeyError:
183                    # attribute was meaningful only on compilation
184                    continue
185                result = h(result, context, value)
186          return result          return result
187    
188  class AttributeCompiler(AttributeHandler):  class AttributeCompiler(AttributeHandler):
# Line 194  class AttributeCompiler(AttributeHandler Line 201  class AttributeCompiler(AttributeHandler
201                  value = element.attributes[self.ns][name]                  value = element.attributes[self.ns][name]
202              except KeyError:              except KeyError:
203                  continue                  continue
204              compiled.append((name, handler(element, context, value)))              cvalue = handler(element, context, value)
205                if isinstance(cvalue, TransformErrorHandler):
206                    element.transform_error_handler = cvalue
207                else:
208                    compiled.append((name, cvalue))
209          return element          return element
210    
211  try:  try:

Legend:
Removed from v.1.28  
changed lines
  Added in v.1.29

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26