25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

42 lines
981 B

  1. import unicodedata
  2. import sys
  3. from setuptools.compat import unicode as decoded_string
  4. # HFS Plus uses decomposed UTF-8
  5. def decompose(path):
  6. if isinstance(path, decoded_string):
  7. return unicodedata.normalize('NFD', path)
  8. try:
  9. path = path.decode('utf-8')
  10. path = unicodedata.normalize('NFD', path)
  11. path = path.encode('utf-8')
  12. except UnicodeError:
  13. pass # Not UTF-8
  14. return path
  15. def filesys_decode(path):
  16. """
  17. Ensure that the given path is decoded,
  18. NONE when no expected encoding works
  19. """
  20. fs_enc = sys.getfilesystemencoding()
  21. if isinstance(path, decoded_string):
  22. return path
  23. for enc in (fs_enc, "utf-8"):
  24. try:
  25. return path.decode(enc)
  26. except UnicodeDecodeError:
  27. continue
  28. def try_encode(string, enc):
  29. "turn unicode encoding into a functional routine"
  30. try:
  31. return string.encode(enc)
  32. except UnicodeEncodeError:
  33. return None