forked from pre-commit/pre-commit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfive.py
More file actions
33 lines (23 loc) · 678 Bytes
/
five.py
File metadata and controls
33 lines (23 loc) · 678 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from __future__ import unicode_literals
PY2 = str is bytes
PY3 = str is not bytes
if PY2: # pragma: no cover (PY2 only)
text = unicode # flake8: noqa
def n(s):
if isinstance(s, bytes):
return s
else:
return s.encode('UTF-8')
defaults_attr = 'func_defaults'
else: # pragma: no cover (PY3 only)
text = str
def n(s):
if isinstance(s, text):
return s
else:
return s.decode('UTF-8')
defaults_attr = '__defaults__'
def to_text(s):
return s if isinstance(s, text) else s.decode('UTF-8')
def to_bytes(s):
return s if isinstance(s, bytes) else s.encode('UTF-8')