[SQL-CVS] r584 - trunk/SQLObject/sqlobject
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <sub...@co...> - 2005-02-09 05:52:04
|
Author: ianb Date: 2005-02-09 05:52:00 +0000 (Wed, 09 Feb 2005) New Revision: 584 Modified: trunk/SQLObject/sqlobject/main.py Log: Added a sqlmeta buddy class/object, which will hold data in the very near future. Modified: trunk/SQLObject/sqlobject/main.py =================================================================== --- trunk/SQLObject/sqlobject/main.py 2005-02-09 05:40:19 UTC (rev 583) +++ trunk/SQLObject/sqlobject/main.py 2005-02-09 05:52:00 UTC (rev 584) @@ -134,6 +134,18 @@ """ pass +class sqlmeta(object): + + """ + This object is the object we use to keep track of all sorts of + information. Subclasses are made for each SQLObject subclass + (dynamically if necessary), and instances are created to go + alongside every SQLObject instance. + """ + + def __init__(self, instance): + self.instance = instance + # SQLObject is the superclass for all SQLObject classes, of # course. All the deeper magic is done in MetaSQLObject, and # only lesser magic is done here. All the actual work is done @@ -192,7 +204,18 @@ # aren't using integer IDs _idType = int + sqlmeta = sqlmeta + def __classinit__(cls, new_attrs): + + if (not new_attrs.has_key('sqlmeta') + and not cls.__bases__ == (object,)): + # We have to create our own subclass, usually. + # type(className, bases_tuple, attr_dict) creates a new + # subclass: + cls.sqlmeta = type('sqlmeta', (cls.sqlmeta,), {}) + cls.sqlmeta.soClass = cls + implicitColumns = [] implicitJoins = [] implicitIndexes = [] @@ -623,6 +646,10 @@ # created, unlike __init__ which would be called # anytime the object was returned from cache. self.id = id + # We shadow the sqlmeta class with an instance of sqlmeta + # that points to us (our sqlmeta buddy object; where the + # sqlmeta class is our class's buddy class) + self.sqlmeta = self.__class__.sqlmeta(self) self._SO_writeLock = threading.Lock() # If no connection was given, we'll inherit the class |