mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Replace five with six
This commit is contained in:
parent
cb8dd335f4
commit
c65a11ce3d
9 changed files with 27 additions and 57 deletions
|
|
@ -1,42 +1,14 @@
|
|||
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
|
||||
string_types = (text, bytes)
|
||||
|
||||
def n(s):
|
||||
if isinstance(s, bytes):
|
||||
return s
|
||||
else:
|
||||
return s.encode('UTF-8')
|
||||
|
||||
exec("""def reraise(tp, value, tb=None):
|
||||
raise tp, value, tb
|
||||
""")
|
||||
else: # pragma: no cover (PY3 only)
|
||||
text = str
|
||||
string_types = (text,)
|
||||
|
||||
def n(s):
|
||||
if isinstance(s, text):
|
||||
return s
|
||||
else:
|
||||
return s.decode('UTF-8')
|
||||
|
||||
def reraise(tp, value, tb=None):
|
||||
if value is None:
|
||||
value = tp()
|
||||
if value.__traceback__ is not tb:
|
||||
raise value.with_traceback(tb)
|
||||
raise value
|
||||
import six
|
||||
|
||||
|
||||
def to_text(s):
|
||||
return s if isinstance(s, text) else s.decode('UTF-8')
|
||||
return s if isinstance(s, six.text_type) else s.decode('UTF-8')
|
||||
|
||||
|
||||
def to_bytes(s):
|
||||
return s if isinstance(s, bytes) else s.encode('UTF-8')
|
||||
|
||||
|
||||
n = to_bytes if six.PY2 else to_text
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue