1.1 --- a/micropython/inspect.py Sun Oct 21 00:53:20 2007 +0200
1.2 +++ b/micropython/inspect.py Sun Oct 21 02:25:25 2007 +0200
1.3 @@ -91,10 +91,10 @@
1.4
1.5 attr = {}
1.6 attr.update(self.class_attributes())
1.7 - for name in self.instattr:
1.8 + for i, name in enumerate(self.instattr):
1.9 if attr.has_key(name):
1.10 print "Instance attribute", name, "overrides class attribute."
1.11 - attr[name] = None
1.12 + attr[name] = i
1.13 return attr
1.14
1.15 class Function(NamespaceDict, Naming):
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/micropython/table.py Sun Oct 21 02:25:25 2007 +0200
2.3 @@ -0,0 +1,39 @@
2.4 +#!/usr/bin/env python
2.5 +
2.6 +"""
2.7 +Preparation of run-time attribute lookup tables.
2.8 +"""
2.9 +
2.10 +try:
2.11 + set
2.12 +except NameError:
2.13 + from sets import Set as set
2.14 +
2.15 +class Table:
2.16 +
2.17 + "A lookup table."
2.18 +
2.19 + def __init__(self):
2.20 + self.attributes = set()
2.21 + self.table = {}
2.22 + self.names = []
2.23 +
2.24 + def add(self, class_name, attributes):
2.25 + self.table[class_name] = attributes
2.26 + for name, origin in attributes.items():
2.27 + self.attributes.add(name)
2.28 +
2.29 + def attribute_names(self):
2.30 + self.names = self.names or list(self.attributes)
2.31 + return self.names
2.32 +
2.33 + def as_matrix(self):
2.34 + matrix = {}
2.35 + for class_name, attributes in self.table.items():
2.36 + row = []
2.37 + for name in self.attribute_names():
2.38 + row.append(attributes.get(name))
2.39 + matrix[class_name] = row
2.40 + return matrix
2.41 +
2.42 +# vim: tabstop=4 expandtab shiftwidth=4