]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Migrated Connection.properties to Connection.info ('info' is the new standard name...
authorJason Kirtland <jek@discorporate.us>
Sun, 18 Nov 2007 18:19:52 +0000 (18:19 +0000)
committerJason Kirtland <jek@discorporate.us>
Sun, 18 Nov 2007 18:19:52 +0000 (18:19 +0000)
CHANGES
lib/sqlalchemy/databases/mysql.py
lib/sqlalchemy/engine/base.py
lib/sqlalchemy/interfaces.py
lib/sqlalchemy/pool.py
test/engine/pool.py

diff --git a/CHANGES b/CHANGES
index 653d58a22f923abbbd60b08f6e5649554746c240..665e75218ef279ae93e3fe0f51200d4565005beb 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -61,6 +61,10 @@ CHANGES
   - Added a field ("info") for storing arbitrary data on schema items
     [ticket:573]    
 
+  - The "properties" collection on Connections has been renamed "info" to
+    match schema's writable collections.  Access is still available via
+    the "properties" name until 0.5.
+
   - fixed the close() method on Transaction when using strategy='threadlocal'
 
   - fix to compiled bind parameters to not mistakenly populate None
index eaba40a6dc43bbcb04449fdc093a347e547dd02c..441c099a2e8c2ac9c6ffe933940315773990fee9 100644 (file)
@@ -1591,9 +1591,9 @@ class MySQLDialect(default.DefaultDialect):
         """
 
         try:
-            return connection.properties['_mysql_server_version_info']
+            return connection.info['_mysql_server_version_info']
         except KeyError:
-            version = connection.properties['_mysql_server_version_info'] = \
+            version = connection.info['_mysql_server_version_info'] = \
               self._server_version_info(connection.connection.connection)
             return version
 
@@ -1663,8 +1663,8 @@ class MySQLDialect(default.DefaultDialect):
         """Sniff out the character set in use for connection results."""
 
         # Allow user override, won't sniff if force_charset is set.
-        if 'force_charset' in connection.properties:
-            return connection.properties['force_charset']
+        if 'force_charset' in connection.info:
+            return connection.info['force_charset']
 
         # Note: MySQL-python 1.2.1c7 seems to ignore changes made
         # on a connection via set_character_set()
@@ -1710,7 +1710,7 @@ class MySQLDialect(default.DefaultDialect):
         # http://dev.mysql.com/doc/refman/5.0/en/name-case-sensitivity.html
 
         try:
-            return connection.properties['lower_case_table_names']
+            return connection.info['lower_case_table_names']
         except KeyError:
             row = _compat_fetchone(connection.execute(
                     "SHOW VARIABLES LIKE 'lower_case_table_names'"),
@@ -1727,7 +1727,7 @@ class MySQLDialect(default.DefaultDialect):
                 else:
                     cs = int(row[1])
                 row.close()
-            connection.properties['lower_case_table_names'] = cs
+            connection.info['lower_case_table_names'] = cs
             return cs
 
     def _detect_collations(self, connection, charset=None):
@@ -1737,7 +1737,7 @@ class MySQLDialect(default.DefaultDialect):
         """
 
         try:
-            return connection.properties['collations']
+            return connection.info['collations']
         except KeyError:
             collations = {}
             if self.server_version_info(connection) < (4, 1, 0):
@@ -1746,7 +1746,7 @@ class MySQLDialect(default.DefaultDialect):
                 rs = connection.execute('SHOW COLLATION')
                 for row in _compat_fetchall(rs, charset):
                     collations[row[0]] = row[1]
-            connection.properties['collations'] = collations
+            connection.info['collations'] = collations
             return collations
 
     def _show_create_table(self, connection, table, charset=None,
index c3f99bb246446499c3f7f1bcc03799908f5a6074..6af0ce0d39a8003e57c661ef36096a2649e0f11f 100644 (file)
@@ -557,8 +557,13 @@ class Connection(Connectable):
     dialect = property(lambda s:s.engine.dialect, doc="Dialect used by this Connection.")
     connection = property(_get_connection, doc="The underlying DB-API connection managed by this Connection.")
     should_close_with_result = property(lambda s:s.__close_with_result, doc="Indicates if this Connection should be closed when a corresponding ResultProxy is closed; this is essentially an auto-release mode.")
-    properties = property(lambda s: s._get_connection().properties,
-                          doc="A collection of per-DB-API connection instance properties.")
+
+    info = property(lambda s: s._get_connection().info,
+                    doc=("A collection of per-DB-API connection instance "
+                         "properties."))
+    properties = property(lambda s: s._get_connection().info,
+                          doc=("An alias for the .info collection, will be "
+                               "removed in 0.5."))
 
     def connect(self):
         """Returns self.
index ae2aeed690eb05461ae3fb460ba621afc7a355a8..eaad2576988fdb0bf58b970a633bd34a91ac5034 100644 (file)
@@ -29,7 +29,7 @@ class PoolListener(object):
     Events also receive a ``_ConnectionRecord``, a long-lived internal
     ``Pool`` object that basically represents a "slot" in the
     connection pool.  ``_ConnectionRecord`` objects have one public
-    attribute of note: ``properties``, a dictionary whose contents are
+    attribute of note: ``info``, a dictionary whose contents are
     scoped to the lifetime of the DB-API connection managed by the
     record.  You can use this shared storage area however you like.
 
@@ -51,7 +51,7 @@ class PoolListener(object):
 
         con_record
           The ``_ConnectionRecord`` that persistently manages the connection
-          
+
         """
 
     def checkout(self, dbapi_con, con_record, con_proxy):
index 40114144b9cfdf1d4ab70c37f4916931fdc8de15..ff38f21b874569e084f3390035fa22d44a1ace04 100644 (file)
@@ -199,7 +199,7 @@ class _ConnectionRecord(object):
     def __init__(self, pool):
         self.__pool = pool
         self.connection = self.__connect()
-        self.properties = {}
+        self.info = {}
         if pool._on_connect:
             for l in pool._on_connect:
                 l.connect(self.connection, self)
@@ -222,7 +222,7 @@ class _ConnectionRecord(object):
     def get_connection(self):
         if self.connection is None:
             self.connection = self.__connect()
-            self.properties.clear()
+            self.info.clear()
             if self.__pool._on_connect:
                 for l in self.__pool._on_connect:
                     l.connect(self.connection, self)
@@ -231,7 +231,7 @@ class _ConnectionRecord(object):
                 self.__pool.log("Connection %s exceeded timeout; recycling" % repr(self.connection))
             self.__close()
             self.connection = self.__connect()
-            self.properties.clear()
+            self.info.clear()
             if self.__pool._on_connect:
                 for l in self.__pool._on_connect:
                     l.connect(self.connection, self)
@@ -260,6 +260,9 @@ class _ConnectionRecord(object):
                 self.__pool.log("Error on connect(): %s" % (str(e)))
             raise
 
+    properties = property(lambda self: self.info,
+                          doc="A synonym for .info, will be removed in 0.5.")
+
 def _finalize_fairy(connection, connection_record, pool, ref=None):
     if ref is not None and connection_record.backref is not ref:
         return
@@ -304,20 +307,21 @@ class _ConnectionFairy(object):
 
     is_valid = property(lambda self:self.connection is not None)
 
-    def _get_properties(self):
-        """A property collection unique to this DB-API connection."""
+    def _get_info(self):
+        """An info collection unique to this DB-API connection."""
 
         try:
-            return self._connection_record.properties
+            return self._connection_record.info
         except AttributeError:
             if self.connection is None:
                 raise exceptions.InvalidRequestError("This connection is closed")
             try:
-                return self._detatched_properties
+                return self._detached_info
             except AttributeError:
-                self._detatched_properties = value = {}
+                self._detached_info = value = {}
                 return value
-    properties = property(_get_properties)
+    info = property(_get_info)
+    properties = property(_get_info)
 
     def invalidate(self, e=None):
         """Mark this connection as invalidated.
@@ -389,8 +393,8 @@ class _ConnectionFairy(object):
             self._connection_record.connection = None
             self._connection_record.backref = None
             self._pool.do_return_conn(self._connection_record)
-            self._detatched_properties = \
-              self._connection_record.properties.copy()
+            self._detached_info = \
+              self._connection_record.info.copy()
             self._connection_record = None
 
     def close(self):
index 9c957ddafb8a1d57cd36226b98cfe49deda4448b..fabf0676619e8606b3b16ac29825e79adc2a1e17 100644 (file)
@@ -379,28 +379,28 @@ class PoolTest(PersistTest):
                            pool_size=1, max_overflow=0, use_threadlocal=False)
 
         c = p.connect()
-        self.assert_(not c.properties)
-        self.assert_(c.properties is c._connection_record.properties)
+        self.assert_(not c.info)
+        self.assert_(c.info is c._connection_record.info)
 
-        c.properties['foo'] = 'bar'
+        c.info['foo'] = 'bar'
         c.close()
         del c
 
         c = p.connect()
-        self.assert_('foo' in c.properties)
+        self.assert_('foo' in c.info)
 
         c.invalidate()
         c = p.connect()
-        self.assert_('foo' not in c.properties)
+        self.assert_('foo' not in c.info)
 
-        c.properties['foo2'] = 'bar2'
+        c.info['foo2'] = 'bar2'
         c.detach()
-        self.assert_('foo2' in c.properties)
+        self.assert_('foo2' in c.info)
 
         c2 = p.connect()
         self.assert_(c.connection is not c2.connection)
-        self.assert_(not c2.properties)
-        self.assert_('foo2' in c.properties)
+        self.assert_(not c2.info)
+        self.assert_('foo2' in c.info)
 
     def test_listeners(self):
         dbapi = MockDBAPI()