will not be descended.
"""
+ # Py2K
if isinstance(cls, types.ClassType):
return list()
+ # end Py2K
hier = set([cls])
process = list(cls.__mro__)
while process:
c = process.pop()
+ # Py2K
if isinstance(c, types.ClassType):
continue
for b in (_ for _ in c.__bases__
if _ not in hier and not isinstance(_, types.ClassType)):
+ # end Py2K
+ # Py3K
+ #for b in (_ for _ in c.__bases__
+ # if _ not in hier):
process.append(b)
hier.add(b)
+ # Py3K
+ #if c.__module__ == 'builtins' or not hasattr(c, '__subclasses__'):
+ # continue
+ # Py2K
if c.__module__ == '__builtin__' or not hasattr(c, '__subclasses__'):
continue
+ # end Py2K
for s in [_ for _ in c.__subclasses__() if _ not in hier]:
process.append(s)
hier.add(s)
return item
def clear(self):
+ # Py2K
+ # in 3k, MutableMapping calls popitem()
self._weakrefs.clear()
self.by_id.clear()
+ # end Py2K
weakref.WeakKeyDictionary.clear(self)
def update(self, *a, **kw):
"""Tests exceptions and DB-API exception wrapping."""
import testenv; testenv.configure_for_tests()
from testlib import sa_unittest as unittest
-import exceptions as stdlib_exceptions
from sqlalchemy import exc as sa_exceptions
+# Py3K
+#StandardError = BaseException
+# Py2K
+from exceptions import StandardError, KeyboardInterrupt, SystemExit
+# end Py2K
-class Error(stdlib_exceptions.StandardError):
+class Error(StandardError):
"""This class will be old-style on <= 2.4 and new-style on >= 2.5."""
class DatabaseError(Error):
pass
def test_db_error_keyboard_interrupt(self):
try:
raise sa_exceptions.DBAPIError.instance(
- '', [], stdlib_exceptions.KeyboardInterrupt())
+ '', [], KeyboardInterrupt())
except sa_exceptions.DBAPIError:
self.assert_(False)
- except stdlib_exceptions.KeyboardInterrupt:
+ except KeyboardInterrupt:
self.assert_(True)
def test_db_error_system_exit(self):
try:
raise sa_exceptions.DBAPIError.instance(
- '', [], stdlib_exceptions.SystemExit())
+ '', [], SystemExit())
except sa_exceptions.DBAPIError:
self.assert_(False)
- except stdlib_exceptions.SystemExit:
+ except SystemExit:
self.assert_(True)
eq_(set(util.class_hierarchy(A)), set((A, B, C, object)))
eq_(set(util.class_hierarchy(B)), set((A, B, C, object)))
-
+
+ # Py2K
def test_oldstyle_mixin(self):
class A(object):
pass
eq_(set(util.class_hierarchy(B)), set((A, B, object)))
eq_(set(util.class_hierarchy(Mixin)), set())
eq_(set(util.class_hierarchy(A)), set((A, B, object)))
-
+ # end Py2K
if __name__ == "__main__":
testenv.main()