Skip to content

Commit

Permalink
compat: rework how bstr() is defined
Browse files Browse the repository at this point in the history
Arrange for `bstr()` to be defined as a function for Python 3 only.
Avoid exception by checking the Python version explicitly.

Set `bstr = bytes` for modern Python2 and use `str` for historical
Pythons.

Related-to: git-cola#589
Signed-off-by: David Aguilar <davvid@gmail.com>
  • Loading branch information
davvid committed Aug 22, 2016
1 parent f8cdf8a commit 12c7668
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions cola/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@

PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] >= 3
PY26_PLUS = PY2 and sys.version_info[1] >= 6
WIN32 = sys.platform == 'win32' or sys.platform == 'cygwin'

try:
if PY3:
def bstr(x):
# pylint: disable=bytes-builtin
return bytes(x, encoding='utf8')
elif PY26_PLUS:
# pylint: disable=bytes-builtin
bytes()
if PY3:
def bstr(x):
return bytes(x, encoding='latin1')
else:
bstr = bytes
except NameError:
bstr = bytes
else:
# Python <= 2.5
bstr = str

Expand Down

0 comments on commit 12c7668

Please sign in to comment.