compat.py 805 B

1234567891011121314151617181920212223242526272829303132
  1. import sys
  2. if sys.version_info < (3,):
  3. def isbasestring(s):
  4. return isinstance(s, basestring)
  5. def open_utf8(filename, mode):
  6. return open(filename, mode)
  7. def byte_to_str(x):
  8. return str(ord(x))
  9. import cStringIO
  10. def StringIO():
  11. return cStringIO.StringIO()
  12. def encode_utf8(x):
  13. return x
  14. def iteritems(d):
  15. return d.iteritems()
  16. else:
  17. def isbasestring(s):
  18. return isinstance(s, (str, bytes))
  19. def open_utf8(filename, mode):
  20. return open(filename, mode, encoding="utf-8")
  21. def byte_to_str(x):
  22. return str(x)
  23. import io
  24. def StringIO():
  25. return io.StringIO()
  26. import codecs
  27. def encode_utf8(x):
  28. return codecs.utf_8_encode(x)[0]
  29. def iteritems(d):
  30. return iter(d.items())