Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/virtualenv/util/six.py @ 1:56ad4e20f292 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author | guerler |
---|---|
date | Fri, 31 Jul 2020 00:32:28 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:d30785e31577 | 1:56ad4e20f292 |
---|---|
1 """Backward compatibility layer with older version of six. | |
2 | |
3 This is used to avoid virtualenv requring a version of six newer than what | |
4 the system may have. | |
5 """ | |
6 from __future__ import absolute_import | |
7 | |
8 from six import PY2, PY3, binary_type, text_type | |
9 | |
10 try: | |
11 from six import ensure_text | |
12 except ImportError: | |
13 | |
14 def ensure_text(s, encoding="utf-8", errors="strict"): | |
15 """Coerce *s* to six.text_type. | |
16 For Python 2: | |
17 - `unicode` -> `unicode` | |
18 - `str` -> `unicode` | |
19 For Python 3: | |
20 - `str` -> `str` | |
21 - `bytes` -> decoded to `str` | |
22 """ | |
23 if isinstance(s, binary_type): | |
24 return s.decode(encoding, errors) | |
25 elif isinstance(s, text_type): | |
26 return s | |
27 else: | |
28 raise TypeError("not expecting type '%s'" % type(s)) | |
29 | |
30 | |
31 try: | |
32 from six import ensure_str | |
33 except ImportError: | |
34 | |
35 def ensure_str(s, encoding="utf-8", errors="strict"): | |
36 """Coerce *s* to `str`. | |
37 For Python 2: | |
38 - `unicode` -> encoded to `str` | |
39 - `str` -> `str` | |
40 For Python 3: | |
41 - `str` -> `str` | |
42 - `bytes` -> decoded to `str` | |
43 """ | |
44 if not isinstance(s, (text_type, binary_type)): | |
45 raise TypeError("not expecting type '%s'" % type(s)) | |
46 if PY2 and isinstance(s, text_type): | |
47 s = s.encode(encoding, errors) | |
48 elif PY3 and isinstance(s, binary_type): | |
49 s = s.decode(encoding, errors) | |
50 return s |