Changeset 306

Show
Ignore:
Timestamp:
10/08/02 18:27:40 (6 years ago)
Author:
sholloway
Message:

Added Indexed Property
Changed ChainedDict?.SetChained?.
Changed skin template's invoke attribute to be evaluated instead of having it just be a string lookup.
Added element iterators to XMLObjectify
Updated demos
Added to test.doctests

Files:

Legend:

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

    r290 r306  
    8787    def SetChained(self, chained): 
    8888        self.chained = chained or {} 
     89        return self.chained 
    8990         
    9091    def GetChained(self): 
  • trunk/RBFoundation/RBFoundation/IndexedProperty.py

    r250 r306  
    88##- architecture. Enjoy. 
    99##~  
    10 ##~ Copyright (C) 2002  Shane Holloway 
     10##~ Copyright (C) 2002  TechGame Networks, LLC. 
    1111##~  
    1212##~ 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. 
    1615##~  
    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 
    3019##~ 
    3120##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    4029 
    4130class 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    """ 
    4254    def __init__(self, containerfn, index, doc=''): 
    4355        self.__doc__ = doc 
    44         self.container = containerfn 
     56        if callable(containerfn): 
     57            self.container = containerfn, tuple() 
     58        else: self.container = getattr, (containerfn, ) 
    4559        self.index = index 
    4660         
    4761    def __get__(self, obj, klass): 
    4862        if obj: 
    49             return self.container(obj)[self.index] 
     63            fn, args = self.container 
     64            return fn(obj, *args)[self.index] 
    5065        else: return self 
    5166 
    5267    def __set__(self, obj, value): 
    53         self.container(obj)[self.index] = value 
     68        fn, args = self.container 
     69        fn(obj, *args)[self.index] = value 
    5470 
    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 
     77class 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 
    5785 
    5886#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    108136    assert t1.Neat == 250 
    109137 
     138    import doctest 
     139    import IndexedProperty as _test 
     140    doctest.testmod(_test) 
    110141    print "Test complete." 
    111142 
  • trunk/RBFoundation/RBFoundation/XMLObjectify.py

    r281 r306  
    9191#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    9292 
     93from __future__ import generators 
    9394from Foundation import XMLBuilder 
    9495from xml.sax.saxutils import escape, quoteattr 
     
    225226    #~ Protected Methods  
    226227    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     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] 
    227242 
    228243    def _getAllElements(self, andData=0): 
  • trunk/RBFoundation/test/test_doctests.py

    r293 r306  
    2424#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    2525 
    26 from Foundation import WeakBind, ContextApply, Utilities, LazyProperty, ChainedDict, AttributedDict, Acquisition 
     26from Foundation import WeakBind, ContextApply, Utilities, LazyProperty, ChainedDict, AttributedDict, Acquisition, IndexedProperty 
    2727 
    2828#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  • trunk/RBSkinning/RBSkinning/skin/template.py

    r280 r306  
    7373 
    7474        if 'unravelnode' not in self.source_settings: 
    75             if self.mode in [self._ExpandingMode, self._InvokingMode]: 
     75            if self.mode not in [self._StoringMode]: 
    7676                self.settings['unravelnode'] = '1' 
    7777 
     
    8282 
    8383        if self.mode == self._StoringMode: 
     84            self.object = self.settings['name'] 
    8485            setattr(self.context, self.settings['name'], weakref.proxy(self)) 
    8586        elif self.mode == self._ExpandingMode: 
     
    8788            TemplateInner.RestoreChildren(self.owner) 
    8889        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 
    9192            self.parent().PushContext(force=1) 
    9293            setattr(self.context, '::invoke:' + InvokeName, weakref.proxy(self))