compatibility.py 443 B

12345678910111213141516171819202122
  1. # coding:utf-8
  2. import sys
  3. PY3 = sys.version_info[0] == 3
  4. if PY3:
  5. text_type = str
  6. binary_type = bytes
  7. else:
  8. text_type = unicode
  9. binary_type = str
  10. def text_(s, encoding='utf-8', errors='strict'):
  11. if isinstance(s, binary_type):
  12. return s.decode(encoding, errors)
  13. return s
  14. def bytes_(s, encoding='utf-8', errors='strict'):
  15. if isinstance(s, text_type):
  16. return s.encode(encoding, errors)
  17. return s