Changeset 644

Show
Ignore:
Timestamp:
07/22/03 17:28:08 (5 years ago)
Author:
sholloway
Message:

Made skin:trylist only catch element factory and import errors

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/RBFoundation/RBFoundation/XMLBuilder.py

    r612 r644  
    4444#~ Classes 
    4545#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     46 
     47class ElementFactoryError(Exception):  
     48    pass 
    4649 
    4750class XMLBuilderObjectBase(object): 
     
    8891        this particular data.  The template method makes no restrictions, except that the instance factory 
    8992        must be able to accept the same arguments as this method.""" 
    90         raise KeyError, 'No Class Registered: %s %s' % node 
     93        raise ElementFactoryError('No Class Registered for %r' % (node,)) 
    9194 
    9295    def _SaveStackState(self, bFull=0): 
  • trunk/RBFoundation/RBFoundation/XMLClassBuilder.py

    r619 r644  
    3232#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    3333 
     34ElementFactoryError = XMLBuilder.ElementFactoryError 
     35 
    3436class ElementFactory(object): 
    3537    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    4648 
    4749    class Raise(object): 
    48         def __init__(self, exception=KeyError, message=''): 
     50        def __init__(self, exception=ElementFactoryError, message=''): 
    4951            self.exception = exception 
    5052            self.message = message 
     
    8991                PyPath = self.PyPathRoot 
    9092            module = __import__(PyPath, globals(), {}, Name) 
     93 
    9194            try: 
    9295                return getattr(module, Name) 
     
    9497                if self.retryimport: 
    9598                    module = reload(module) 
    96                     return getattr(module, Name) 
    97                 raise 
     99                    try: return getattr(module, Name) 
     100                    except AttributeError: pass 
     101                raise ElementFactoryError, 'Could not find "%s" in module %r' % (Name, module) 
    98102 
    99103        def __call__(self, owner, parent, node, attributes, namespacemap): 
     
    109113                self._CachedElementFactories[node] = result 
    110114            return result 
     115 
    111116    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    112117 
     
    157162 
    158163    class TryList(object): 
    159         def __init__(self, trylist, ignoreExceptions=[ImportError, AttributeError, KeyError]): 
     164        def __init__(self, trylist, ignoreExceptions=[ElementFactoryError, ImportError]):#, AttributeError, KeyError]): 
    160165            self._trylist = trylist 
    161166            self._ignoreExceptions = tuple(ignoreExceptions) 
    162167 
    163         def __call__(self, *args, **kw): 
     168        def __call__(self, owner, parent, node, attributes, namespacemap): 
    164169            for each in self._trylist: 
    165170                try: 
    166                     return each(*args, **kw
     171                    return each(owner, parent, node, attributes, namespacemap
    167172                except self._ignoreExceptions: 
    168173                    pass 
     174 
     175            raise ElementFactoryError('No suitable element factory for node %r' % (node,)) 
    169176 
    170177    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    184191                    self._CachedElementFactories[node] = result 
    185192                    return result 
    186                 except self._ignoreExceptions
     193                except self._ignoreExceptions, e
    187194                    pass 
     195 
     196            raise ElementFactoryError('No suitable element factory for node %r' % (node,)) 
    188197 
    189198#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    244253                return self.NextFactorySet._GetElementFactory(*args, **kw) 
    245254 
    246         raise KeyError, "Could not find a class to build for node %r" % (node,
     255        raise ElementFactoryError("Could not find a class to build for node %r" % (node,)
    247256 
    248257#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  • trunk/RBSkinning/RBSkinning/SkinObject.py

    r606 r644  
    234234        variables['self'] = weakref.proxy(self) 
    235235        variables['ctx'] = variables['context'] = weakref.proxy(self.context) 
    236         if self.parent(): 
    237             variables['parentObj'] = self.parent().object 
     236        parent = self.parent() 
     237        if parent: 
     238            variables['parent'] = parent 
     239            variables['parentObj'] = parent.object 
    238240        return variables 
    239241 
  • trunk/RBSkinning/RBSkinning/skin/trylist.py

    r545 r644  
    2424#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    2525 
     26from RBFoundation.XMLBuilder import ElementFactoryError 
    2627from RBSkinning.SkinObject import SkinObject  
    2728from RBSkinning.UtilitySkinElements import StoreXML, RestoreStoredXMLMixin 
     
    3940    default_settings = SkinObject.default_settings.copy() 
    4041    #default_settings.update({ 
    41     #    'catch': '(ImportError,)' 
     42    #    'catch': '(ImportError, ElementFactoryError)' 
    4243    #    }) 
    4344 
    4445    ElementFactories = TemplateElementFactorySet 
    45     DefaultCatchlist = (ImportError,NameError,LookupError,AttributeError) 
     46    DefaultCatchlist = (ImportError, ElementFactoryError) 
    4647 
    4748    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    6061 
    6162        try: 
    62             catchtuple = self.EvalLocal(self.settings['catch']
     63            catchtuple = self.EvalLocal(self.settings['catch'], ElementFactoryError=ElementFactoryError
    6364        except (KeyError, IndexError): 
    6465            catchtuple = self.DefaultCatchlist