[z3-checkins] r22262 - in z3/sqlos/trunk/src/sqlos: . ftests
jinty at codespeak.net
jinty at codespeak.net
Tue Jan 17 21:28:52 CET 2006
Author: jinty
Date: Tue Jan 17 21:28:50 2006
New Revision: 22262
Modified:
z3/sqlos/trunk/src/sqlos/container.py
z3/sqlos/trunk/src/sqlos/ftests/containers.txt
z3/sqlos/trunk/src/sqlos/ftests/isolated_containers.txt
z3/sqlos/trunk/src/sqlos/metaconfigure.py
Log:
Merge the jinty-utilities branch. It really is just a bugfix, but re-factors to
get there.
------------------------------------------------------------------------
r21860 | jinty | 2006-01-10 02:39:25 +0100 (Tue, 10 Jan 2006) | 1 line
Add a comment.
------------------------------------------------------------------------
r21859 | jinty | 2006-01-10 02:20:33 +0100 (Tue, 10 Jan 2006) | 1 line
Deprecate allowedFactories and convert the last in-tree users.
------------------------------------------------------------------------
r21858 | jinty | 2006-01-10 02:07:20 +0100 (Tue, 10 Jan 2006) | 1 line
Dike out the SQLObjectFactory.
------------------------------------------------------------------------
r21857 | jinty | 2006-01-10 02:03:18 +0100 (Tue, 10 Jan 2006) | 1 line
Create a _getAllowedIISQLObjectUtilities function and convert users of
get allowedFactories to use this. Also make the logic of the NameChooser
to follow that of _getAllowedIISQLObjectUtilities. This fixes the bug
uncovered in the previous commit.
------------------------------------------------------------------------
r21856 | jinty | 2006-01-10 02:00:14 +0100 (Tue, 10 Jan 2006) | 1 line
Change the testing infrastructure so the bug we are trying to fix is
triggered.
Modified: z3/sqlos/trunk/src/sqlos/container.py
==============================================================================
--- z3/sqlos/trunk/src/sqlos/container.py (original)
+++ z3/sqlos/trunk/src/sqlos/container.py Tue Jan 17 21:28:50 2006
@@ -16,6 +16,7 @@
from persistent import Persistent
from zope.interface import implements
from zope.component import IFactory
+from zope import deprecation
from zope.app import zapi
from zope.app.container.interfaces import IContained
from zope.app.container.contained import ContainedProxy
@@ -65,8 +66,10 @@
for name, factory in zapi.getFactoriesFor(ISQLObject, context=self.context):
if checkFactory(self, None, factory):
# get the sqlobject class
- factory = zapi.getUtility(IISQLObject, name, context=self.context)
- if obj.sqlmeta.table == factory.sqlmeta.table:
+ utility = zapi.getUtility(IISQLObject, name, context=self.context)
+ if utility is None:
+ continue
+ if obj.sqlmeta.table == utility.sqlmeta.table:
# if the tables names are the same, we assume that the
# sqlobject is an instance of that class, perhaps that
# is wrong
@@ -81,10 +84,24 @@
def __init__(self):
pass
- def allowedFactories(self):
+ def _allowedFactories(self):
for name, factory in zapi.getFactoriesFor(ISQLObject, context=self):
if checkFactory(self, None, factory):
yield name
+ allowedFactories = deprecation.deprecated(_allowedFactories,
+ 'allowedFactories is deprecated and will be removed after sqlos 0.2'
+ ' please use _getAllowedIISQLObjectUtilities instead.')
+
+ def _getAllowedIISQLObjectUtilities(self):
+ for name, factory in zapi.getFactoriesFor(ISQLObject, context=self):
+ if checkFactory(self, None, factory):
+ utility = zapi.queryUtility(IISQLObject, name, context=self)
+ # Someone might have registered a factory implementing
+ # IISQLObject using <zope:factory> for whatever reason.
+ # in this case queryUtility returns None and we can just
+ # ignore it
+ if utility is not None:
+ yield name, utility
def keys(self):
""" Return a sequence-like object containing the names
@@ -105,10 +122,9 @@
"""Return a sequence-like object containing tuples of the form
(name, object) for the objects that appear in the folder.
"""
- for factoryName in self.allowedFactories():
- factory = zapi.getUtility(IISQLObject, factoryName, context=self)
- for obj in factory.select():
- name = '%s.%s' % (factoryName, obj.id)
+ for utility_name, utility in self._getAllowedIISQLObjectUtilities():
+ for obj in utility.select():
+ name = '%s.%s' % (utility_name, obj.id)
yield (name, contained(obj, parent=self, name=name))
def __getitem__(self, name):
@@ -140,15 +156,15 @@
except ValueError:
raise KeyError, name
- if factoryName not in self.allowedFactories():
- raise KeyError, name
-
- factory = zapi.getUtility(IISQLObject, factoryName, context=self)
- try:
- obj = factory.get(id)
- return contained(obj, parent=self, name=name)
- except SQLObjectNotFound:
- raise KeyError, name
+ for utility_name, utility in self._getAllowedIISQLObjectUtilities():
+ if factoryName != utility_name:
+ continue
+ try:
+ obj = utility.get(id)
+ return contained(obj, parent=self, name=name)
+ except SQLObjectNotFound:
+ raise KeyError, name
+ raise KeyError, name
def get(self, name, default=None):
"""Return the named object, or the value of the default
@@ -168,9 +184,8 @@
def __len__(self):
"""Return the number of objects in the folder."""
i = 0
- for factoryName in self.allowedFactories():
- factory = zapi.getUtility(IISQLObject, factoryName, context=self)
- i += factory.select().count() # optimal, does not get all objects
+ for utility_name, utility in self._getAllowedIISQLObjectUtilities():
+ i += utility.select().count() # optimal, does not get all objects
return i
def __delitem__(self, name):
@@ -192,11 +207,20 @@
_container_id = None
def allowedFactories(self):
- # Ignore all factories not providing ISQLObjectIsolated
- for f in SQLObjectContainer.allowedFactories(self):
+ # Ignore all factories not implementing ISQLObjectIsolated
+ for f in SQLObjectContainer._allowedFactories(self):
implemented = zapi.getFactoryInterfaces(f)
if implemented.isOrExtends(ISQLObjectIsolated):
yield f
+ allowedFactories = deprecation.deprecated(allowedFactories,
+ 'allowedFactories is deprecated and will be removed after sqlos 0.2'
+ ' please use _getAllowedIISQLObjectUtilities instead.')
+
+ def _getAllowedIISQLObjectUtilities(self):
+ # Ignore all utilities not implementing ISQLObjectIsolated
+ for name, utility in SQLObjectContainer._getAllowedIISQLObjectUtilities(self):
+ if ISQLObjectIsolated.implementedBy(utility):
+ yield name, utility
def _getContainerId(self):
if self._container_id is None:
@@ -209,9 +233,8 @@
def __len__(self):
"""Return the number of objects in the folder."""
i = 0
- for factoryName in self.allowedFactories():
- factory = zapi.getUtility(IISQLObject, factoryName, context=self)
- i += factory.countByDomain(self.container_id)
+ for name, utility in self._getAllowedIISQLObjectUtilities():
+ i += utility.countByDomain(self.container_id)
return i
def __delitem__(self, name):
@@ -236,10 +259,9 @@
"""Return a sequence-like object containing tuples of the form
(name, object) for the objects that appear in the folder.
"""
- for factoryName in self.allowedFactories():
- factory = zapi.getUtility(IISQLObject, factoryName, context=self)
- for obj in factory.selectByDomain(self.container_id):
- name = '%s.%s' % (factoryName, obj.id)
+ for utility_name, utility in self._getAllowedIISQLObjectUtilities():
+ for obj in utility.selectByDomain(self.container_id):
+ name = '%s.%s' % (utility_name, obj.id)
yield (name, contained(obj, parent=self, name=name))
def __getitem__(self, name):
Modified: z3/sqlos/trunk/src/sqlos/ftests/containers.txt
==============================================================================
--- z3/sqlos/trunk/src/sqlos/ftests/containers.txt (original)
+++ z3/sqlos/trunk/src/sqlos/ftests/containers.txt Tue Jan 17 21:28:50 2006
@@ -18,7 +18,8 @@
In the ftesting.zcml a SamplePerson factory should be registered:
- >>> u'sqlos.somename.SamplePerson' in container.allowedFactories()
+ >>> utilities = [i for i, j in container._getAllowedIISQLObjectUtilities()]
+ >>> u'sqlos.somename.SamplePerson' in utilities
True
So let's create some database tables if not already there:
Modified: z3/sqlos/trunk/src/sqlos/ftests/isolated_containers.txt
==============================================================================
--- z3/sqlos/trunk/src/sqlos/ftests/isolated_containers.txt (original)
+++ z3/sqlos/trunk/src/sqlos/ftests/isolated_containers.txt Tue Jan 17 21:28:50 2006
@@ -18,7 +18,8 @@
In the ftesting.zcml a SampleIsolatedPerson factory should be registered:
- >>> u'SampleIsolatedPerson' in container.allowedFactories()
+ >>> utilities = [i for i, j in container._getAllowedIISQLObjectUtilities()]
+ >>> u'SampleIsolatedPerson' in utilities
True
So let's create some database tables if not already there:
Modified: z3/sqlos/trunk/src/sqlos/metaconfigure.py
==============================================================================
--- z3/sqlos/trunk/src/sqlos/metaconfigure.py (original)
+++ z3/sqlos/trunk/src/sqlos/metaconfigure.py Tue Jan 17 21:28:50 2006
@@ -19,14 +19,11 @@
from sqlos.interfaces import IISQLObject, IConnectionName
from sqlos.interfaces import IReadSQLObjectClass, IWriteSQLObjectClass
-class SQLObjectFactory(Factory):
- implements(IFactory)
-
def handler(_context, component, id, title=None, description=None):
if isinstance(component, basestring):
component = _context.resolve(component)
- factoryObj = SQLObjectFactory(component, title, description)
+ factoryObj = Factory(component, title, description)
# XXX We compute a permission name from the package top-level name
# plus the component (which should be a class) __name__ The
More information about the z3-checkins
mailing list