Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(540)

Side by Side Diff: recipe_engine/third_party/setuptools/unicode_utils.py

Issue 1344583003: Recipe package system. (Closed) Base URL: git@github.com:luci/recipes-py.git@master
Patch Set: Recompiled proto Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
OLDNEW
« no previous file with comments | « recipe_engine/third_party/setuptools/tests/test_upload_docs.py ('k') | recipe_engine/third_party/setuptools/utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698