Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

35 linhas
736 B

  1. import sys
  2. from typing import Text # noqa
  3. PY2 = sys.version_info[0] == 2 # type: bool
  4. if PY2:
  5. from StringIO import StringIO # noqa
  6. else:
  7. from io import StringIO # noqa
  8. def to_env(text):
  9. # type: (Text) -> str
  10. """
  11. Encode a string the same way whether it comes from the environment or a `.env` file.
  12. """
  13. if PY2:
  14. return text.encode(sys.getfilesystemencoding() or "utf-8")
  15. else:
  16. return text
  17. def to_text(string):
  18. # type: (str) -> Text
  19. """
  20. Make a string Unicode if it isn't already.
  21. This is useful for defining raw unicode strings because `ur"foo"` isn't valid in
  22. Python 3.
  23. """
  24. if PY2:
  25. return string.decode("utf-8")
  26. else:
  27. return string