Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/virtualenv/util/six.py @ 0:26e78fe6e8c4 draft
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author | shellac |
---|---|
date | Sat, 02 May 2020 07:14:21 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:26e78fe6e8c4 |
---|---|
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 |