diff options
Diffstat (limited to 'happybase/util.py')
-rw-r--r-- | happybase/util.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/happybase/util.py b/happybase/util.py index c697f90..f975464 100644 --- a/happybase/util.py +++ b/happybase/util.py @@ -69,7 +69,7 @@ def ensure_bytes(str_or_bytes, binary_type=six.binary_type, .format(type(str_or_bytes).__name__)) -def str_increment(s): +def bytes_increment(b): """Increment and truncate a byte string (for sorting purposes) This functions returns the shortest string that sorts after the given @@ -79,8 +79,10 @@ def str_increment(s): drops everything after it. If the string only contains ``0xFF`` bytes, `None` is returned. """ - for i in range(len(s) - 1, -1, -1): - if s[i] != '\xff': - return s[:i] + chr(ord(s[i]) + 1) - + assert isinstance(b, six.binary_type) + b = bytearray(b) # Used subset of its API is the same on Python 2 and 3. + for i in range(len(b) - 1, -1, -1): + if b[i] != 0xff: + b[i] += 1 + return bytes(b[:i+1]) return None |