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