Commits

Mike Bayer committed 13c828e

- Dropped 0.3-compatibility for user defined types
(convert_result_value, convert_bind_param).

Comments (0)

Files changed (5)

     - The 'length' argument to all Numeric types has been renamed
       to 'scale'.  'length' is deprecated and is still accepted
       with a warning.
-      
+
+    - Dropped 0.3-compatibility for user defined types
+      (convert_result_value, convert_bind_param).
+
 - sql
     - Temporarily rolled back the "ORDER BY" enhancement from
       [ticket:1068].  This feature is on hold pending further

doc/build/content/types.txt

         def copy(self):
             return MyType(self.impl.length)
 
-Note that the "old" way to process bind parameters and result values, the `convert_bind_param()` and `convert_result_value()` methods, are still available.  The downside of these is that when using a type which already processes data such as the `Unicode` type, you need to call the superclass version of these methods directly.  Using `process_bind_param()` and `process_result_value()`, user-defined code can return and receive the desired Python data directly.
-
-As of version 0.4.2, `TypeDecorator` should generally be used for any user-defined type which redefines the behavior of another type, including other `TypeDecorator` subclasses such as `PickleType`, and the new `process_...()` methods described above should be used.  
+`TypeDecorator` should generally be used for any user-defined type which redefines the behavior of another type, including other `TypeDecorator` subclasses such as `PickleType`, and the new `process_...()` methods described above should be used.
 
 To build a type object from scratch, which will not have a corresponding database-specific implementation, subclass `TypeEngine`:
 
     class MyType(types.TypeEngine):
         def __init__(self, precision = 8):
             self.precision = precision
-            
+
         def get_col_spec(self):
             return "MYTYPE(%s)" % self.precision
-            
-        def convert_bind_param(self, value, dialect):
-            return value
-            
+
+        def bind_processor(self, dialect):
+            def process(value):
+                return value
+            return process
+        def result_processor(self, dialect):
+            def process(value):
+                return value
+            return process
+
         def convert_result_value(self, value, dialect):
             return value
 

lib/sqlalchemy/types.py

 from sqlalchemy.util import pickle
 import sqlalchemy.util as util
 NoneType = type(None)
-
-class _UserTypeAdapter(type):
-    """adapts 0.3 style user-defined types with convert_bind_param/convert_result_value
-    to use newer bind_processor()/result_processor() methods."""
-
-    def __init__(cls, clsname, bases, dict):
-        if not hasattr(cls.convert_result_value, '_sa_override'):
-            cls.__instrument_result_proc(cls)
-
-        if not hasattr(cls.convert_bind_param, '_sa_override'):
-            cls.__instrument_bind_proc(cls)
-
-        return super(_UserTypeAdapter, cls).__init__(clsname, bases, dict)
-
-    def __instrument_bind_proc(cls, class_):
-        def bind_processor(self, dialect):
-            def process(value):
-                return self.convert_bind_param(value, dialect)
-            return process
-        class_.super_bind_processor = class_.bind_processor
-        class_.bind_processor = bind_processor
-
-    def __instrument_result_proc(cls, class_):
-        def result_processor(self, dialect):
-            def process(value):
-                return self.convert_result_value(value, dialect)
-            return process
-        class_.super_result_processor = class_.result_processor
-        class_.result_processor = result_processor
-
-
+    
 class AbstractType(object):
-    __metaclass__ = _UserTypeAdapter
 
     def __init__(self, *args, **kwargs):
         pass
     def copy_value(self, value):
         return value
 
-    def convert_result_value(self, value, dialect):
-        """Legacy convert_result_value() compatibility method.
-
-        This adapter method is provided for user-defined types that implement
-        the older convert_* interface and need to call their super method.
-        These calls are adapted behind the scenes to use the newer
-        callable-based interface via result_processor().
-
-        Compatibility is configured on a case-by-case basis at class
-        definition time by a legacy adapter metaclass.  This method is only
-        available and functional if the concrete subclass implements the
-        legacy interface.
-        """
-
-        processor = self.super_result_processor(dialect)
-        if processor:
-            return processor(value)
-        else:
-            return value
-    convert_result_value._sa_override = True
-
-    def convert_bind_param(self, value, dialect):
-        """Legacy convert_bind_param() compatability method.
-
-        This adapter method is provided for user-defined types that implement
-        the older convert_* interface and need to call their super method.
-        These calls are adapted behind the scenes to use the newer
-        callable-based interface via bind_processor().
-
-        Compatibility is configured on a case-by-case basis at class
-        definition time by a legacy adapter metaclass.  This method is only
-        available and functional if the concrete subclass implements the
-        legacy interface.
-        """
-
-        processor = self.super_bind_processor(dialect)
-        if processor:
-            return processor(value)
-        else:
-            return value
-    convert_bind_param._sa_override = True
-
     def bind_processor(self, dialect):
         """Defines a bind parameter processing function."""
 

test/orm/relationships.py

     def define_tables(self, metadata):
         class MySpecialType(sa.types.TypeDecorator):
             impl = String
-            def convert_bind_param(self, value, dialect):
+            def process_bind_param(self, value, dialect):
                 return "lala" + value
-            def convert_result_value(self, value, dialect):
+            def process_result_value(self, value, dialect):
                 return value[4:]
 
         Table('t1', metadata,

test/sql/testtypes.py

     def testprocessing(self):
 
         global users
-        users.insert().execute(user_id = 2, goofy = 'jack', goofy2='jack', goofy4=u'jack', goofy5=u'jack', goofy6='jack', goofy7=u'jack', goofy8=12, goofy9=12)
-        users.insert().execute(user_id = 3, goofy = 'lala', goofy2='lala', goofy4=u'lala', goofy5=u'lala', goofy6='lala', goofy7=u'lala', goofy8=15, goofy9=15)
-        users.insert().execute(user_id = 4, goofy = 'fred', goofy2='fred', goofy4=u'fred', goofy5=u'fred', goofy6='fred', goofy7=u'fred', goofy8=9, goofy9=9)
+        users.insert().execute(
+            user_id=2, goofy='jack', goofy2='jack', goofy4=u'jack',
+            goofy7=u'jack', goofy8=12, goofy9=12)
+        users.insert().execute(
+            user_id=3, goofy='lala', goofy2='lala', goofy4=u'lala',
+            goofy7=u'lala', goofy8=15, goofy9=15)
+        users.insert().execute(
+            user_id=4, goofy='fred', goofy2='fred', goofy4=u'fred',
+            goofy7=u'fred', goofy8=9, goofy9=9)
 
         l = users.select().execute().fetchall()
         for assertstr, assertint, assertint2, row in zip(
             [1200, 1500, 900],
             [1800, 2250, 1350],
             l
-
         ):
-            for col in row[1:7]:
+            for col in row[1:5]:
                 self.assertEquals(col, assertstr)
-            self.assertEquals(row[7], assertint)
-            self.assertEquals(row[8], assertint2)
-            for col in (row[3], row[4], row[6]):
+            self.assertEquals(row[5], assertint)
+            self.assertEquals(row[6], assertint2)
+            for col in row[3], row[4]:
                 assert isinstance(col, unicode)
 
     def setUpAll(self):
             def copy(self):
                 return MyUnicodeType(self.impl.length)
 
-        class LegacyType(types.TypeEngine):
-            def get_col_spec(self):
-                return "VARCHAR(100)"
-            def convert_bind_param(self, value, dialect):
-                return "BIND_IN"+ value
-            def convert_result_value(self, value, dialect):
-                return value + "BIND_OUT"
-            def adapt(self, typeobj):
-                return typeobj()
-
-        class LegacyUnicodeType(types.TypeDecorator):
-            impl = Unicode
-
-            def convert_bind_param(self, value, dialect):
-                return "BIND_IN" + super(LegacyUnicodeType, self).convert_bind_param(value, dialect)
-
-            def convert_result_value(self, value, dialect):
-                return super(LegacyUnicodeType, self).convert_result_value(value, dialect) + "BIND_OUT"
-
-            def copy(self):
-                return LegacyUnicodeType(self.impl.length)
-
         metadata = MetaData(testing.db)
         users = Table('type_users', metadata,
             Column('user_id', Integer, primary_key = True),
             Column('goofy2', MyDecoratedType(50), nullable = False),
 
             Column('goofy4', MyUnicodeType(50), nullable = False),
-            Column('goofy5', LegacyUnicodeType(50), nullable = False),
-            Column('goofy6', LegacyType, nullable = False),
             Column('goofy7', MyNewUnicodeType(50), nullable = False),
             Column('goofy8', MyNewIntType, nullable = False),
             Column('goofy9', MyNewIntSubClass, nullable = False),
-
         )
 
         metadata.create_all()