]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
working with how this will be documented and having some probs with sphinx
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 10 Aug 2010 00:49:08 +0000 (20:49 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 10 Aug 2010 00:49:08 +0000 (20:49 -0400)
doc/build/reference/orm/index.rst
doc/build/reference/orm/query.rst
doc/build/reference/sqlalchemy/event.rst
doc/build/reference/sqlalchemy/index.rst
doc/build/reference/sqlalchemy/interfaces.rst
lib/sqlalchemy/engine/base.py
lib/sqlalchemy/event.py
lib/sqlalchemy/interfaces.py
lib/sqlalchemy/pool.py
test/engine/test_pool.py

index 001d7b4eebd7d12c3047b712e159da3fa0d3d3c0..e98d5a1117880f7e969a7b45770668afa88ac0d6 100644 (file)
@@ -3,6 +3,8 @@
 sqlalchemy.orm
 ==============
 
+.. module:: sqlalchemy.orm
+
 .. toctree::
     :glob:
 
index 931bbf064c28153158d8b6dbf67a59096b82d0e2..ee30abd4a8db936ad60edaa8783c7b8ccc4f3b7b 100644 (file)
@@ -3,7 +3,9 @@
 Querying
 ========
 
-.. module:: sqlalchemy.orm
+.. module:: sqlalchemy.orm.query
+
+.. currentmodule:: sqlalchemy.orm
 
 The Query Object
 ----------------
index 05e7ab63b7e7dc09c19c75769c6de4b6969cbd82..ec36ee5990d3bbcfdd30f622b18011c052ca13ad 100644 (file)
@@ -1,7 +1,19 @@
 Events
-------
+======
 
 .. automodule:: sqlalchemy.event
+
+.. autofunction:: sqlalchemy.event.listen
+
+Connection Pool Events
+----------------------
+
+.. autoclass:: sqlalchemy.pool.PoolEvents
    :members:
 
+Connection Events
+------------------------
+
+.. autoclass:: sqlalchemy.engine.base.EngineEvents
+    :members:
 
index b87c2900bd5d338c89db83df6350c339ef044f5d..0bcc9806322a9e64d13c41bcfd8624d5e2b94a73 100644 (file)
@@ -1,6 +1,8 @@
 sqlalchemy
 ==========
 
+.. module:: sqlalchemy
+
 .. toctree::
     :glob:
 
index 27882b5b27bca2e0ff498ab66948860c5e36d644..b1430e2d7750cc91e48f53f64afb61c3f50dcc14 100644 (file)
@@ -1,5 +1,5 @@
-Interfaces
-----------
+Interfaces (Deprecated)
+------------------------
 
 SQLAlchemy's interface system is now deprecated, and has been
 superceded by a more flexible and consistent event dispatch
index 4260e923abf5a450071dd7fc301dc549a870fc1d..7b6ff5b7a3f5a27965f3a5a95353739323928f7c 100644 (file)
@@ -1546,6 +1546,54 @@ class TwoPhaseTransaction(Transaction):
     def _do_commit(self):
         self.connection._commit_twophase_impl(self.xid, self._is_prepared)
 
+class EngineEvents(event.Events):
+    """Available events for :class:`.Engine`."""
+    
+    @classmethod
+    def listen(cls, fn, identifier, target):
+        if issubclass(target.Connection, Connection):
+            target.Connection = _proxy_connection_cls(
+                                        Connection, 
+                                        target.events)
+        event.Events.listen(fn, identifier, target)
+
+    def on_execute(self, conn, execute, clauseelement, *multiparams, **params):
+        """Intercept high level execute() events."""
+
+    def on_cursor_execute(self, conn, execute, cursor, statement, 
+                        parameters, context, executemany):
+        """Intercept low-level cursor execute() events."""
+
+    def on_begin(self, conn, begin):
+        """Intercept begin() events."""
+
+    def on_rollback(self, conn, rollback):
+        """Intercept rollback() events."""
+
+    def on_commit(self, conn, commit):
+        """Intercept commit() events."""
+
+    def on_savepoint(self, conn, savepoint, name=None):
+        """Intercept savepoint() events."""
+
+    def on_rollback_savepoint(self, conn, rollback_savepoint, name, context):
+        """Intercept rollback_savepoint() events."""
+
+    def on_release_savepoint(self, conn, release_savepoint, name, context):
+        """Intercept release_savepoint() events."""
+
+    def on_begin_twophase(self, conn, begin_twophase, xid):
+        """Intercept begin_twophase() events."""
+
+    def on_prepare_twophase(self, conn, prepare_twophase, xid):
+        """Intercept prepare_twophase() events."""
+
+    def on_rollback_twophase(self, conn, rollback_twophase, xid, is_prepared):
+        """Intercept rollback_twophase() events."""
+
+    def on_commit_twophase(self, conn, commit_twophase, xid, is_prepared):
+        """Intercept commit_twophase() events."""
+
 class Engine(Connectable, log.Identified):
     """
     Connects a :class:`~sqlalchemy.pool.Pool` and 
@@ -1578,52 +1626,8 @@ class Engine(Connectable, log.Identified):
         if execution_options:
             self.update_execution_options(**execution_options)
 
-    class events(event.Events):
-        @classmethod
-        def listen(cls, fn, identifier, target):
-            if issubclass(target.Connection, Connection):
-                target.Connection = _proxy_connection_cls(
-                                            Connection, 
-                                            target.events)
-            event.Events.listen(fn, identifier, target)
             
-        def on_execute(self, conn, execute, clauseelement, *multiparams, **params):
-            """Intercept high level execute() events."""
-
-        def on_cursor_execute(self, conn, execute, cursor, statement, 
-                            parameters, context, executemany):
-            """Intercept low-level cursor execute() events."""
-
-        def on_begin(self, conn, begin):
-            """Intercept begin() events."""
-
-        def on_rollback(self, conn, rollback):
-            """Intercept rollback() events."""
-
-        def on_commit(self, conn, commit):
-            """Intercept commit() events."""
-
-        def on_savepoint(self, conn, savepoint, name=None):
-            """Intercept savepoint() events."""
-
-        def on_rollback_savepoint(self, conn, rollback_savepoint, name, context):
-            """Intercept rollback_savepoint() events."""
-
-        def on_release_savepoint(self, conn, release_savepoint, name, context):
-            """Intercept release_savepoint() events."""
-
-        def on_begin_twophase(self, conn, begin_twophase, xid):
-            """Intercept begin_twophase() events."""
-
-        def on_prepare_twophase(self, conn, prepare_twophase, xid):
-            """Intercept prepare_twophase() events."""
-
-        def on_rollback_twophase(self, conn, rollback_twophase, xid, is_prepared):
-            """Intercept rollback_twophase() events."""
-
-        def on_commit_twophase(self, conn, commit_twophase, xid, is_prepared):
-            """Intercept commit_twophase() events."""
-    events = event.dispatcher(events)
+    events = event.dispatcher(EngineEvents)
     
     def update_execution_options(self, **opt):
         """update the execution_options dictionary of this :class:`Engine`.
index 603aaf383c442f6812b914b61e89f27c239fa5ba..5a8c193a0259313b96876101943d03e7ab7c9852 100644 (file)
@@ -1,10 +1,7 @@
 """
-The event system handles all events throughout the sqlalchemy
-and sqlalchemy.orm packages.   
+The event system handles all events throughout the :mod:`sqlalchemy`
+and :mod:`sqlalchemy.orm` packages.
 
-Event specifications:
-
-:attr:`sqlalchemy.pool.Pool.events`
 
 """
 
@@ -110,7 +107,8 @@ class EventDescriptor(object):
         self._clslevel = util.defaultdict(list)
     
     def append(self, obj, target):
-        assert isinstance(target, type), "Class-level Event targets must be classes."
+        assert isinstance(target, type), \
+                "Class-level Event targets must be classes."
         for cls in [target] + target.__subclasses__():
             self._clslevel[cls].append(obj)
     
index 4eaf4d4ad3e4ca93ece9c84a3591931f38f56d9b..36573bf4371d3d86824e80d574870a7a15275b61 100644 (file)
@@ -14,7 +14,7 @@ class PoolListener(object):
 
     .. note:: :class:`PoolListener` is deprecated.   Please
        refer to :func:`event.listen` as well as 
-       :attr:`Pool.events`.
+       :attr:`.Pool.events`.
     
     Usage::
     
@@ -146,7 +146,8 @@ class ConnectionProxy(object):
     """Allows interception of statement execution by Connections.
 
     .. note:: :class:`ConnectionProxy` is deprecated.   Please
-       refer to :func:`event.listen`.
+       refer to :func:`event.listen` as well as 
+       :attr:`.Engine.events`.
     
     Either or both of the ``execute()`` and ``cursor_execute()``
     may be implemented to intercept compiled statement and
index 9574d28da690aa3724d7e7b9db5359c596ee5f54..8a2845562340f5f921929552f67699afdabac8f9 100644 (file)
@@ -57,6 +57,82 @@ def clear_managers():
         manager.close()
     proxies.clear()
 
+class PoolEvents(event.Events):
+    """Available events for :class:`.Pool`.
+    
+    The methods here define the name of an event as well
+    as the names of members that are passed to listener
+    functions.  Note all members are passed by name.
+    
+    e.g.::
+    
+        from sqlalchemy import events
+        
+        def my_on_checkout(dbapi_conn, connection_rec, connection_proxy):
+            "handle an on checkout event"
+            
+        events.listen(my_on_checkout, 'on_checkout', Pool)
+
+    """
+    
+    def on_connect(self, dbapi_connection, connection_record):
+        """Called once for each new DB-API connection or Pool's ``creator()``.
+
+        :param dbapi_con:
+          A newly connected raw DB-API connection (not a SQLAlchemy
+          ``Connection`` wrapper).
+
+        :param con_record:
+          The ``_ConnectionRecord`` that persistently manages the connection
+
+        """
+
+    def on_first_connect(self, dbapi_connection, connection_record):
+        """Called exactly once for the first DB-API connection.
+
+        :param dbapi_con:
+          A newly connected raw DB-API connection (not a SQLAlchemy
+          ``Connection`` wrapper).
+
+        :param con_record:
+          The ``_ConnectionRecord`` that persistently manages the connection
+
+        """
+
+    def on_checkout(self, dbapi_connection, connection_record, connection_proxy):
+        """Called when a connection is retrieved from the Pool.
+
+        :param dbapi_con:
+          A raw DB-API connection
+
+        :param con_record:
+          The ``_ConnectionRecord`` that persistently manages the connection
+
+        :param con_proxy:
+          The ``_ConnectionFairy`` which manages the connection for the span of
+          the current checkout.
+
+        If you raise an ``exc.DisconnectionError``, the current
+        connection will be disposed and a fresh connection retrieved.
+        Processing of all checkout listeners will abort and restart
+        using the new connection.
+        """
+
+    def on_checkin(self, dbapi_connection, connection_record):
+        """Called when a connection returns to the pool.
+
+        Note that the connection may be closed, and may be None if the
+        connection has been invalidated.  ``checkin`` will not be called
+        for detached connections.  (They do not return to the pool.)
+
+        :param dbapi_con:
+          A raw DB-API connection
+
+        :param con_record:
+          The ``_ConnectionRecord`` that persistently manages the connection
+
+        """
+
 class Pool(log.Identified):
     """Abstract base class for connection pools."""
 
@@ -133,82 +209,11 @@ class Pool(log.Identified):
             for l in listeners:
                 self.add_listener(l)
 
-    class events(event.Events):
-        """Available events for :class:`Pool`.
-        
-        The methods here define the name of an event as well
-        as the names of members that are passed to listener
-        functions.  Note all members are passed by name.
-        
-        e.g.::
-        
-            from sqlalchemy import events
-            events.listen(fn, 'on_checkout', Pool)
-
-        """
-        
-        def on_connect(self, dbapi_connection, connection_record):
-            """Called once for each new DB-API connection or Pool's ``creator()``.
-
-            :param dbapi_con:
-              A newly connected raw DB-API connection (not a SQLAlchemy
-              ``Connection`` wrapper).
-
-            :param con_record:
-              The ``_ConnectionRecord`` that persistently manages the connection
-
-            """
-
-        def on_first_connect(self, dbapi_connection, connection_record):
-            """Called exactly once for the first DB-API connection.
-
-            :param dbapi_con:
-              A newly connected raw DB-API connection (not a SQLAlchemy
-              ``Connection`` wrapper).
-
-            :param con_record:
-              The ``_ConnectionRecord`` that persistently manages the connection
-
-            """
-
-        def on_checkout(self, dbapi_connection, connection_record, connection_proxy):
-            """Called when a connection is retrieved from the Pool.
-
-            :param dbapi_con:
-              A raw DB-API connection
-
-            :param con_record:
-              The ``_ConnectionRecord`` that persistently manages the connection
-
-            :param con_proxy:
-              The ``_ConnectionFairy`` which manages the connection for the span of
-              the current checkout.
-
-            If you raise an ``exc.DisconnectionError``, the current
-            connection will be disposed and a fresh connection retrieved.
-            Processing of all checkout listeners will abort and restart
-            using the new connection.
-            """
-
-        def on_checkin(self, dbapi_connection, connection_record):
-            """Called when a connection returns to the pool.
-
-            Note that the connection may be closed, and may be None if the
-            connection has been invalidated.  ``checkin`` will not be called
-            for detached connections.  (They do not return to the pool.)
-
-            :param dbapi_con:
-              A raw DB-API connection
-
-            :param con_record:
-              The ``_ConnectionRecord`` that persistently manages the connection
-
-            """
-    events = event.dispatcher(events)
+    events = event.dispatcher(PoolEvents)
         
-    @util.deprecated("Pool.add_listener() is deprecated.  Use event.listen()")
+    @util.deprecated(":meth:`.Pool.add_listener` is deprecated.  Use :func:`.event.listen`")
     def add_listener(self, listener):
-        """Add a ``PoolListener``-like object to this pool.
+        """Add a :class:`.PoolListener`-like object to this pool.
         
         ``listener`` may be an object that implements some or all of
         PoolListener, or a dictionary of callables containing implementations
index c9cd6bdd44a4bbe48e7a4e23a80995d6257f3a46..e09b7a04fe8e49dcf72094c9e6fde05224036a6c 100644 (file)
@@ -403,13 +403,13 @@ class PoolTest(PoolTestBase):
             assert_listeners(p, 1, 1, 1, 1)
 
             p.add_listener(i_connect)
-            assert_listeners(p, 2, 2, 1, 1)
+            assert_listeners(p, 2, 1, 1, 1)
 
             p.add_listener(i_checkout)
-            assert_listeners(p, 3, 2, 2, 1)
+            assert_listeners(p, 3, 1, 1, 1)
 
             p.add_listener(i_checkin)
-            assert_listeners(p, 4, 2, 2, 2)
+            assert_listeners(p, 4, 1, 1, 1)
             del p
 
             p = _pool(listeners=[i_all])
@@ -424,7 +424,7 @@ class PoolTest(PoolTestBase):
             assert counts == [1, 2, 1]
             p.add_listener(i_checkin)
             c.close()
-            assert counts == [1, 2, 3]
+            assert counts == [1, 2, 2]
 
     def test_listener_after_oninit(self):
         """Test that listeners are called after OnInit is removed"""