Update of /cvsroot/sqlobject/SQLObject/SQLObject
In directory sc8-pr-cvs1:/tmp/cvs-serv1901/SQLObject
Modified Files:
SQLObject.py
Log Message:
Added registries for classes, so that class names only have to be
unique within their registry.
Index: SQLObject.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/SQLObject.py,v
retrieving revision 1.35
retrieving revision 1.36
diff -C2 -d -r1.35 -r1.36
*** SQLObject.py 12 May 2003 01:59:42 -0000 1.35
--- SQLObject.py 24 May 2003 20:48:50 -0000 1.36
***************
*** 47,59 ****
# actual classes.
! # Here we keep a dictionary of class names to classes -- note
# that the classes might be spread among different modules, so
# since we pile them together names need to be globally unique,
# not just module unique.
classRegistry = {}
! # This is the list of (cls, needClass) pairs, where cls has
! # a reference to the class named needClass.
! needSet = []
# Here's what we call after each class is created, to fix up
--- 47,62 ----
# actual classes.
! # Here we keep a dictionaries of class names to classes -- note
# that the classes might be spread among different modules, so
# since we pile them together names need to be globally unique,
# not just module unique.
+ # Like needSet below, the container dictionary is keyed by the
+ # "class registry".
classRegistry = {}
! # This contains the list of (cls, needClass) pairs, where cls has
! # a reference to the class named needClass. It is keyed by "class
! # registries", which are disjunct sets of classes.
! needSet = {}
# Here's what we call after each class is created, to fix up
***************
*** 62,72 ****
def setNeedSet():
global needSet
! newNeedSet = []
! for needClass, setCls in needSet:
! if classRegistry.has_key(setCls):
! setattr(findClass(needClass), '_SO_class_%s' % setCls, findClass(setCls))
! else:
! newNeedSet.append((needClass, setCls))
! needSet = newNeedSet
# This is the metaclass. It essentially takes a dictionary
--- 65,82 ----
def setNeedSet():
global needSet
! for registryName, needList in needSet.items():
! newNeedList = []
! for needClass, setCls in needList:
! if classRegistry.get(registryName, {}).has_key(setCls):
! setattr(findClass(needClass, registry=registryName),
! '_SO_class_%s' % setCls,
! findClass(setCls, registry=registryName))
! else:
! newNeedList.append((needClass, setCls))
! needSet[registryName] = newNeedList
!
! def addNeedSet(needClass, setCls):
! needSet.setdefault(needClass.__name__, []).append(
! (needClass.__name__, setCls))
# This is the metaclass. It essentially takes a dictionary
***************
*** 104,116 ****
d['_table'] = None
- # needSet stuff (see top of module) would get messed
- # up if more than one SQLObject class has the same
- # name.
- assert not classRegistry.has_key(className), "A database object by the name %s has already been created" % repr(className)
-
# We actually create the class.
newClass = type.__new__(cls, className, bases, d)
newClass._SO_finishedClassCreation = False
# We append to _columns, but we don't want to change the
# superclass's _columns list, so we make a copy if necessary
--- 114,132 ----
d['_table'] = None
# We actually create the class.
newClass = type.__new__(cls, className, bases, d)
newClass._SO_finishedClassCreation = False
+ # needSet stuff (see top of module) would get messed
+ # up if more than one SQLObject class has the same
+ # name.
+ registry = newClass._registry
+ assert not classRegistry.get(registry, {}).has_key(className), "A database object by the name %s has already been created" % repr(className)
+
+ # Register it, for use with needSet
+ if not classRegistry.has_key(registry):
+ classRegistry[registry] = {}
+ classRegistry[registry][className] = newClass
+
# We append to _columns, but we don't want to change the
# superclass's _columns list, so we make a copy if necessary
***************
*** 194,199 ****
makeProperties(newClass)
- # Register it, for use with needSet
- classRegistry[className] = newClass
# Call needSet
setNeedSet()
--- 210,213 ----
***************
*** 263,269 ****
break
! def findClass(name):
! assert classRegistry.has_key(name), "No class by the name %s found (I have %s)" % (repr(name), ', '.join(classRegistry.keys()))
! return classRegistry[name]
--- 277,283 ----
break
! def findClass(name, registry=None):
! assert classRegistry.get(registry, {}).has_key(name), "No class by the name %s found (I have %s)" % (repr(name), ', '.join(classRegistry.keys()))
! return classRegistry[registry][name]
***************
*** 311,314 ****
--- 325,330 ----
_style = None
+ _registry = None
+
def __new__(cls, id, connection=None, selectResults=None):
***************
*** 438,442 ****
# some point. See needSet at the top of the
# file for more on this.
! needSet.append((cls.__name__, column.foreignKey))
if column.alternateMethodName:
--- 454,458 ----
# some point. See needSet at the top of the
# file for more on this.
! addNeedSet(cls, column.foreignKey)
if column.alternateMethodName:
***************
*** 945,949 ****
# We only have names of classes a lot of the time,
# so we have to fetch the actual class definition:
! cls = findClass(self.otherClass)
ids = inst._connection._SO_selectJoin(
cls,
--- 961,965 ----
# We only have names of classes a lot of the time,
# so we have to fetch the actual class definition:
! cls = findClass(self.otherClass, registry=inst._registry)
ids = inst._connection._SO_selectJoin(
cls,
***************
*** 977,981 ****
def performJoin(self, inst):
! cls = findClass(self.otherClass)
me = self.callingClass
ids = me._connection._SO_intermediateJoin(
--- 993,997 ----
def performJoin(self, inst):
! cls = findClass(self.otherClass, registry=inst._registry)
me = self.callingClass
ids = me._connection._SO_intermediateJoin(
|