# HG changeset patch # User Paul Boddie # Date 1192926325 -7200 # Node ID 96337e2a2058a19df6d8b55f4744fe432a7903ba # Parent 12f98130428ced83b57bcbc4cb917cc1bf19c688 Added positions for instance attributes. Added a module with support for making class/attribute tables. diff -r 12f98130428c -r 96337e2a2058 micropython/inspect.py --- a/micropython/inspect.py Sun Oct 21 00:53:20 2007 +0200 +++ b/micropython/inspect.py Sun Oct 21 02:25:25 2007 +0200 @@ -91,10 +91,10 @@ attr = {} attr.update(self.class_attributes()) - for name in self.instattr: + for i, name in enumerate(self.instattr): if attr.has_key(name): print "Instance attribute", name, "overrides class attribute." - attr[name] = None + attr[name] = i return attr class Function(NamespaceDict, Naming): diff -r 12f98130428c -r 96337e2a2058 micropython/table.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/micropython/table.py Sun Oct 21 02:25:25 2007 +0200 @@ -0,0 +1,39 @@ +#!/usr/bin/env python + +""" +Preparation of run-time attribute lookup tables. +""" + +try: + set +except NameError: + from sets import Set as set + +class Table: + + "A lookup table." + + def __init__(self): + self.attributes = set() + self.table = {} + self.names = [] + + def add(self, class_name, attributes): + self.table[class_name] = attributes + for name, origin in attributes.items(): + self.attributes.add(name) + + def attribute_names(self): + self.names = self.names or list(self.attributes) + return self.names + + def as_matrix(self): + matrix = {} + for class_name, attributes in self.table.items(): + row = [] + for name in self.attribute_names(): + row.append(attributes.get(name)) + matrix[class_name] = row + return matrix + +# vim: tabstop=4 expandtab shiftwidth=4