]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
more work on the types...
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 22 Sep 2005 06:48:55 +0000 (06:48 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 22 Sep 2005 06:48:55 +0000 (06:48 +0000)
lib/sqlalchemy/types.py

index e0860c83a3401b81ce899b7ae40aecdb4076ee49..ab441a8ea5b1652e43e049d9109a0942c45140c1 100644 (file)
@@ -18,6 +18,14 @@ class TypeEngine(object):
         raise NotImplementedError()
     def adapt(self, typeobj):
         return typeobj()
+    def type_descriptor(self, conversion, cls = None):
+        t = cls or self.__class__
+        for t in t.__mro__[0:-1]:
+            try:
+                return self.adapt(conversion[t])
+            except KeyError, e:
+                pass
+        return self.adapt(cls or self.__class__)
 
     typeclass = property(lambda s: s.__class__)
     typeself = property(lambda s:s)
@@ -35,6 +43,12 @@ class String(TypeEngine):
         self.length = length
     def adapt(self, typeobj):
         return typeobj(self.length)
+    def type_descriptor(self, conversion):
+        if self.length is None:
+            return super(String, self).type_descriptor(conversion, TEXT)
+        else:
+            return super(String, self).type_descriptor(conversion)
+            
 String.singleton = String(-1)
 
 class Integer(TypeEngine):