Commits

jason kirtland committed 8f7ab98

Migrated Connection.properties to Connection.info ('info' is the new standard name for user-writable property collections that came out of [ticket:573]). 'properties' is now an alias, will be removed in 0.5.

Comments (0)

Files changed (6)

   - 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

lib/sqlalchemy/databases/mysql.py

         """
 
         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
 
         """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()
         # 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'"),
                 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):
         """
 
         try:
-            return connection.properties['collations']
+            return connection.info['collations']
         except KeyError:
             collations = {}
             if self.server_version_info(connection) < (4, 1, 0):
                 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,

lib/sqlalchemy/engine/base.py

     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.

lib/sqlalchemy/interfaces.py

     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.
 
 
         con_record
           The ``_ConnectionRecord`` that persistently manages the connection
-          
+
         """
 
     def checkout(self, dbapi_con, con_record, con_proxy):

lib/sqlalchemy/pool.py

     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)
     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)
                 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)
                 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
 
     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.
             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):

test/engine/pool.py

                            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()