You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
617B

  1. from gitdb.utils import compat
  2. if compat.PY3:
  3. string_types = (str, )
  4. text_type = str
  5. else:
  6. string_types = (basestring, )
  7. text_type = unicode
  8. def force_bytes(data, encoding="ascii"):
  9. if isinstance(data, bytes):
  10. return data
  11. if isinstance(data, string_types):
  12. return data.encode(encoding)
  13. return data
  14. def force_text(data, encoding="utf-8"):
  15. if isinstance(data, text_type):
  16. return data
  17. if isinstance(data, bytes):
  18. return data.decode(encoding)
  19. if compat.PY3:
  20. return text_type(data, encoding)
  21. else:
  22. return text_type(data)