Changeset 2551


Ignore:
Timestamp:
Nov 22, 2009, 4:07:29 PM (15 years ago)
Author:
broder
Message:

Add an iter method to invirt.common.struct.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/invirt-base/python/invirt/common.py

    r2541 r2551  
    1313    def __init__(self, d = {}, __prefix = None, **kwargs):
    1414        'd is the dictionary or the items-iterable to update my __dict__ with.'
    15         self.__dict__.update(d)
    16         self.__dict__.update(kwargs)
     15        dct = {}
     16        dct.update(d)
     17        dct.update(kwargs)
     18        self.__dict__.update(dct)
     19        self.__keys = set(dct)
    1720        self.__prefix = __prefix
    1821    def __getattr__(self, key):
     
    2528            raise AttributeError("anonymous struct has no member '%s'"
    2629                                 % (key,))
     30    def __iter__(self):
     31        for i in self.__keys:
     32            yield i
    2733
    2834def dicts2struct(x, prefix = None):
     
    119125        self.assertEqual(structs.list[0],     dicts['list'][0])
    120126        self.assertEqual(structs.list[1].key, dicts['list'][1]['key'])
     127        self.assertEqual(set(structs), set(['atom', 'dict', 'list']))
    121128
    122129if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.