[z3-checkins] r5264 - in z3/sqlos/trunk: . auth container ftests
interfaces services transaction
dreamcatcher at codespeak.net
dreamcatcher at codespeak.net
Thu Jun 24 05:07:34 MEST 2004
Author: dreamcatcher
Date: Thu Jun 24 05:07:32 2004
New Revision: 5264
Added:
z3/sqlos/trunk/_sqlos.py (contents, props changed)
z3/sqlos/trunk/connection.py (contents, props changed)
z3/sqlos/trunk/descriptor.py (contents, props changed)
z3/sqlos/trunk/metaconfigure.py (contents, props changed)
z3/sqlos/trunk/metadirectives.py (contents, props changed)
Modified:
z3/sqlos/trunk/README.txt
z3/sqlos/trunk/__init__.py
z3/sqlos/trunk/adapter.py
z3/sqlos/trunk/annotations.py
z3/sqlos/trunk/attributeannotations.py
z3/sqlos/trunk/auth/__init__.py
z3/sqlos/trunk/configure.zcml
z3/sqlos/trunk/container/__init__.py
z3/sqlos/trunk/factory.py
z3/sqlos/trunk/ftests/__init__.py
z3/sqlos/trunk/ftests/test_transaction.py
z3/sqlos/trunk/interfaces/__init__.py
z3/sqlos/trunk/interfaces/auth.py
z3/sqlos/trunk/interfaces/container.py
z3/sqlos/trunk/interfaces/services.py
z3/sqlos/trunk/meta.zcml
z3/sqlos/trunk/services/__init__.py
z3/sqlos/trunk/services/classservice.py
z3/sqlos/trunk/services/metaconfigure.py
z3/sqlos/trunk/services/servicenames.py
z3/sqlos/trunk/services/sqlfactoryservice.py
z3/sqlos/trunk/transaction/__init__.py
z3/sqlos/trunk/utils.py
z3/sqlos/trunk/vocab.py
Log:
Fix copyright header. Rework connection handling to fix a race condition detected by Andrew Bennetts. Add a sqlos:factory directive that registers both the factory and a IISQLObject utility. This should replace the ClassService. Add deprecation warnings to registerClass and getFactory. Those should go away on the next batch of changes.
Modified: z3/sqlos/trunk/README.txt
==============================================================================
--- z3/sqlos/trunk/README.txt (original)
+++ z3/sqlos/trunk/README.txt Thu Jun 24 05:07:32 2004
@@ -2,7 +2,7 @@
===================================
:Author: Sidnei da Silva
-:Contact: sidnei at redesul.com.br
+:Contact: sidnei at awkly.org
:Date: $Date$
:Version: $Rev$
@@ -56,8 +56,8 @@
See this example::
from zope.interface import implements
- from SQLObject import *
- from zopeproducts.sfbr.interfaces import IPerson
+ from sqlobject import *
+ from myproject.interfaces import IPerson
class Person(SQLObject):
@@ -92,35 +92,36 @@
This interface is used to auto-generate the edit forms inside Zope
3. Let`s see what is needed to do that::
- <zopeConfigure
+ <configure
xmlns='http://namespaces.zope.org/zope'
- xmlns:browser='http://namespaces.zope.org/browser'>
+ xmlns:browser='http://namespaces.zope.org/browser'
+ xmlns:sqlos='http://namespaces.sqlobject.org/sqlos'>
<browser:editform
- schema="zopeproducts.example.interfaces.IPerson"
+ schema="myproduct.interfaces.IPerson"
name="edit.html"
menu="zmi_views"
label="Edit a Person"
permission="zope.ManageContent"
/>
- <content class="zopeproducts.example.person.Person">
-
- <factory
- id="Person"
- permission="zope.ManageContent"
- title="Person"
- description="A Simple Person" />
+ <content class="myproduct.person.Person">
<require
permission="zope.ManageContent"
- interface="zopeproducts.example.interfaces.IPerson"
- set_schema="zopeproducts.example.interfaces.IPerson"
+ interface="myproduct.interfaces.IPerson"
+ set_schema="myproduct.interfaces.IPerson"
/>
</content>
- </zopeConfigure>
+ <sqlos:factory
+ id="Person"
+ title="Person"
+ description="A Simple Person"
+ />
+
+ </configure>
There are a few things that you need to know about this piece of
ZCML:
@@ -139,8 +140,11 @@
Second, the <content class="...."> directive is used to register some
information about the class, like what factory will be using for
creating instances of it and what are the permissions needed to do
-stuff with this class. The <factory> stuff is not completely plugged
-in at the moment, so let's take a look at the <require> directive:
+stuff with this class. The <sqlos:factory> directive register the
+class as a IFactory utility and also registers the class as a
+IISQLObject utility.
+
+Let's take a look at the <require> directive:
As you can see, there are 3 attributes on the directive. The
``permission`` attribute specifies the permission that is
@@ -154,32 +158,6 @@
protect ``set_schema`` on the interface, you won`t be able to modify
the instance.
-Now, the last thing needed is registering the class with the
-``ClassService``, which was created temporarily because there wasn't a
-service that could do what we wanted. The service that is more closer
-to what we need is the Factory Service, but Jim said he was going to
-change it soon, so its better to have our own service for now. Later
-we can merge the functionalities we need into the Factory service.
-
-For registering our class with the class service, all you need is
-this::
-
- <zopeConfigure
- xmlns='http://namespaces.zope.org/zope'
- xmlns:classService='http://namespaces.zope.org/class'>
-
- <classService:registerClass
- component="zopeproducts.example.person.Person"
- name="Person"
- />
-
- </zopeConfigure>
-
-I will not enter in details about how this work either. You just need
-to know that this registers the person class under the name
-``Person``, so that's what you will see on the SQLObjectContainer edit
-form as the class available for choosing.
-
XXX Write about SQLObjectAuthSource.
Notes about transaction interoperability
Modified: z3/sqlos/trunk/__init__.py
==============================================================================
--- z3/sqlos/trunk/__init__.py (original)
+++ z3/sqlos/trunk/__init__.py Thu Jun 24 05:07:32 2004
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2004 sqlos Contributors. All rights reserved.
+# Copyright (c) 2004 Enfold Systems LLC. All rights reserved.
#
# This software is distributed under the terms of the Zope Public
# License (ZPL) v2.1. See COPYING.txt for more information.
@@ -34,37 +34,7 @@
classImplements(SQLObject, ISQLObject)
classImplements(SelectResults, ISelectResults)
-class ClassObjDescriptor:
-
- def __init__(self, name, module='sqlos'):
- self.name = name
- self.module = module
-
- def __get__(self, inst, cls=None):
- if inst is None:
- # being called for the class
- add_perm = '%s.Add%s' % (self.module, cls.__name__)
- checker = NamesChecker(new=add_perm,
- q='zope.View',
- select='zope.View')
- return checker
- try:
- return inst.__dict__[self.name]
- except KeyError:
- raise AttributeError, self.name
-
- def __set__(self, inst, value):
- inst.__dict__[self.name] = value
-
- def __delete__(self, inst):
- try:
- del inst.__dict__[self.name]
- except KeyError:
- raise AttributeError, self.name
-
-security_checker = ClassObjDescriptor('__Security_checker__')
-
-SQLObject.__Security_checker__ = security_checker
+from _sqlos import SQLOS
def caller(n=1):
"""Return the name of the calling function n levels up in the frame stack.
@@ -73,38 +43,6 @@
import inspect
return inspect.getouterframes(inspect.currentframe())[n][3]
-class SQLOS(SQLObject):
- """Subclass SQLObject to enable ``lazy updates`` by default,
- as well as adding knowledge to register ``dirty`` objects
- with SQLObjectTransactionManager so they get sync'd on transaction
- boundaries.
- """
-
- _lazyUpdate = True
-
- def _set_dirty(self, value):
- if value:
- self._connection._dm.register(self)
- self._dirty = value
-
- def _get_dirty(self):
- return self._dirty
-
- dirty = property(_get_dirty, _set_dirty)
-
- def get(cls, id, connection=None, selectResults=None):
- # While interacting with zope, we may end up having
- # objects in the cache that have a __parent__ set.
- # This may be confusing when expect to get a object
- # which has no __parent__ and thats not what you get.
- val = super(SQLOS, cls).get(id, connection=connection,
- selectResults=selectResults)
- if getattr(val, '__parent__', None) is not None:
- val.__parent__ = None
- val.__name__ = None
- return val
- get = classmethod(get)
-
def DateTimeConverter(value, db=None):
return repr(value.date().isoformat())
Added: z3/sqlos/trunk/_sqlos.py
==============================================================================
--- (empty file)
+++ z3/sqlos/trunk/_sqlos.py Thu Jun 24 05:07:32 2004
@@ -0,0 +1,62 @@
+##############################################################################
+#
+# Copyright (c) 2004 Enfold Systems LLC. All rights reserved.
+#
+# This software is distributed under the terms of the Zope Public
+# License (ZPL) v2.1. See COPYING.txt for more information.
+#
+##############################################################################
+"""
+$Id: __init__.py 5216 2004-06-21 18:33:07Z dreamcatcher $
+"""
+
+from zope.interface import implements, directlyProvides
+from sqlobject.main import SQLObject
+from sqlos.descriptor import ClassObjDescriptor
+from sqlos.connection import ConnectionDescriptor
+from sqlos.interfaces import ISQLObject, IISQLObject
+
+security_checker = ClassObjDescriptor('__Security_checker__')
+SQLObject.__Security_checker__ = security_checker
+
+class SQLOS(SQLObject):
+ """Subclass SQLObject to enable ``lazy updates`` by default,
+ as well as adding knowledge to register ``dirty`` objects
+ with SQLObjectTransactionManager so they get sync'd on transaction
+ boundaries.
+ """
+ implements(ISQLObject)
+
+ __Security_checker__ = security_checker
+ _connection = ConnectionDescriptor()
+ _lazyUpdate = True
+
+ def _set_dirty(self, value):
+ if value:
+ self._connection._dm.register(self)
+ self._dirty = value
+
+ def _get_dirty(self):
+ return self._dirty
+
+ dirty = property(_get_dirty, _set_dirty)
+
+ def get(cls, id, connection=None, selectResults=None):
+ # While interacting with zope, we may end up having
+ # objects in the cache that have a __parent__ set.
+ # This may be confusing when expect to get a object
+ # which has no __parent__ and thats not what you get.
+ val = super(SQLOS, cls).get(id, connection=connection,
+ selectResults=selectResults)
+ if getattr(val, '__parent__', None) is not None:
+ val.__parent__ = None
+ val.__name__ = None
+ return val
+ get = classmethod(get)
+
+ def setConnection(cls, connection):
+ if connection is not None:
+ cls._connection = connection
+
+ setConnection = classmethod(setConnection)
+
Modified: z3/sqlos/trunk/adapter.py
==============================================================================
--- z3/sqlos/trunk/adapter.py (original)
+++ z3/sqlos/trunk/adapter.py Thu Jun 24 05:07:32 2004
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2004 sqlos Contributors. All rights reserved.
+# Copyright (c) 2004 Enfold Systems LLC. All rights reserved.
#
# This software is distributed under the terms of the Zope Public
# License (ZPL) v2.1. See COPYING.txt for more information.
Modified: z3/sqlos/trunk/annotations.py
==============================================================================
--- z3/sqlos/trunk/annotations.py (original)
+++ z3/sqlos/trunk/annotations.py Thu Jun 24 05:07:32 2004
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2004 sqlos Contributors. All rights reserved.
+# Copyright (c) 2004 Enfold Systems LLC. All rights reserved.
#
# This software is distributed under the terms of the Zope Public
# License (ZPL) v2.1. See COPYING.txt for more information.
Modified: z3/sqlos/trunk/attributeannotations.py
==============================================================================
--- z3/sqlos/trunk/attributeannotations.py (original)
+++ z3/sqlos/trunk/attributeannotations.py Thu Jun 24 05:07:32 2004
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2004 sqlos Contributors. All rights reserved.
+# Copyright (c) 2004 Enfold Systems LLC. All rights reserved.
#
# This software is distributed under the terms of the Zope Public
# License (ZPL) v2.1. See COPYING.txt for more information.
Modified: z3/sqlos/trunk/auth/__init__.py
==============================================================================
--- z3/sqlos/trunk/auth/__init__.py (original)
+++ z3/sqlos/trunk/auth/__init__.py Thu Jun 24 05:07:32 2004
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2004 sqlos Contributors. All rights reserved.
+# Copyright (c) 2004 Enfold Systems LLC. All rights reserved.
#
# This software is distributed under the terms of the Zope Public
# License (ZPL) v2.1. See COPYING.txt for more information.
@@ -17,13 +17,14 @@
from zope.app import zapi
from zope.app.pluggableauth.interfaces import ILoginPasswordPrincipalSource
-from sqlos.interfaces.container import ISQLObjectContainerSchema
-from sqlos.interfaces.auth import ISQLObjectPrincipalSource
-from sqlos.factory import SQLObjectFactory
-
from zope.app.pluggableauth import SimplePrincipal
from zope.app.container.contained import Contained
from zope.exceptions import NotFoundError
+from zope.component import IFactory
+
+from sqlos.interfaces.container import ISQLObjectContainerSchema
+from sqlos.interfaces.auth import ISQLObjectPrincipalSource
+from sqlos.interfaces import IISQLObject
class SQLObjectPrincipalSource(Persistent, Contained):
"""A Principal Source for SQLObject-based data."""
@@ -40,11 +41,14 @@
def readPrincipals(self):
principals = []
- fs = zapi.getService(self, 'SQLObjectFactory')
- factories = fs.getFactories(self.classNames)
+ factories = filter(None,
+ [zapi.queryUtility(IISQLObject, name, context=self)
+ for name in self.classNames])
+ # XXX We are depending on the internal implementation of
+ # the <factory> directive here. Should be cleaned later
+ # when we extend the <factory> directive to take a mixin class.
+ factories = [factory for factory in factories]
for factory in factories:
- if not factory:
- continue
for user in factory.select():
userinfo = (user.username, user.password, user.fullname)
p = SimplePrincipal(*userinfo)
@@ -59,7 +63,6 @@
In this case the login equals the id.
"""
- id = id.split('\t')[2]
for p in self.readPrincipals():
if p.id == id:
return p
Modified: z3/sqlos/trunk/configure.zcml
==============================================================================
--- z3/sqlos/trunk/configure.zcml (original)
+++ z3/sqlos/trunk/configure.zcml Thu Jun 24 05:07:32 2004
@@ -10,7 +10,8 @@
<browser:menuItem menu="add_content"
for="zope.app.container.interfaces.IAdding"
- title="SQLObject Container" action="SQLObjectContainer"
+ title="SQLObject Container"
+ action="SQLObjectContainer"
description="A container for SQLObject instances"
/>
@@ -105,11 +106,6 @@
-->
- <classService:registerClass
- component="sqlos.annotations.Annotations"
- name="Annotations"
- />
-
<class class=".adapter.MySQLAdapter">
<require
permission="zope.Public"
Added: z3/sqlos/trunk/connection.py
==============================================================================
--- (empty file)
+++ z3/sqlos/trunk/connection.py Thu Jun 24 05:07:32 2004
@@ -0,0 +1,103 @@
+##############################################################################
+#
+# Copyright (c) 2004 Enfold Systems LLC. All rights reserved.
+#
+# This software is distributed under the terms of the Zope Public
+# License (ZPL) v2.1. See COPYING.txt for more information.
+#
+##############################################################################
+"""
+$Id: factory.py 5216 2004-06-21 18:33:07Z dreamcatcher $
+"""
+__metaclass__ = type
+
+from transaction import get_transaction
+from zope.interface import implements
+from zope.component import ComponentLookupError
+from zope.app import zapi
+from zope.app.rdb.interfaces import IZopeDatabaseAdapter
+from sqlos.interfaces import IZopeSQLConnection, IConnectionName
+from sqlos.adapter import PostgresAdapter
+import warnings
+
+class SQLObjectWarning(UserWarning): pass
+
+class ConnectionDescriptor:
+
+ def __init__(self, name=None):
+ self.name = name
+
+ def __get__(self, inst, cls=None):
+ context = inst is None and cls or inst
+ name = self.name
+ if name is None:
+ try:
+ ut = zapi.getUtility(IConnectionName)
+ except ComponentLookupError:
+ return self
+ if ut is None:
+ warnings.warn("Couldn't find ISQLConnectionName utility. "
+ "Please verify your setup.",
+ SQLObjectWarning, 2)
+ return
+ name = ut.name
+
+ try:
+ return getConnection(context, name)
+ except ComponentLookupError:
+ return self
+
+ def __set__(self, inst, value):
+ # Ignore, so we don't get overriden.
+ # We always use the connections from the
+ # global thread cache.
+ pass
+
+# Connection cache, one per thread, a-la Transaction.
+# This code was heavily based on ZODB.Transaction
+connCache = {}
+
+try:
+ import thread
+except:
+ def getConnection(context, name):
+ global connCache
+ if not connCache.get(name):
+ newconn = zapi.queryUtility(IZopeDatabaseAdapter, name,
+ default=None,
+ context=context)
+ if newconn is None:
+ warnings.warn("Couldn't find a rdb connection by the "
+ "name %s. Please verify your setup." % name,
+ SQLObjectWarning, 3)
+ connCache[key] = zapi.getAdapter(newconn(), IZopeSQLConnection)
+ return connCache[name]
+
+ def releaseConnection(name):
+ global connCache
+ if connCache.has_key(name):
+ connCache[name].close()
+ del connCache[name]
+else:
+ def getConnection(context, name):
+ global connCache
+ tid = thread.get_ident()
+ key = (tid, name)
+ if not connCache.get(key):
+ newconn = zapi.queryUtility(IZopeDatabaseAdapter, name,
+ default=None,
+ context=context)
+ if newconn is None:
+ warnings.warn("Couldn't find a rdb connection by the "
+ "name %s. Please verify your setup." % name,
+ SQLObjectWarning, 3)
+ connCache[key] = zapi.getAdapter(newconn(), IZopeSQLConnection)
+ return connCache[key]
+
+ def releaseConnection(name):
+ global connCache
+ tid = thread.get_ident()
+ key = (tid, name)
+ if connCache.has_key(key):
+ connCache[key].close()
+ del connCache[key]
Modified: z3/sqlos/trunk/container/__init__.py
==============================================================================
--- z3/sqlos/trunk/container/__init__.py (original)
+++ z3/sqlos/trunk/container/__init__.py Thu Jun 24 05:07:32 2004
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2004 sqlos Contributors. All rights reserved.
+# Copyright (c) 2004 Enfold Systems LLC. All rights reserved.
#
# This software is distributed under the terms of the Zope Public
# License (ZPL) v2.1. See COPYING.txt for more information.
@@ -136,12 +136,11 @@
container = zapi.getAdapter(self.context, IContainer)
klass = content.__class__
klass = removeAllProxies(klass)
- cs = zapi.getService(None, 'ClassService')
- className = cs.getClassNameByClass(klass)
+ className = klass.__name__
id = content.id
- name = className+'.'+str(id)
- name = container.__setitem__(name, content)
+ name = '%s.%s' % (className, id)
+ container[name] = content
return container[name]
def action(self, type_name=''):
@@ -159,9 +158,6 @@
self.request.response.redirect(url)
return
- cs = zapi.getService(None, 'ClassService')
- klass = cs.getClass(type_name)
-
content = zapi.createObject(self, type_name, CreateNewSQLObject)
publish(self.context, ObjectCreatedEvent(content))
Added: z3/sqlos/trunk/descriptor.py
==============================================================================
--- (empty file)
+++ z3/sqlos/trunk/descriptor.py Thu Jun 24 05:07:32 2004
@@ -0,0 +1,42 @@
+##############################################################################
+#
+# Copyright (c) 2004 Enfold Systems LLC. All rights reserved.
+#
+# This software is distributed under the terms of the Zope Public
+# License (ZPL) v2.1. See COPYING.txt for more information.
+#
+##############################################################################
+"""
+$Id: __init__.py 5216 2004-06-21 18:33:07Z dreamcatcher $
+"""
+__metaclass__ = type
+
+from zope.security.checker import NamesChecker
+
+class ClassObjDescriptor:
+
+ def __init__(self, name, module='sqlos'):
+ self.name = name
+ self.module = module
+
+ def __get__(self, inst, cls=None):
+ if inst is None:
+ # being called for the class
+ add_perm = '%s.Add%s' % (self.module, cls.__name__)
+ checker = NamesChecker(new=add_perm,
+ q='zope.View',
+ select='zope.View')
+ return checker
+ try:
+ return inst.__dict__[self.name]
+ except KeyError:
+ raise AttributeError, self.name
+
+ def __set__(self, inst, value):
+ inst.__dict__[self.name] = value
+
+ def __delete__(self, inst):
+ try:
+ del inst.__dict__[self.name]
+ except KeyError:
+ raise AttributeError, self.name
Modified: z3/sqlos/trunk/factory.py
==============================================================================
--- z3/sqlos/trunk/factory.py (original)
+++ z3/sqlos/trunk/factory.py Thu Jun 24 05:07:32 2004
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2004 sqlos Contributors. All rights reserved.
+# Copyright (c) 2004 Enfold Systems LLC. All rights reserved.
#
# This software is distributed under the terms of the Zope Public
# License (ZPL) v2.1. See COPYING.txt for more information.
@@ -10,24 +10,14 @@
$Id$
"""
-from transaction import get_transaction
-
+import warnings
from zope.interface import implements
from zope.app import zapi
-from zope.proxy import removeAllProxies
-from zope.app.rdb.interfaces import IZopeDatabaseAdapter
+from sqlos.interfaces import IISQLObject
from sqlos.interfaces.container import ISQLObjectContainerSchema, \
ISQLObjectFactory
-from sqlos.interfaces import IZopeSQLConnection
-
-class Dummy(object):
-
- id = 'stub'
- def select(self, clause=None):
- return [Dummy()]
- select = classmethod(select)
-
+from sqlos.connection import getConnection, connCache
class SQLObjectFactory(object):
@@ -37,19 +27,14 @@
connectionName = None
def getFactory(self, className):
- cs = zapi.getService('ClassService')
- klass = cs.getClass(className)
- conn = getConnection(None, self.connectionName)
- if klass._connection is not conn:
- klass._connection = conn
- # XXX Table creation cache, so we don't do a select
- # each time getFactory is called. Needs a smarter way
- # to do it later.
- cache = getattr(self, '_v_table_cache', tuple())
- if klass.__name__ not in cache:
- cache=cache+(klass.__name__,)
- self._v_table_cache = cache
- klass.createTable(ifNotExists=True)
+ warnings.warn('The SQLObjectFactory service is deprecated '
+ 'please update your code to use '
+ 'zapi.queryUtility(IISQLObject, name, context=context).',
+ DeprecationWarning, 2)
+ klass = zapi.queryUtility(IISQLObject, className,
+ default=None, context=self)
+ if klass is None:
+ raise KeyError, className
return klass
def getFactories(self, classNames=None):
@@ -62,45 +47,3 @@
factories.append(klass)
return tuple(factories)
-
-# Connection cache, one per thread, a-la Transaction.
-# This code was heavily based on ZODB.Transaction
-
-class ConnCache(dict): pass
-connCache = {}
-
-try:
- import thread
-except:
- def getConnection(context, name):
- global connCache
- if not connCache.get(name):
- newconn = zapi.getUtility(IZopeDatabaseAdapter, name,
- context=context)()
- connCache[key] = zapi.getAdapter(newconn, IZopeSQLConnection)
- return connCache[name]
-
- def releaseConnection(name):
- global connCache
- if connCache.has_key(name):
- connCache[name].close()
- del connCache[name]
-else:
- def getConnection(context, name):
- global connCache
- tid = thread.get_ident()
- key = (tid, name)
- if not connCache.get(key):
- newconn = zapi.getUtility(IZopeDatabaseAdapter, name,
- context=context)()
- connCache[key] = zapi.getAdapter(newconn,
- IZopeSQLConnection)
- return connCache[key]
-
- def releaseConnection(name):
- global connCache
- tid = thread.get_ident()
- key = (tid, name)
- if connCache.has_key(key):
- connCache[key].close()
- del connCache[key]
Modified: z3/sqlos/trunk/ftests/__init__.py
==============================================================================
--- z3/sqlos/trunk/ftests/__init__.py (original)
+++ z3/sqlos/trunk/ftests/__init__.py Thu Jun 24 05:07:32 2004
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2004 sqlos Contributors. All rights reserved.
+# Copyright (c) 2004 Enfold Systems LLC. All rights reserved.
#
# This software is distributed under the terms of the Zope Public
# License (ZPL) v2.1. See COPYING.txt for more information.
Modified: z3/sqlos/trunk/ftests/test_transaction.py
==============================================================================
--- z3/sqlos/trunk/ftests/test_transaction.py (original)
+++ z3/sqlos/trunk/ftests/test_transaction.py Thu Jun 24 05:07:32 2004
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2004 sqlos Contributors. All rights reserved.
+# Copyright (c) 2004 Enfold Systems LLC. All rights reserved.
#
# This software is distributed under the terms of the Zope Public
# License (ZPL) v2.1. See COPYING.txt for more information.
@@ -12,7 +12,7 @@
import unittest
from transaction import get_transaction
-from zope.testing.functional import BrowserTestCase
+from zope.app.tests.functional import BrowserTestCase
from zope.app import zapi
from zope.app.tests import setup
from zope.app.rdb import ZopeConnection
Modified: z3/sqlos/trunk/interfaces/__init__.py
==============================================================================
--- z3/sqlos/trunk/interfaces/__init__.py (original)
+++ z3/sqlos/trunk/interfaces/__init__.py Thu Jun 24 05:07:32 2004
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2004 sqlos Contributors. All rights reserved.
+# Copyright (c) 2004 Enfold Systems LLC. All rights reserved.
#
# This software is distributed under the terms of the Zope Public
# License (ZPL) v2.1. See COPYING.txt for more information.
@@ -12,11 +12,22 @@
from zope.schema import TextLine
from zope.interface import Interface, Attribute
from sqlobject import NoDefault
-from zope.component import getService, ComponentLookupError
+from zope.component import getService, ComponentLookupError, IFactory
from zope.schema.vocabulary import SimpleVocabulary
from zope.schema import Choice, List
from zope.app.annotation.interfaces import IAttributeAnnotatable
+class ISQLObjectFactory(IFactory):
+ """ A marker interface for SQLObject Factories """
+
+class IConnectionName(Interface):
+ """A marker interface for providing a connection name"""
+
+ name = TextLine(
+ title=u"Connection Name",
+ required=True
+ )
+
class ISQLSchema(Interface):
""" SQLObject-based schemas must declare 'id' or else it doesn't
@@ -159,85 +170,109 @@
Store annotations in the annotations table, keyed by
table_name/id on a IAttributeAnnotatable object.
"""
+class IReadSQLObjectClass(Interface):
-class ISQLObject(Interface):
+ q = Attribute('Query?')
- _idName = Attribute('Primary Key')
+ def get(id):
+ """Return object by the given primary key.
+ """
- q = Attribute('Query?')
+ def sqlrepr(value):
+ """ Shorthand for _connection.sqlrepr
+ """
+
+ def select(clause=None, clauseTables=None, orderBy=NoDefault,
+ groupBy=None, limit=None, lazyColumns=False,
+ reversed=False):
+ """ Do a select query and return the resulting objects.
+ """
+
+ def selectBy(**kw):
+ """ """
+
+class IWriteSQLObjectClass(Interface):
+
+
+ def delete(id):
+ """ Delete item by primary key id.
+ """
def addColumn(columnDef, changeSchema=False):
- """ Add a column to the class. If changeSchema is True, also add the
- column to the database. Also generates getter and setter methods on the
- class.
+ """ Add a column to the class. If changeSchema is True, also
+ add the column to the database. Also generates getter and
+ setter methods on the class.
"""
def addColumnsFromDatabase():
- """ Add to the class the columns that are defined on the database but
- not already present.
+ """ Add to the class the columns that are defined on the
+ database but not already present.
"""
def delColumn(column, changeSchema=False):
- """ Delete the given column from the class. 'column' may be either a string
- or a Col instance. If changeSchema is true, also remove the column from the
- database table.
+ """ Delete the given column from the class. 'column' may be
+ either a string or a Col instance. If changeSchema is true,
+ also remove the column from the database table.
"""
def addJoin(joinDef):
- """ Add a join definition to the class, optionally removing or adding items
- as requested.
+ """ Add a join definition to the class, optionally removing or
+ adding items as requested.
"""
def delJoin(joinDef):
- """ Remove a join definition from the class, optionally removing or adding
- items as requested.
+ """ Remove a join definition from the class, optionally
+ removing or adding items as requested.
"""
- def set(**kw):
- """ Used to update multiple values at once, potentially with one SQL
- statement if possible.
- """
-
- def select(clause=None, clauseTables=None, orderBy=NoDefault,
- groupBy=None, limit=None, lazyColumns=False,
- reversed=False):
- """ Do a select query and return the resulting objects. """
-
- def selectBy(**kw):
- """ """
-
def dropTable(ifExists=False, dropJoinTables=True):
- """ Drop the table. If the 'ifExists' parameter was passed, check if
- the table exists before trying to delete. If 'dropJoinTables' is True,
- drop the join tables associated.
+ """ Drop the table. If the 'ifExists' parameter was passed,
+ check if the table exists before trying to delete. If
+ 'dropJoinTables' is True, drop the join tables associated.
"""
def createTable(ifNotExists=False, createJoinTables=True):
- """ Create the table. If the 'ifNotExists' parameter was passed, check if
- the table exists before trying to create. If 'createJoinTables' is True,
- create the join tables associated.
+ """ Create the table. If the 'ifNotExists' parameter was
+ passed, check if the table exists before trying to create. If
+ 'createJoinTables' is True, create the join tables associated.
"""
def createJoinTables(ifNotExists=False):
- """ Create the associated join tables. If the 'ifNotExists' parameter is True,
- check if the tables doesn't already exist first.
+ """ Create the associated join tables. If the 'ifNotExists'
+ parameter is True, check if the tables doesn't already exist
+ first.
"""
def dropJoinTables(ifExists=False):
- """ Drop the associated join tables. If the 'ifExists' parameter is True,
- then first check if the tables exist before trying to delete.
+ """ Drop the associated join tables. If the 'ifExists'
+ parameter is True, then first check if the tables exist before
+ trying to delete.
"""
def clearTable():
- """ Clear the table. """
+ """ Clear the table.
+ """
+
+class IISQLObject(IReadSQLObjectClass, IWriteSQLObjectClass):
+ """Class methods for SQLObject classes."""
+
+class ISQLObject(Interface):
+
+ _idName = Attribute('Primary Key')
+
+
+ def set(**kw):
+ """ Used to update multiple values at once, potentially with
+ one SQL statement if possible.
+ """
def destroySelf():
- """ Kill this object and remove it from all caches. Also removes the
- row associated with this object from the table. """
+ """ Kill this object and remove it from all caches. Also
+ removes the row associated with this object from the table.
+ """
def syncUpdate():
''' '''
-
class ICacheSet(Interface):
def get(id, cls):
Modified: z3/sqlos/trunk/interfaces/auth.py
==============================================================================
--- z3/sqlos/trunk/interfaces/auth.py (original)
+++ z3/sqlos/trunk/interfaces/auth.py Thu Jun 24 05:07:32 2004
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2004 sqlos Contributors. All rights reserved.
+# Copyright (c) 2004 Enfold Systems LLC. All rights reserved.
#
# This software is distributed under the terms of the Zope Public
# License (ZPL) v2.1. See COPYING.txt for more information.
Modified: z3/sqlos/trunk/interfaces/container.py
==============================================================================
--- z3/sqlos/trunk/interfaces/container.py (original)
+++ z3/sqlos/trunk/interfaces/container.py Thu Jun 24 05:07:32 2004
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2004 sqlos Contributors. All rights reserved.
+# Copyright (c) 2004 Enfold Systems LLC. All rights reserved.
#
# This software is distributed under the terms of the Zope Public
# License (ZPL) v2.1. See COPYING.txt for more information.
Modified: z3/sqlos/trunk/interfaces/services.py
==============================================================================
--- z3/sqlos/trunk/interfaces/services.py (original)
+++ z3/sqlos/trunk/interfaces/services.py Thu Jun 24 05:07:32 2004
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2004 sqlos Contributors. All rights reserved.
+# Copyright (c) 2004 Enfold Systems LLC. All rights reserved.
#
# This software is distributed under the terms of the Zope Public
# License (ZPL) v2.1. See COPYING.txt for more information.
Modified: z3/sqlos/trunk/meta.zcml
==============================================================================
--- z3/sqlos/trunk/meta.zcml (original)
+++ z3/sqlos/trunk/meta.zcml Thu Jun 24 05:07:32 2004
@@ -1,5 +1,6 @@
<configure xmlns='http://namespaces.zope.org/zope'
- i18n_domain="sqlobjectsupport">
+ xmlns:meta="http://namespaces.zope.org/meta"
+ i18n_domain="sqlos">
<serviceType id='ClassService'
interface='.interfaces.services.IClassService' />
@@ -7,12 +8,28 @@
permission='zope.ManageContent'
component='.services.classservice.service' />
- <directives namespace="http://namespaces.zope.org/class">
+ <meta:directives namespace="http://namespaces.zope.org/class">
<directive name="registerClass" attributes="component name"
handler=".services.metaconfigure.classhandler" />
- </directives>
+ </meta:directives>
+
+ <meta:directives namespace="http://namespaces.sqlobject.org/sqlos">
+
+ <meta:directive
+ name="factory"
+ schema=".metadirectives.IFactoryDirective"
+ handler=".metaconfigure.factory"
+ />
+
+ <meta:directive
+ name="connectionName"
+ schema=".metadirectives.IConnectionName"
+ handler=".metaconfigure.connectionName"
+ />
+
+ </meta:directives>
<include package=".services" file="sqlfactoryservice.zcml" />
Added: z3/sqlos/trunk/metaconfigure.py
==============================================================================
--- (empty file)
+++ z3/sqlos/trunk/metaconfigure.py Thu Jun 24 05:07:32 2004
@@ -0,0 +1,69 @@
+##############################################################################
+#
+# Copyright (c) 2004 Enfold Systems LLC. All rights reserved.
+#
+# This software is distributed under the terms of the Zope Public
+# License (ZPL) v2.1. See COPYING.txt for more information.
+#
+##############################################################################
+"""
+$Id: __init__.py 5216 2004-06-21 18:33:07Z dreamcatcher $
+"""
+
+from zope.interface.verify import verifyClass
+from zope.interface import directlyProvides, implements
+from sqlos.interfaces import ISQLObjectFactory, IISQLObject
+from sqlos.interfaces import IConnectionName
+from zope.app.component.metaconfigure import factory, utility
+from zope.app.component.metaconfigure import PublicPermission, proxify
+from zope.security.checker import getCheckerForInstancesOf
+from zope.component.factory import Factory
+
+class SQLObjectFactory(Factory):
+ implements(ISQLObjectFactory)
+
+def handler(_context, component, id, title=None, description=None):
+
+ component = _context.resolve(component)
+
+ factoryObj = SQLObjectFactory(component, title, description)
+
+ if title is not None:
+ factoryObj.title = title
+
+ if description is not None:
+ factoryObj.description = description
+
+ utility(_context, ISQLObjectFactory, factoryObj,
+ permission=PublicPermission, name=id)
+
+ if not IISQLObject.providedBy(component):
+ if verifyClass(IISQLObject, component, tentative=1):
+ directlyProvides(component, IISQLObject)
+
+ # XXX We do the proxyfication ourselves so that it gets
+ # the right proxy. See comment below.
+ checker = getCheckerForInstancesOf(component)
+ component = proxify(component, checker)
+
+ # XXX We pass permission=None here so the component doesn't get
+ # proxified by the utility handler. If we did pass a permission
+ # in, it would create a checker for the provided interfaces, thus
+ # disregarding the checker created by the <content>
+ # directive. IMHO, the utility handler needs to be fixed to lookup
+ # a checker using getCheckerForInstancesOf
+ utility(_context, IISQLObject, component,
+ permission=None, name=id)
+
+class ConnectionName:
+ """A connection name utility"""
+
+ implements(IConnectionName)
+
+ def __init__(self, name):
+ self.name = name
+
+def connectionName(_context, name):
+ component = ConnectionName(name)
+ utility(_context, IConnectionName, component,
+ permission=PublicPermission, name='')
Added: z3/sqlos/trunk/metadirectives.py
==============================================================================
--- (empty file)
+++ z3/sqlos/trunk/metadirectives.py Thu Jun 24 05:07:32 2004
@@ -0,0 +1,51 @@
+##############################################################################
+#
+# Copyright (c) 2004 Enfold Systems LLC. All rights reserved.
+#
+# This software is distributed under the terms of the Zope Public
+# License (ZPL) v2.1. See COPYING.txt for more information.
+#
+##############################################################################
+"""
+$Id: __init__.py 5216 2004-06-21 18:33:07Z dreamcatcher $
+"""
+
+from zope.interface import Interface
+from zope.configuration.fields import GlobalObject, MessageID
+from zope.schema import TextLine
+
+class IConnectionName(Interface):
+
+ name = TextLine(
+ title=u"Connection Name",
+ required=True
+ )
+
+class IFactoryDirective(Interface):
+ """
+ Define a factory
+ """
+
+ component = GlobalObject(
+ title=u"Component to be used",
+ required=True
+ )
+
+ id = TextLine(
+ title=u"ID",
+ required=False
+ )
+
+ title = MessageID(
+ title=u"Title",
+ description=u"""
+ text suitable for use in the 'add content' menu of a
+ management interface""",
+ required=False
+ )
+
+ description = MessageID(
+ title=u"Description",
+ description=u"Longer narrative description of what this factory does",
+ required=False
+ )
Modified: z3/sqlos/trunk/services/__init__.py
==============================================================================
--- z3/sqlos/trunk/services/__init__.py (original)
+++ z3/sqlos/trunk/services/__init__.py Thu Jun 24 05:07:32 2004
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2004 sqlos Contributors. All rights reserved.
+# Copyright (c) 2004 Enfold Systems LLC. All rights reserved.
#
# This software is distributed under the terms of the Zope Public
# License (ZPL) v2.1. See COPYING.txt for more information.
Modified: z3/sqlos/trunk/services/classservice.py
==============================================================================
--- z3/sqlos/trunk/services/classservice.py (original)
+++ z3/sqlos/trunk/services/classservice.py Thu Jun 24 05:07:32 2004
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2004 sqlos Contributors. All rights reserved.
+# Copyright (c) 2004 Enfold Systems LLC. All rights reserved.
#
# This software is distributed under the terms of the Zope Public
# License (ZPL) v2.1. See COPYING.txt for more information.
Modified: z3/sqlos/trunk/services/metaconfigure.py
==============================================================================
--- z3/sqlos/trunk/services/metaconfigure.py (original)
+++ z3/sqlos/trunk/services/metaconfigure.py Thu Jun 24 05:07:32 2004
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2004 sqlos Contributors. All rights reserved.
+# Copyright (c) 2004 Enfold Systems LLC. All rights reserved.
#
# This software is distributed under the terms of the Zope Public
# License (ZPL) v2.1. See COPYING.txt for more information.
@@ -9,17 +9,17 @@
"""
$Id: adapter.py 5212 2004-06-21 18:09:05Z philikon $
"""
+import warnings
from zope.component import getService
+from sqlos.metaconfigure import handler
def classhandler(_context, component, name=''):
- component = _context.resolve(component)
+ warnings.warn("registerClass is deprecated. Please use "
+ "the factory directive from the "
+ "http://namespaces.sqlobject.org/sqlos namespace "
+ "instead, which replaces the <factory> subdirective "
+ "of content to register specific SQLObject factories. ",
+ DeprecationWarning, 1)
- return _context.action(
- discriminator = ('registerClass', component),
- callable = registerClass,
- args = (component, name),
- )
-
-def registerClass(component, name):
- getService('ClassService').registerClass(component, name)
+ return handler(_context, component, name)
Modified: z3/sqlos/trunk/services/servicenames.py
==============================================================================
--- z3/sqlos/trunk/services/servicenames.py (original)
+++ z3/sqlos/trunk/services/servicenames.py Thu Jun 24 05:07:32 2004
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2004 sqlos Contributors. All rights reserved.
+# Copyright (c) 2004 Enfold Systems LLC. All rights reserved.
#
# This software is distributed under the terms of the Zope Public
# License (ZPL) v2.1. See COPYING.txt for more information.
Modified: z3/sqlos/trunk/services/sqlfactoryservice.py
==============================================================================
--- z3/sqlos/trunk/services/sqlfactoryservice.py (original)
+++ z3/sqlos/trunk/services/sqlfactoryservice.py Thu Jun 24 05:07:32 2004
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2004 sqlos Contributors. All rights reserved.
+# Copyright (c) 2004 Enfold Systems LLC. All rights reserved.
#
# This software is distributed under the terms of the Zope Public
# License (ZPL) v2.1. See COPYING.txt for more information.
Modified: z3/sqlos/trunk/transaction/__init__.py
==============================================================================
--- z3/sqlos/trunk/transaction/__init__.py (original)
+++ z3/sqlos/trunk/transaction/__init__.py Thu Jun 24 05:07:32 2004
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2004 sqlos Contributors. All rights reserved.
+# Copyright (c) 2004 Enfold Systems LLC. All rights reserved.
#
# This software is distributed under the terms of the Zope Public
# License (ZPL) v2.1. See COPYING.txt for more information.
Modified: z3/sqlos/trunk/utils.py
==============================================================================
--- z3/sqlos/trunk/utils.py (original)
+++ z3/sqlos/trunk/utils.py Thu Jun 24 05:07:32 2004
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2004 sqlos Contributors. All rights reserved.
+# Copyright (c) 2004 Enfold Systems LLC. All rights reserved.
#
# This software is distributed under the terms of the Zope Public
# License (ZPL) v2.1. See COPYING.txt for more information.
Modified: z3/sqlos/trunk/vocab.py
==============================================================================
--- z3/sqlos/trunk/vocab.py (original)
+++ z3/sqlos/trunk/vocab.py Thu Jun 24 05:07:32 2004
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2004 sqlos Contributors. All rights reserved.
+# Copyright (c) 2004 Enfold Systems LLC. All rights reserved.
#
# This software is distributed under the terms of the Zope Public
# License (ZPL) v2.1. See COPYING.txt for more information.
More information about the z3-checkins
mailing list