compat.py 777 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. # encoding: utf-8
  2. """
  3. This module provides compatibility between Python 2 and 3. Hardly
  4. anything is used by this project to constitute including `six`_.
  5. .. _`six`: http://pythonhosted.org/six
  6. """
  7. import sys
  8. if sys.version_info[0] < 3:
  9. # Python 2.
  10. unicode = unicode
  11. string_types = (basestring,)
  12. from collections import Iterable
  13. from itertools import izip_longest
  14. def iterkeys(mapping):
  15. return mapping.iterkeys()
  16. else:
  17. # Python 3.
  18. unicode = str
  19. string_types = (unicode,)
  20. from collections.abc import Iterable
  21. from itertools import zip_longest as izip_longest
  22. def iterkeys(mapping):
  23. return mapping.keys()
  24. try:
  25. # Python 3.6+.
  26. from collections.abc import Collection
  27. except ImportError:
  28. # Python 2.7 - 3.5.
  29. from collections import Container as Collection