1.1 --- a/micropython/inspect.py Sat Feb 23 21:11:02 2008 +0100
1.2 +++ b/micropython/inspect.py Sat Feb 23 21:25:03 2008 +0100
1.3 @@ -386,44 +386,59 @@
1.4 if not instattr.has_key(name):
1.5 instattr[name] = set([-1]) # position not yet defined
1.6
1.7 + # Cache the attributes by converting the positioned attributes into
1.8 + # a dictionary.
1.9 +
1.10 if not instattr:
1.11 self.all_instattr = {}
1.12 else:
1.13 - positions = instattr.items()
1.14 - instarray = [None] * len(positions)
1.15 -
1.16 - # Get the positions in ascending order of list size, with lists
1.17 - # of the same size ordered according to their smallest position
1.18 - # value.
1.19 -
1.20 - positions.sort(self._cmp_positions)
1.21 - #print self.name, positions
1.22 -
1.23 - # Get the names in position order.
1.24 -
1.25 - held = []
1.26 -
1.27 - for name, pos in positions:
1.28 - pos = list(pos)
1.29 - if pos[0] != -1 and instarray[pos[0]] is None:
1.30 - instarray[pos[0]] = name, Attr(pos[0], None, name)
1.31 - else:
1.32 - if pos[0] != -1 or len(pos) > 1:
1.33 - self.instattr_relocated.add(name)
1.34 - held.append((name, pos))
1.35 -
1.36 - for i, attr in enumerate(instarray):
1.37 - if attr is None:
1.38 - name, pos = held.pop()
1.39 - instarray[i] = name, Attr(i, None, name)
1.40 -
1.41 - self.all_instattr = dict(instarray)
1.42 + self.all_instattr = dict(self._get_position_list(instattr))
1.43
1.44 self.all_instattr_names = self.all_instattr.keys()
1.45
1.46 return self.all_instattr
1.47
1.48 + def _get_position_list(self, instattr):
1.49 +
1.50 + """
1.51 + Return the instance attributes, 'instattr', as a list indicating the
1.52 + positions of the attributes in the final instance structure.
1.53 + """
1.54 +
1.55 + positions = instattr.items()
1.56 + instarray = [None] * len(positions)
1.57 +
1.58 + # Get the positions in ascending order of list size, with lists
1.59 + # of the same size ordered according to their smallest position
1.60 + # value.
1.61 +
1.62 + positions.sort(self._cmp_positions)
1.63 + #print self.name, positions
1.64 +
1.65 + # Get the names in position order.
1.66 +
1.67 + held = []
1.68 +
1.69 + for name, pos in positions:
1.70 + pos = list(pos)
1.71 + if pos[0] != -1 and instarray[pos[0]] is None:
1.72 + instarray[pos[0]] = name, Attr(pos[0], None, name)
1.73 + else:
1.74 + if pos[0] != -1 or len(pos) > 1:
1.75 + self.instattr_relocated.add(name)
1.76 + held.append((name, pos))
1.77 +
1.78 + for i, attr in enumerate(instarray):
1.79 + if attr is None:
1.80 + name, pos = held.pop()
1.81 + instarray[i] = name, Attr(i, None, name)
1.82 +
1.83 + return instarray
1.84 +
1.85 def _cmp_positions(self, a, b):
1.86 +
1.87 + "Compare name plus position list operands 'a' and 'b'."
1.88 +
1.89 name_a, list_a = a
1.90 name_b, list_b = b
1.91 if len(list_a) < len(list_b):