[Checkins] SVN: z3c.saconfig/trunk/ EngineCreatedEvent also gets ``engine_args`` and ``engine_kw`` as

Martijn Faassen faassen at startifact.com
Tue Sep 28 11:53:34 EDT 2010


Log message for revision 117011:
  EngineCreatedEvent also gets ``engine_args`` and ``engine_kw`` as
  attributes, so that event handlers can potentially differentiate
  between engines.
  
  

Changed:
  U   z3c.saconfig/trunk/CHANGES.txt
  U   z3c.saconfig/trunk/src/z3c/saconfig/README.txt
  U   z3c.saconfig/trunk/src/z3c/saconfig/interfaces.py
  U   z3c.saconfig/trunk/src/z3c/saconfig/utility.py

-=-
Modified: z3c.saconfig/trunk/CHANGES.txt
===================================================================
--- z3c.saconfig/trunk/CHANGES.txt	2010-09-28 15:52:53 UTC (rev 117010)
+++ z3c.saconfig/trunk/CHANGES.txt	2010-09-28 15:53:34 UTC (rev 117011)
@@ -1,6 +1,13 @@
 z3c.saconfig
 ************
 
+0.12 (2010-09-28)
+=================
+
+- EngineCreatedEvent also gets ``engine_args`` and ``engine_kw`` as
+  attributes, so that event handlers can potentially differentiate
+  between engines.
+
 0.11 (2010-07-05)
 =================
 

Modified: z3c.saconfig/trunk/src/z3c/saconfig/README.txt
===================================================================
--- z3c.saconfig/trunk/src/z3c/saconfig/README.txt	2010-09-28 15:52:53 UTC (rev 117010)
+++ z3c.saconfig/trunk/src/z3c/saconfig/README.txt	2010-09-28 15:53:34 UTC (rev 117011)
@@ -145,10 +145,14 @@
   >>> @component.adapter(IEngineCreatedEvent)
   ... def createdHandler(event):
   ...     print "created engine"
+  ...     print "args:", event.engine_args
+  ...     print "kw:", event.engine_kw
   >>> component.provideHandler(createdHandler)
   >>> event_engine_factory = EngineFactory(TEST_DSN1)
   >>> engine = event_engine_factory()
   created engine
+  args: ('sqlite:///:memory:',)
+  kw: {}
 
 Let's get rid of the event handler again::
 

Modified: z3c.saconfig/trunk/src/z3c/saconfig/interfaces.py
===================================================================
--- z3c.saconfig/trunk/src/z3c/saconfig/interfaces.py	2010-09-28 15:52:53 UTC (rev 117010)
+++ z3c.saconfig/trunk/src/z3c/saconfig/interfaces.py	2010-09-28 15:53:34 UTC (rev 117011)
@@ -64,9 +64,17 @@
     an active engine.
     """
     engine = Attribute("The engine that was just created.")
-    
+
+    engine_args = Attribute("List of arguments given to SQLAlchemy "
+                            "create_engine")
+
+    engine_kw = Attribute("Dictionary of keyword attributes given to "
+                          "SQLAlchemy create_engine")
+
 class EngineCreatedEvent(object):
     implements(IEngineCreatedEvent)
 
-    def __init__(self, engine):
+    def __init__(self, engine, engine_args, engine_kw):
         self.engine = engine
+        self.engine_args = engine_args
+        self.engine_kw = engine_kw

Modified: z3c.saconfig/trunk/src/z3c/saconfig/utility.py
===================================================================
--- z3c.saconfig/trunk/src/z3c/saconfig/utility.py	2010-09-28 15:52:53 UTC (rev 117010)
+++ z3c.saconfig/trunk/src/z3c/saconfig/utility.py	2010-09-28 15:53:34 UTC (rev 117011)
@@ -163,7 +163,7 @@
                 args, kw = self.configuration()
                 _ENGINES[self._key] = engine = sqlalchemy.create_engine(
                     *args, **kw)
-                notify(EngineCreatedEvent(engine))
+                notify(EngineCreatedEvent(engine, args, kw))
             return _ENGINES[self._key]
         finally:
             _ENGINES_LOCK.release()



More information about the checkins mailing list