compat.py 544 B

12345678910111213141516171819202122232425262728
  1. import sys
  2. PY3 = sys.version_info[0] >= 3
  3. if PY3:
  4. unicode = bytes.decode
  5. unicode_type = str
  6. basestring = str
  7. xrange = range
  8. int_types = (int,)
  9. long = int
  10. def iteritems(d):
  11. return iter(d.items())
  12. def itervalues(d):
  13. return iter(d.values())
  14. else:
  15. # Python 2
  16. unicode = unicode_type = unicode
  17. basestring = basestring
  18. xrange = xrange
  19. int_types = (int, long)
  20. long = long
  21. def iteritems(d):
  22. return d.iteritems()
  23. def itervalues(d):
  24. return d.itervalues()