compat.py 621 B

1234567891011121314151617181920212223242526272829303132
  1. import sys
  2. __all__ = (
  3. 'text_type', 'string_types', 'izip', 'iteritems', 'itervalues',
  4. 'with_metaclass',
  5. )
  6. if sys.version_info[0] >= 3:
  7. text_type = str
  8. string_types = (str, )
  9. izip = zip
  10. def iteritems(o):
  11. return o.items()
  12. def itervalues(o):
  13. return o.values()
  14. else:
  15. text_type = unicode
  16. string_types = (basestring, )
  17. from itertools import izip
  18. def iteritems(o):
  19. return o.iteritems()
  20. def itervalues(o):
  21. return o.itervalues()
  22. def with_metaclass(meta, base=object):
  23. return meta("NewBase", (base,), {})