Revision adf385c7 lib/objects.py
b/lib/objects.py | ||
---|---|---|
109 | 109 |
setattr(self, k, v) |
110 | 110 |
|
111 | 111 |
def __getattr__(self, name): |
112 |
if name not in self.__slots__:
|
|
112 |
if name not in self._all_slots():
|
|
113 | 113 |
raise AttributeError("Invalid object attribute %s.%s" % |
114 | 114 |
(type(self).__name__, name)) |
115 | 115 |
return None |
116 | 116 |
|
117 | 117 |
def __setstate__(self, state): |
118 |
slots = self._all_slots() |
|
118 | 119 |
for name in state: |
119 |
if name in self.__slots__:
|
|
120 |
if name in slots:
|
|
120 | 121 |
setattr(self, name, state[name]) |
121 | 122 |
|
123 |
@classmethod |
|
124 |
def _all_slots(cls): |
|
125 |
"""Compute the list of all declared slots for a class. |
|
126 |
|
|
127 |
""" |
|
128 |
slots = [] |
|
129 |
for parent in cls.__mro__: |
|
130 |
slots.extend(getattr(parent, "__slots__", [])) |
|
131 |
return slots |
|
132 |
|
|
122 | 133 |
def ToDict(self): |
123 | 134 |
"""Convert to a dict holding only standard python types. |
124 | 135 |
|
... | ... | |
130 | 141 |
|
131 | 142 |
""" |
132 | 143 |
result = {} |
133 |
for name in self.__slots__:
|
|
144 |
for name in self._all_slots():
|
|
134 | 145 |
value = getattr(self, name, None) |
135 | 146 |
if value is not None: |
136 | 147 |
result[name] = value |
Also available in: Unified diff