[z3-checkins] r36315 - in z3/sqlos/trunk/src/sqlos: . container ftests interfaces testing
kobold at codespeak.net
kobold at codespeak.net
Mon Jan 8 20:48:55 CET 2007
Author: kobold
Date: Mon Jan 8 20:48:54 2007
New Revision: 36315
Removed:
z3/sqlos/trunk/src/sqlos/interfaces/auth.py
Modified:
z3/sqlos/trunk/src/sqlos/__init__.py
z3/sqlos/trunk/src/sqlos/container/__init__.py
z3/sqlos/trunk/src/sqlos/container/isolated.py
z3/sqlos/trunk/src/sqlos/ftests/isolated_containers.txt
z3/sqlos/trunk/src/sqlos/interfaces/__init__.py
z3/sqlos/trunk/src/sqlos/interfaces/container.py
z3/sqlos/trunk/src/sqlos/testing/sampleperson.py
z3/sqlos/trunk/src/sqlos/zsqlobject.py
Log:
New API, with deprecation warnings for the old names: only isolated containeres are affected.
Modified: z3/sqlos/trunk/src/sqlos/__init__.py
==============================================================================
--- z3/sqlos/trunk/src/sqlos/__init__.py (original)
+++ z3/sqlos/trunk/src/sqlos/__init__.py Mon Jan 8 20:48:54 2007
@@ -13,4 +13,5 @@
from zope.deprecation import deprecated
from sqlos.zsqlobject import SQLOS
-deprecated('SQLOS', 'sqlos.SQLOS is deprecated and will go away in next release')
+deprecated('SQLOS', 'sqlos.SQLOS is deprecated and will go away in next release; '
+'use sqlos.zsqlobject.SQLOS instead.')
Modified: z3/sqlos/trunk/src/sqlos/container/__init__.py
==============================================================================
--- z3/sqlos/trunk/src/sqlos/container/__init__.py (original)
+++ z3/sqlos/trunk/src/sqlos/container/__init__.py Mon Jan 8 20:48:54 2007
@@ -11,6 +11,13 @@
$Id$
"""
+from zope.deprecation import deprecated
+
from standard import contained, SQLObjectNameChooser, SQLObjectContainer
-from isolated import SQLIsolatedContainer
+from isolated import SQLObjectIsolatedContainer
from mono import SQLObjectMonoNameChooser, SQLObjectMonoContainer
+
+SQLIsolatedContainer = SQLObjectIsolatedContainer
+deprecated('SQLIsolatedContainer', 'sqlos.container.SQLIsolatedContainer is deprecated '
+'and will go away in next release; use sqlos.container.SQLObjectIsolatedContainer '
+'instead.')
Modified: z3/sqlos/trunk/src/sqlos/container/isolated.py
==============================================================================
--- z3/sqlos/trunk/src/sqlos/container/isolated.py (original)
+++ z3/sqlos/trunk/src/sqlos/container/isolated.py Mon Jan 8 20:48:54 2007
@@ -17,12 +17,12 @@
from sqlos.container.standard import contained, SQLObjectContainer
from sqlos.interfaces import ISQLObjectIsolated
-from sqlos.interfaces.container import IIsolatedSQLContainer
+from sqlos.interfaces.container import ISQLObjectIsolatedContainer
-class SQLIsolatedContainer(SQLObjectContainer):
+class SQLObjectIsolatedContainer(SQLObjectContainer):
- implements(IIsolatedSQLContainer)
+ implements(ISQLObjectIsolatedContainer)
_container_id = None
@@ -75,7 +75,7 @@
yield (name, contained(obj, parent=self, name=name))
def __getitem__(self, name):
- obj = super(SQLIsolatedContainer, self).__getitem__(name)
+ obj = super(SQLObjectIsolatedContainer, self).__getitem__(name)
if hasattr(obj, 'domains'):
if self.container_id in obj.domains:
return contained(obj, parent=self, name=name)
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 Mon Jan 8 20:48:54 2007
@@ -1,11 +1,11 @@
First let's get a container for sqlos objects:
>>> from sqlos.testing import sampleperson
- >>> from sqlos.interfaces.container import IIsolatedSQLContainer
+ >>> from sqlos.interfaces.container import ISQLObjectIsolatedContainer
>>> from zope.interface.verify import verifyObject
>>> container = sampleperson.SampleIsolatedPersonContainer()
- >>> verifyObject(IIsolatedSQLContainer, container)
+ >>> verifyObject(ISQLObjectIsolatedContainer, container)
True
We are not in the business of letting errors pass silently, so looking inside
Modified: z3/sqlos/trunk/src/sqlos/interfaces/__init__.py
==============================================================================
--- z3/sqlos/trunk/src/sqlos/interfaces/__init__.py (original)
+++ z3/sqlos/trunk/src/sqlos/interfaces/__init__.py Mon Jan 8 20:48:54 2007
@@ -23,235 +23,208 @@
from sqlobject.main import SQLObject, SelectResults
from sqlobject.sqlbuilder import SQLObjectTable
+
class IConnectionName(Interface):
"""A marker interface for providing a connection name"""
name = TextLine(
title=u"Connection Name",
- required=True
+ required=True,
)
+
class ISQLSchema(Interface):
- """ SQLObject-based schemas must declare 'id' or else it doesn't
- get security set """
+ """Base interface for SQLObject-based objects"""
id = Attribute('Id')
+
class IDBConnection(Interface):
- """ SQLObject DBConnection interface """
+ """SQLObject DBConnection interface"""
- name = Attribute("The object name, used as key for caching connections")
+ name = Attribute("The object name, used as key for caching connections")
debug = Attribute("Print debug trace messages")
cache = Attribute("A ResultSet cache object")
style = Attribute("A style object. Used for controlling the naming style.")
+
class IDBAPI(IDBConnection):
+ """DBAPI Interface"""
def _runWithConnection(meth, *args):
- """ Runs a method with a connection from the pool """
+ """Runs a method with a connection from the pool"""
def getConnection():
- """ Return a connection from the pool """
+ """Return a connection from the pool"""
def releaseConnection(conn):
- """ Return a connection back to the pool """
+ """Return a connection back to the pool"""
def query(s):
- """ Run a query string against the database """
+ """Run a query string against the database"""
def queryAll(s):
- """ Run a query string against the database and return all results """
+ """Run a query string against the database and return all results"""
def queryOne(s):
- """ Run a query string against the database and return one row """
+ """Run a query string against the database and return one row"""
def transaction():
- """ Return a transaction object for this connection """
+ """Return a transaction object for this connection"""
def queryInsertID(soInstance, id, names, values):
- """ Insert a row into the database and return the generated id """
+ """Insert a row into the database and return the generated id"""
def iterSelect(select):
- """ """
+ """Iter on a select"""
def queryForSelect(select):
- """ """
+ """Query for a select"""
def createTable(soClass):
- """ Create a table for the given SQLObject class """
+ """Create a table for the given SQLObject class"""
def createColumns(soClass):
- """ Return a query needed to create the columns for the given SO class """
+ """Return a query needed to create the columns for the given SO class"""
def dropTable(tableName):
- """ Drop the given table """
+ """Drop the given table"""
def clearTable(tableName):
- """ Clear the given table """
-
- ### Private methods
+ """Clear the given table"""
def _SO_update(so, values):
- """ """
+ """"""
def _SO_selectOne(so, columnNames):
- """ """
+ """"""
def _SO_selectOneAlt(cls, columnNames, column, value):
- """ """
+ """"""
def _SO_delete(so):
- """ """
+ """"""
def _SO_selectJoin(soClass, column, value):
- """ """
+ """"""
def _SO_intermediateJoin(table, getColumn, joinColumn, value):
- """ """
+ """"""
def _SO_intermediateDelete(table, firstColumn, firstValue,
secondColumn, secondValue):
- """ """
+ """"""
def _SO_intermediateInsert(table, firstColumn, firstValue,
secondColumn, secondValue):
- """ """
+ """"""
def _SO_columnClause(soClass, kw):
- """ """
+ """"""
+
class ISQLConnection(IDBAPI):
def makeConnection():
- """ Return a newly-built connection instance using args passed
- on __init__ """
+ """Return a newly-built connection instance"""
def getConnection():
- """ Get a connection from the pool """
+ """Get a connection from the pool"""
def _runWithConnection(meth, *args):
- """ Run a method with the give args and a connection """
+ """Run a method with the give args and a connection"""
def createColumn(soClass, column):
- """ Create a column """
+ """Create a column"""
def createIDColumn(soClass):
- """ Return the string used to create the ID column """
+ """Return the string used to create the ID column"""
def joinSQLType(join):
- """ Return the string to be used in join queries """
+ """Return the string to be used in join queries"""
def tableExists(tableName):
- """ Return if the given table exists or not in the database """
+ """Return if the given table exists or not in the database"""
def addColumn(tableName, column):
- """ Add the given column to the database """
+ """Add the given column to the database"""
def delColumn(tableName, column):
- """ Remove the given column from the database """
+ """Remove the given column from the database"""
def columnsFromSchema(tableName, soClass):
- """ Return a set of columns from the table schema """
+ """Return a set of columns from the table schema"""
def guessClass(t):
- """ Returns a column class and a dict to be used on column
- initialization """
+ """Returns a column class and a dict to be used on column initialization"""
+
class IZopeSQLConnection(ISQLConnection):
- """ """
+ """Marker for Zope relational database connections"""
-class ISQLAttributeAnnotatable(IAttributeAnnotatable):
- """
- Store annotations in the annotations table, keyed by
- table_name/id on a IAttributeAnnotatable object.
- """
class IReadSQLObjectClass(Interface):
- q = Attribute('Query?')
+ q = Attribute('Query')
def get(id):
- """Return object by the given primary key.
- """
+ """Return object by the given primary key."""
def sqlrepr(value):
- """ Shorthand for _connection.sqlrepr
- """
+ """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.
- """
+ """Do a select query and return the resulting objects."""
def selectBy(**kw):
- """ """
+ """Do a select query filtering by the specified keywords"""
+
class IWriteSQLObjectClass(Interface):
def delete(id):
- """ Delete item by primary key id.
- """
-
- # XXX these moved to sqlmeta in sqlobject 0.7, should we define another
- # interface?
- #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.
- # """
- #
- #def addColumnsFromDatabase():
- # """ 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.
- # """
- #
- #def addJoin(joinDef):
- # """ 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.
- # """
+ """Delete item by primary key id."""
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 IISQLObjectIsolated(IISQLObject):
"""Support for using this class in isolated containers.
@@ -268,34 +241,30 @@
similar to select()
"""
-class ISQLObject(IContained):
-
- # XXX - _idName moved to sqlmeta
- #_idName = Attribute('Primary Key')
+class ISQLObject(IContained):
def set(**kw):
- """ Used to update multiple values at once, potentially with
- one SQL statement if possible.
+ """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():
- """ Submit changes to the database
- """
+ """Submit changes to the database"""
def sync():
- """ If there are pending changes, submit them to the database,
- and after that re-sync the object with the database.
+ """If there are pending changes, submit them to the database, and after
+ that re-sync the object with the database.
"""
def expire():
- """ Expire the object, clearing the cache for the current connection.
- """
+ """Expire the object, clearing the cache for the current connection."""
+
class ISQLObjectIsolated(ISQLObject):
@@ -305,44 +274,44 @@
class ICacheSet(Interface):
def get(id, cls):
- """ Get object 'id' from cache key 'cls.__name__' """
+ """Get object 'id' from cache key 'cls.__name__'"""
def put(id, cls):
- """ Set a cache value using 'id' and 'cls.__name__' as keys """
+ """Set a cache value using 'id' and 'cls.__name__' as keys"""
def finishPut(cls):
- """ """
+ """"""
def created(id, cls, obj):
- """ """
+ """"""
def purge(id, cls):
- """ Purge an object from the cache """
+ """Purge an object from the cache"""
def clear(cls=None):
- """ Clear the cache if cls is None, else clear only the given
- class cache """
+ """Clear the cache if cls is None, else clear only the given class cache"""
+
class ISelectResults(Interface):
def __getitem__(item):
- """ List Emulation """
+ """List Emulation"""
def __iter__():
- """ List Emulation """
+ """List Emulation"""
def __len__():
- """ List emulation """
+ """List emulation"""
+
class IIterator(Interface):
def __iter__():
- """ Iterator """
+ """Iterator"""
def next():
- """ Iterator """
+ """Iterator"""
-# XXX: Why do we need these????
defineChecker(SQLObjectTable, NoProxy)
@@ -353,5 +322,3 @@
classImplements(_sybase.builder(), ISQLConnection)
classImplements(SQLObject, ISQLObject)
classImplements(SelectResults, ISelectResults)
-
-
Deleted: /z3/sqlos/trunk/src/sqlos/interfaces/auth.py
==============================================================================
--- /z3/sqlos/trunk/src/sqlos/interfaces/auth.py Mon Jan 8 20:48:54 2007
+++ (empty file)
@@ -1,51 +0,0 @@
-##############################################################################
-#
-# 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: adapter.py 5212 2004-06-21 18:09:05Z philikon $
-"""
-
-from zope.interface import Interface
-from zope.schema import TextLine, Password
-from zope.app.container.constraints import ItemTypePrecondition
-from zope.app.pluggableauth.interfaces import IPrincipalSource
-
-from sqlos.interfaces import ISQLSchema
-from sqlos.interfaces.container import ISQLObjectContainer
-
-class IPrincipalInfo(ISQLSchema):
-
- fullname = TextLine(title=u'Full Name',
- required=True)
-
- username = TextLine(title=u'Username',
- description=u'The user login name',
- required=True,
- )
-
-class IPrincipalPassword(Interface):
-
- password = Password(title=u'Password',
- required=True)
-
-class IPrincipal(IPrincipalInfo, IPrincipalPassword):
- """A SQL-Based Principal, for use with ISQLObjectPrincipalSource"""
-
-class ISQLObjectPrincipalSource(IPrincipalSource):
- """Describes SQLObject-based principal sources."""
-
- def readPrincipals():
- """ """
-
-class IPrincipalContainer(ISQLObjectContainer):
- """A container for principals"""
-
- def __setitem__(name, obj):
- """Add a new object"""
-
- __setitem__.precondition = ItemTypePrecondition(IPrincipal)
Modified: z3/sqlos/trunk/src/sqlos/interfaces/container.py
==============================================================================
--- z3/sqlos/trunk/src/sqlos/interfaces/container.py (original)
+++ z3/sqlos/trunk/src/sqlos/interfaces/container.py Mon Jan 8 20:48:54 2007
@@ -9,7 +9,10 @@
"""
$Id: adapter.py 5212 2004-06-21 18:09:05Z philikon $
"""
+
from zope.interface import Attribute
+from zope.deprecation import deprecated
+
from zope.app.container.constraints import ItemTypePrecondition
from zope.annotation.interfaces import IAttributeAnnotatable
from zope.app.container.interfaces import IContainerNamesContainer
@@ -17,24 +20,32 @@
class ISQLObjectReadContainer(IReadContainer, IAttributeAnnotatable):
- """An SQLObject Container """
+ """Read interface for SQLObject containers"""
-class ISQLObjectContainer(IContainer, IContainerNamesContainer,
- IAttributeAnnotatable):
- """An SQLObject Container """
+class ISQLObjectContainer(IContainer, IContainerNamesContainer, IAttributeAnnotatable):
+ """A SQLObject container"""
def __setitem__(name, obj):
"""Add a new object"""
-
__setitem__.precondition = ItemTypePrecondition()
+ def __delitem__(name):
+ """Remove an object"""
+
-class IIsolatedSQLContainer(ISQLObjectContainer):
- # TODO Attribute -> zope.schema.* - jinty
- container_id = Attribute("The id of the containers, this is a filter on the"
- "database table.")
+class ISQLObjectIsolatedContainer(ISQLObjectContainer):
+ """An isolated SQLObject container"""
+
+ container_id = Attribute(u'The id of the containers, this is a filter on '
+ 'the database table.')
class ISQLObjectMonoContainer(ISQLObjectContainer):
- """An SQLObject Container """
+ """A mono-type SQLObject container"""
+
+
+IIsolatedSQLContainer = ISQLObjectIsolatedContainer
+deprecated('IIsolatedSQLContainer', 'sqlos.interfaces.container.IIsolatedSQLContainer '
+'is deprecated and will go away in next release; use sqlos.interfaces.container.'
+'ISQLObjectIsolatedContainer instead.')
Modified: z3/sqlos/trunk/src/sqlos/testing/sampleperson.py
==============================================================================
--- z3/sqlos/trunk/src/sqlos/testing/sampleperson.py (original)
+++ z3/sqlos/trunk/src/sqlos/testing/sampleperson.py Mon Jan 8 20:48:54 2007
@@ -7,7 +7,7 @@
from sqlos.zsqlobject import SQLOS
from sqlos.interfaces import ISQLSchema, IISQLObjectIsolated, ISQLObjectIsolated
from sqlos.interfaces.container import ISQLObjectContainer
-from sqlos.container import SQLObjectContainer, SQLIsolatedContainer, SQLObjectMonoContainer
+from sqlos.container import SQLObjectContainer, SQLObjectIsolatedContainer, SQLObjectMonoContainer
def createTestingTablesSubscriber(obj):
# An event subscriber that can be used to create the testing tables
@@ -113,7 +113,7 @@
selectByDomain = classmethod(selectByDomain)
-class SampleIsolatedPersonContainer(SQLIsolatedContainer):
+class SampleIsolatedPersonContainer(SQLObjectIsolatedContainer):
implements(IPersonContainer)
Modified: z3/sqlos/trunk/src/sqlos/zsqlobject.py
==============================================================================
--- z3/sqlos/trunk/src/sqlos/zsqlobject.py (original)
+++ z3/sqlos/trunk/src/sqlos/zsqlobject.py Mon Jan 8 20:48:54 2007
@@ -17,14 +17,16 @@
from sqlos.connection import ConnectionDescriptor
from sqlos.interfaces import ISQLObject
-from sqlos import _transaction
+from sqlos._transaction import dirty_object_registry
def syncUpdateAll():
"""Calls syncUpdate on all dirty SQLOS objects, sending all SQL to the DB.
>>> syncUpdateAll()
+
"""
- _transaction.dirty_object_registry.syncUpdateAll()
+
+ dirty_object_registry.syncUpdateAll()
class SQLOS(SQLObject, Contained):
@@ -48,8 +50,11 @@
And finally call tearDown and cleanup:
>>> testdb.tearDown()
+
"""
+
implements(ISQLObject)
+
_connection = ConnectionDescriptor()
class sqlmeta:
@@ -57,12 +62,10 @@
def _set_dirty(self, value):
if value:
- _transaction.dirty_object_registry.register(self)
+ dirty_object_registry.register(self)
self._dirty = value
-
def _get_dirty(self):
return self._dirty
-
dirty = property(_get_dirty, _set_dirty)
def get(self, id, connection=None, selectResults=None):
@@ -72,7 +75,7 @@
# which has no __parent__ and thats not what you get.
try:
val = super(SQLOS, self).get(id, connection=connection,
- selectResults=selectResults)
+ selectResults=selectResults)
except ValueError:
raise AttributeError, id
if getattr(val, '__parent__', None) is not None:
@@ -87,5 +90,4 @@
def setConnection(self, connection):
if connection is not None:
self._connection = connection
-
setConnection = classmethod(setConnection)
More information about the z3-checkins
mailing list