From 20a29096d2c2721262c44151dfed21e97aebe4f4 Mon Sep 17 00:00:00 2001 From: SE2Dev Date: Sun, 14 Jan 2018 18:14:48 -0500 Subject: [PATCH] Fix byte2int() for Python 3 Provides a fix for byte2int() using the Python 2 implemention on Python 3 when the "six" module isn't present --- _lz4.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/_lz4.py b/_lz4.py index f6a3965..254e515 100644 --- a/_lz4.py +++ b/_lz4.py @@ -12,8 +12,15 @@ except ImportError: xrange = range - def byte2int(_bytes): - return ord(_bytes[0]) + # If we're running Python 3 or newer, we must + # define byte2int differently than with Python 2 + import sys + if sys.version_info[0] >= 3: + import operator + byte2int = operator.itemgetter(0) + else: + def byte2int(_bytes): + return ord(_bytes[0]) class CorruptError(Exception): pass