[Checkins] SVN: z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/base.py -
introducing new 'model_provider' parameter
Andreas Jung
andreas at andreas-jung.com
Mon Apr 23 09:33:49 EDT 2007
Log message for revision 74677:
- introducing new 'model_provider' parameter
- deprecating 'model' parameter
Changed:
U z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/base.py
-=-
Modified: z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/base.py
===================================================================
--- z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/base.py 2007-04-23 13:20:29 UTC (rev 74676)
+++ z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/base.py 2007-04-23 13:33:48 UTC (rev 74677)
@@ -6,6 +6,7 @@
# and ZOPYX Ltd. & Co. KG, Tuebingen, Germany
##########################################################################
+import warnings
import threading
import sqlalchemy
@@ -27,11 +28,14 @@
implements(ISQLAlchemyWrapper)
- def __init__(self, dsn, model=None, **kw):
+ def __init__(self, dsn, model=None, model_provider=None, **kw):
""" 'dsn' - a RFC-1738-style connection string
'model' - optional instance of model.Model
+ 'model_provider' - optional callable providing an instance
+ of model.Model()
+
'kw' - optional keyword arguments passed to create_engine()
"""
@@ -49,7 +53,12 @@
self._engine.echo = self.echo
self._model = None
+ if model is not None and model_provider is not None:
+ raise ValueError("You can not specify both 'model' and 'model_provider' at the same time")
+
if model:
+ warnings.warn("The 'model' parameter is deprecated. Use 'model_provider' instead", DeprecationWarning, stacklevel=1)
+
if isinstance(model, Model):
self._model = model
@@ -62,11 +71,19 @@
self._model = util.getModel()
+
else:
raise ValueError("The 'model' parameter passed to constructor must either be "\
"the name of a named utility implementing IModelProvider or "\
"an instance of z3c.sqlalchemy.model.Model.")
+ if model_provider:
+
+ if not callable(model_provider):
+ raise ValueError('model_provider must be callable')
+
+ self._model = model_provider(self.metadata)
+
# mappers must be initialized at last since we need to acces
# the 'model' from within the constructor of LazyMapperCollection
self._mappers = LazyMapperCollection(self)
More information about the Checkins
mailing list