Michael Foord | 1e68bec | 2012-03-03 22:24:30 +0000 | [diff] [blame] | 1 | import sys |
| 2 | |
| 3 | info = sys.version_info |
| 4 | if info[:3] >= (3, 2, 0): |
| 5 | # for Python 3.2 ordinary unittest is fine |
| 6 | import unittest as unittest2 |
| 7 | else: |
| 8 | import unittest2 |
| 9 | |
| 10 | |
| 11 | try: |
| 12 | callable = callable |
| 13 | except NameError: |
| 14 | def callable(obj): |
| 15 | return hasattr(obj, '__call__') |
| 16 | |
| 17 | |
| 18 | inPy3k = sys.version_info[0] == 3 |
| 19 | with_available = sys.version_info[:2] >= (2, 5) |
| 20 | |
| 21 | |
| 22 | def is_instance(obj, klass): |
| 23 | """Version of is_instance that doesn't access __class__""" |
| 24 | return issubclass(type(obj), klass) |
| 25 | |
| 26 | |
| 27 | class SomeClass(object): |
| 28 | class_attribute = None |
| 29 | |
| 30 | def wibble(self): |
| 31 | pass |
| 32 | |
| 33 | |
| 34 | class X(object): |
| 35 | pass |
| 36 | |
| 37 | try: |
| 38 | next = next |
| 39 | except NameError: |
| 40 | def next(obj): |
| 41 | return obj.next() |