Commits

Daniel Fetchinson committed 5a8d108

test suite passes with python2.7 -3 without warnings

  • Participants
  • Parent commits dc9cbfe

Comments (0)

Files changed (7)

File formencode/api.py

  
             except AttributeError:
                 trans = _stdtrans
- 
-        if not callable(trans):
+        
+        from collections import Callable
+        if not isinstance(trans, Callable):
             trans = _stdtrans
 
         msg = self._messages[msgName]

File formencode/declarative.py

 """
 
 import copy
-import new
+try:
+    import new
+    def make_instancemethod( func, obj, _type ):
+        return new.instancemethod( func, obj, _type )
+except ImportError:
+    def make_instancemethod( func, obj, _type ):
+        return func.__get__( obj, _type )
 
 from itertools import count
 
             obj = type.singleton()
         if type is None:
             type = obj.__class__
-        return new.instancemethod(self.func, obj, type)
+        return make_instancemethod(self.func, obj, type)
 
 
 class Declarative(object):

File formencode/doctest_xml_compare.py

         if reporter:
             reporter('tail: %r != %r' % (x1.tail, x2.tail))
         return False
-    cl1 = x1.getchildren()
-    cl2 = x2.getchildren()
+    cl1 = list(x1)
+    cl2 = list(x2)
     if len(cl1) != len(cl2):
         if reporter:
             reporter('children length differs, %i != %i'

File formencode/htmlgen.py

         el.attrib.update(kw)
         el.text = self.text
         last = None
-        for item in self.getchildren():
+        for item in self:
             last = item
             el.append(item)
         for arg in flatten(args):

File formencode/national.py

             value = value.replace(f, t)
         value = self._perform_rex_transformation(value, self._preTransformations)
         if self.default_cc:
-            if callable(self.default_cc):
+            from collections import Callable
+            if isinstance(self.default_cc, Callable):
                 cc = self.default_cc()
             else:
                 cc = self.default_cc

File formencode/util/doctest24.py

         return (f,t)
 
     def rundict(self, d, name, module=None):
-        import new
-        m = new.module(name)
+        try:
+            import new
+            new_module = new.module
+        except ImportError:
+            # python 3.x
+            import imp
+            new_module = imp.new_module
+        m = new_module(name)
         m.__dict__.update(d)
         if module is None:
             module = False
         return self.rundoc(m, name, module)
 
     def run__test__(self, d, name):
-        import new
-        m = new.module(name)
+        try:
+            import new
+            new_module = new.module
+        except ImportError:
+            # python 3.x
+            import imp
+            import imp
+            new_module = imp.new_module
+        m = new_module(name)
         m.__test__ = d
         return self.rundoc(m, name)
 

File formencode/validators.py

             date_format = date_format.encode(encoding)
         else:
             encoding = None
+        from collections import Callable
         if self.earliest_date:
-            if callable(self.earliest_date):
+            if isinstance(self.earliest_date, Callable):
                 earliest_date = self.earliest_date()
             else:
                 earliest_date = self.earliest_date
                     self.message('after', state, date=date_formatted),
                     value, state)
         if self.latest_date:
-            if callable(self.latest_date):
+            if isinstance(self.latest_date, Callable):
                 latest_date = self.latest_date()
             else:
                 latest_date = self.latest_date