root/trunk/RBSkinning/RBSkinning/skin/trylist.py

Revision 644, 2.8 kB (checked in by sholloway, 5 years ago)

Made skin:trylist only catch element factory and import errors

Line 
1 #!/usr/bin/env python
2 ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 ##~ License
4 ##~
5 ##- The RuneBlade Foundation library is intended to ease some
6 ##- aspects of writing intricate Jabber, XML, and User Interface (wxPython, etc.)
7 ##- applications, while providing the flexibility to modularly change the
8 ##- architecture. Enjoy.
9 ##~
10 ##~ Copyright (C) 2002  TechGame Networks, LLC.
11 ##~
12 ##~ This library is free software; you can redistribute it and/or
13 ##~ modify it under the terms of the BSD style License as found in the
14 ##~ LICENSE file included with this distribution.
15 ##~
16 ##~ TechGame Networks, LLC can be reached at:
17 ##~ 3578 E. Hartsel Drive #211
18 ##~ Colorado Springs, Colorado, USA, 80920
19 ##~
20 ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21
22 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 #~ Imports
24 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25
26 from RBFoundation.XMLBuilder import ElementFactoryError
27 from RBSkinning.SkinObject import SkinObject
28 from RBSkinning.UtilitySkinElements import StoreXML, RestoreStoredXMLMixin
29 from template import TemplateElementFactorySet
30
31 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32 #~ Class
33 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34
35 class trylist(SkinObject, RestoreStoredXMLMixin):
36     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37     #~ Constants / Variables / Etc.
38     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
39
40     default_settings = SkinObject.default_settings.copy()
41     #default_settings.update({
42     #    'catch': '(ImportError, ElementFactoryError)'
43     #    })
44
45     ElementFactories = TemplateElementFactorySet
46     DefaultCatchlist = (ImportError, ElementFactoryError)
47
48     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
49     #~ Public Methods
50     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51
52     def __init__(self, owner, parent, node, attributes, namespacemap):
53         SkinObject.__init__(self, owner, parent, node, attributes, namespacemap)
54         self.owner = owner
55
56     def SkinInitialize(self):
57         self.owner.PushElementFactorySet(self.ElementFactories)
58
59     def SkinFinalize(self):
60         self.owner.PopElementFactorySet()
61
62         try:
63             catchtuple = self.EvalLocal(self.settings['catch'], ElementFactoryError=ElementFactoryError)
64         except (KeyError, IndexError):
65             catchtuple = self.DefaultCatchlist
66
67         stackstate = self.owner._SaveStackState()
68         for isnode, child in self.children:
69             try:
70                 if isnode:
71                     result = child.Restore(self.owner)
72                     if result is not None:
73                         break
74             except catchtuple, e:
75                 # Adjust the element stack to what it was when wes started
76                 self.owner._RestoreStackState(stackstate)
77
78         del self.owner
79
80     def _addData(self, data):
81         pass # Ignore all CDATA
Note: See TracBrowser for help on using the browser.