unicode.rst 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. .. _unicode:
  2. ===============
  3. Unicode in Salt
  4. ===============
  5. Though Unicode handling in large projects can often be complex, Salt adheres to
  6. several basic rules to help developers handle Unicode correctly.
  7. (For a basic introduction to this problem, see Ned Batchelder's
  8. `excellent intoroduction to the topic <http://nedbatchelder.com/text/unipain/unipain.html>`.
  9. Salt's basic workflow for Unicode handling is as follows:
  10. 1) Salt should convert whatever data is passed on CLI/API to Unicode.
  11. Internally, everything that Salt does should be Unicode unless it is
  12. printing to the screen or writing to storage.
  13. 2) Modules and various Salt pluggable systems use incoming data assuming Unicode.
  14. 2.1) For Salt modules that query an API; the module should convert the data
  15. received from the API into Unicode.
  16. 2.2) For Salt modules that shell out to get output; the module should
  17. convert data received into Unicode. (This does not apply if using the
  18. :mod:`cmd <salt.modules.cmdmod>` execution module, which should handle
  19. this for you.
  20. 2.3) For Salt modules which print directly to the console (not via an
  21. outputter) or which write directly to disk, a string should be encoded
  22. when appropriate. To handle this conversion, the global variable
  23. ``__salt_system_encoding__`` is available, which declares the locale of
  24. the system that Salt is running on.
  25. 3) When a function in a Salt module returns a string, it should return a
  26. ``unicode`` type in Python 2.
  27. 4) When Salt delivers the data to an outputter or a returner, it is the job of
  28. the outputter or returner to encode the Unicode before displaying it on the
  29. console or writing it to storage.