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