compat.py 631 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from __future__ import unicode_literals
  4. import sys
  5. SUPPORT_UCS4 = len('\U00020000') == 1
  6. PY2 = sys.version_info < (3, 0)
  7. subversion = getattr(sys, 'subversion', [''])
  8. # 这些 Python 实现虽然是 Python 2 但字符串的行为跟 Python 3 是一样的
  9. if subversion[0] in (
  10. 'IronPython',
  11. ):
  12. PY2 = False # pragma: no cover
  13. if not PY2:
  14. text_type = str
  15. bytes_type = bytes
  16. else:
  17. text_type = unicode # noqa
  18. bytes_type = str
  19. try:
  20. callable_check = callable # noqa
  21. except NameError:
  22. def callable_check(obj):
  23. return hasattr(obj, '__call__')