Changeset 306
- Timestamp:
- 10/08/02 18:27:40 (6 years ago)
- Files:
-
- trunk/RBFoundation/RBFoundation/ChainedDict.py (modified) (1 diff)
- trunk/RBFoundation/RBFoundation/IndexedProperty.py (modified) (3 diffs)
- trunk/RBFoundation/RBFoundation/XMLObjectify.py (modified) (2 diffs)
- trunk/RBFoundation/test/test_doctests.py (modified) (1 diff)
- trunk/RBSkinning/RBSkinning/skin/template.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/RBFoundation/RBFoundation/ChainedDict.py
r290 r306 87 87 def SetChained(self, chained): 88 88 self.chained = chained or {} 89 return self.chained 89 90 90 91 def GetChained(self): trunk/RBFoundation/RBFoundation/IndexedProperty.py
r250 r306 8 8 ##- architecture. Enjoy. 9 9 ##~ 10 ##~ Copyright (C) 2002 Shane Holloway10 ##~ Copyright (C) 2002 TechGame Networks, LLC. 11 11 ##~ 12 12 ##~ This library is free software; you can redistribute it and/or 13 ##~ modify it under the terms of the GNU Lesser General Public 14 ##~ License as published by the Free Software Foundation; either 15 ##~ version 2.1 of the License, or any later version at your discretion. 13 ##~ modify it under the terms of the BSD style License as found in the 14 ##~ LICENSE file included with this distribution. 16 15 ##~ 17 ##~ This library is distributed in the hope that it will be useful, 18 ##~ but WITHOUT ANY WARRANTY; without even the implied warranty of 19 ##~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 ##~ Lesser General Public License for more details. 21 ##~ 22 ##~ You should have received a copy of the GNU Lesser General Public 23 ##~ License along with this library; if not, write to the Free Software 24 ##~ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 ##~ 26 ##~ 27 ##~ Shane Holloway can be reached at shane.holloway@runeblade.com, or by post at 28 ##~ 1630 Dublin Blvd. #210 29 ##~ Colorado Springs, Colorado, USA, 80918 16 ##~ TechGame Networks, LLC can be reached at: 17 ##~ 3578 E. Hartsel Drive #211 18 ##~ Colorado Springs, Colorado, USA, 80920 30 19 ##~ 31 20 ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 40 29 41 30 class IndexedProperty(object): 31 """ 32 >>> class _Test(object): 33 ... def __init__(self, data): self.data = data 34 ... def __GetData(self): return self.data 35 ... test0 = IndexedProperty(__GetData, 0) 36 ... test1 = IndexedProperty(__GetData, 1) 37 ... test2 = IndexedProperty(__GetData, 2) 38 ... 39 >>> t = _Test([42, 42**2, 42**3]) 40 >>> t.test0 41 42 42 >>> t.test1 43 1764 44 >>> t.test2 45 74088 46 >>> t.test2 = 2 * t.test1 / t.test0; t.test2 47 84 48 >>> del t.test1; t.test1 49 84 50 >>> t.test2 51 Traceback (most recent call last): 52 IndexError: list index out of range 53 """ 42 54 def __init__(self, containerfn, index, doc=''): 43 55 self.__doc__ = doc 44 self.container = containerfn 56 if callable(containerfn): 57 self.container = containerfn, tuple() 58 else: self.container = getattr, (containerfn, ) 45 59 self.index = index 46 60 47 61 def __get__(self, obj, klass): 48 62 if obj: 49 return self.container(obj)[self.index] 63 fn, args = self.container 64 return fn(obj, *args)[self.index] 50 65 else: return self 51 66 52 67 def __set__(self, obj, value): 53 self.container(obj)[self.index] = value 68 fn, args = self.container 69 fn(obj, *args)[self.index] = value 54 70 55 def __delete__(self, obj, value): 56 del self.container(obj)[self.index] 71 def __delete__(self, obj): 72 fn, args = self.container 73 del fn(obj, *args)[self.index] 74 75 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 76 77 class IndexedPropertyDefault(IndexedProperty): 78 def __init__(self, containerfn, index, default=None, doc=''): 79 self.default = default 80 IndexedProperty.__init__(self, containerfn, index, doc) 81 82 def __get__(self, obj, klass): 83 try: return IndexedProperty.__get__(self, obj, klass) 84 except (KeyError, ValueError), e: return self.default 57 85 58 86 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 108 136 assert t1.Neat == 250 109 137 138 import doctest 139 import IndexedProperty as _test 140 doctest.testmod(_test) 110 141 print "Test complete." 111 142 trunk/RBFoundation/RBFoundation/XMLObjectify.py
r281 r306 91 91 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 92 92 93 from __future__ import generators 93 94 from Foundation import XMLBuilder 94 95 from xml.sax.saxutils import escape, quoteattr … … 225 226 #~ Protected Methods 226 227 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 228 229 def _iterAllElements(self, andData=0): 230 """Returns all elements.""" 231 for x in self._elements: 232 if andData or x[0][-1]: 233 yield x[-1] 234 235 def _iterElements(self, namespace=None, node=None, andData=0): 236 """Returns all elements.""" 237 for x in self._elements: 238 if not andData and not x[0][-1]: continue 239 if namespace and namespace != x[0][0]: continue 240 if node and node != x[0][-1]: continue 241 yield x[-1] 227 242 228 243 def _getAllElements(self, andData=0): trunk/RBFoundation/test/test_doctests.py
r293 r306 24 24 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 25 25 26 from Foundation import WeakBind, ContextApply, Utilities, LazyProperty, ChainedDict, AttributedDict, Acquisition 26 from Foundation import WeakBind, ContextApply, Utilities, LazyProperty, ChainedDict, AttributedDict, Acquisition, IndexedProperty 27 27 28 28 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ trunk/RBSkinning/RBSkinning/skin/template.py
r280 r306 73 73 74 74 if 'unravelnode' not in self.source_settings: 75 if self.mode in [self._ExpandingMode, self._InvokingMode]:75 if self.mode not in [self._StoringMode]: 76 76 self.settings['unravelnode'] = '1' 77 77 … … 82 82 83 83 if self.mode == self._StoringMode: 84 self.object = self.settings['name'] 84 85 setattr(self.context, self.settings['name'], weakref.proxy(self)) 85 86 elif self.mode == self._ExpandingMode: … … 87 88 TemplateInner.RestoreChildren(self.owner) 88 89 elif self.mode == self._InvokingMode: 89 InvokeName = self.settings['invoke']90 TemplateOuter = getattr(self.context, InvokeName)90 TemplateOuter = self.EvalLocal(self.settings['invoke']) 91 InvokeName = TemplateOuter.object 91 92 self.parent().PushContext(force=1) 92 93 setattr(self.context, '::invoke:' + InvokeName, weakref.proxy(self))
