Skip to content

Commit

Permalink
Python 3.4 doesn't have bytes.hex() or bytes.encode()
Browse files Browse the repository at this point in the history
so use binascii.hexlify() for everything below Python 3.5
  • Loading branch information
PoByBolek committed Apr 26, 2019
1 parent 06b6b8e commit 8395a96
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions xapian_backend.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import unicode_literals

import binascii
import datetime
import pickle
import os
Expand Down Expand Up @@ -1619,11 +1620,11 @@ def strf(dt):
# So we encode the byte string as hex characters instead which have the
# same sort order as the actual bytes.
if hasattr(value, 'hex'):
# Convert the bytes to a hex string in Python 3.
# Convert the bytes to a hex string in Python 3.5+.
value = value.hex().lower()
else:
# Convert the bytes to a hex string in Python 2.
value = value.encode('hex').lower()
# Convert the bytes to a hex string in Python 2 and 3.4.
value = binascii.hexlify(value).decode('ascii').lower()
elif field_type == 'date' or field_type == 'datetime':
if field_type == 'date':
# http://stackoverflow.com/a/1937636/931303 and comments
Expand Down

0 comments on commit 8395a96

Please sign in to comment.