Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/setuptools/unicode_utils.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
| author | shellac |
|---|---|
| date | Mon, 22 Mar 2021 18:12:50 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:4f3585e2f14b |
|---|---|
| 1 import unicodedata | |
| 2 import sys | |
| 3 | |
| 4 | |
| 5 # HFS Plus uses decomposed UTF-8 | |
| 6 def decompose(path): | |
| 7 if isinstance(path, str): | |
| 8 return unicodedata.normalize('NFD', path) | |
| 9 try: | |
| 10 path = path.decode('utf-8') | |
| 11 path = unicodedata.normalize('NFD', path) | |
| 12 path = path.encode('utf-8') | |
| 13 except UnicodeError: | |
| 14 pass # Not UTF-8 | |
| 15 return path | |
| 16 | |
| 17 | |
| 18 def filesys_decode(path): | |
| 19 """ | |
| 20 Ensure that the given path is decoded, | |
| 21 NONE when no expected encoding works | |
| 22 """ | |
| 23 | |
| 24 if isinstance(path, str): | |
| 25 return path | |
| 26 | |
| 27 fs_enc = sys.getfilesystemencoding() or 'utf-8' | |
| 28 candidates = fs_enc, 'utf-8' | |
| 29 | |
| 30 for enc in candidates: | |
| 31 try: | |
| 32 return path.decode(enc) | |
| 33 except UnicodeDecodeError: | |
| 34 continue | |
| 35 | |
| 36 | |
| 37 def try_encode(string, enc): | |
| 38 "turn unicode encoding into a functional routine" | |
| 39 try: | |
| 40 return string.encode(enc) | |
| 41 except UnicodeEncodeError: | |
| 42 return None |
