Revision adf385c7

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
b/lib/opcodes.py
52 52
    __slots__ attribute for this class.
53 53

  
54 54
    """
55
    slots = self._all_slots()
55 56
    for key in kwargs:
56
      if key not in self.__slots__:
57
      if key not in slots:
57 58
        raise TypeError("Object %s doesn't support the parameter '%s'" %
58 59
                        (self.__class__.__name__, key))
59 60
      setattr(self, key, kwargs[key])
......
69 70

  
70 71
    """
71 72
    state = {}
72
    for name in self.__slots__:
73
    for name in self._all_slots():
73 74
      if hasattr(self, name):
74 75
        state[name] = getattr(self, name)
75 76
    return state
......
88 89
      raise ValueError("Invalid data to __setstate__: expected dict, got %s" %
89 90
                       type(state))
90 91

  
91
    for name in self.__slots__:
92
    for name in self._all_slots():
92 93
      if name not in state:
93 94
        delattr(self, name)
94 95

  
95 96
    for name in state:
96 97
      setattr(self, name, state[name])
97 98

  
99
  @classmethod
100
  def _all_slots(cls):
101
    """Compute the list of all declared slots for a class.
102

  
103
    """
104
    slots = []
105
    for parent in cls.__mro__:
106
      slots.extend(getattr(parent, "__slots__", []))
107
    return slots
108

  
98 109

  
99 110
class OpCode(BaseOpCode):
100 111
  """Abstract OpCode.
b/tools/cfgshell
93 93
    dirs = []
94 94
    entries = []
95 95
    if isinstance(obj, objects.ConfigObject):
96
      for name in obj.__slots__:
96
      # pylint: disable-msg=W0212
97
      # yes, we're using a protected member
98
      for name in obj._all_slots():
97 99
        child = getattr(obj, name, None)
98 100
        if isinstance(child, (list, dict, tuple, objects.ConfigObject)):
99 101
          dirs.append(name)

Also available in: Unified diff