Skip to content

Commit

Permalink
Use StringIO instead of BytesIO for Python 2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Costello committed Mar 22, 2013
1 parent 9b67020 commit 5460787
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions rdbtools/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,20 @@ def read_ziplist_entry(self, f) :

def read_zipmap(self, f) :
raw_string = self.read_string(f)
raw_byte_arr = array.array('B', raw_string)
buff = io.BytesIO(raw_byte_arr.tostring())
bytearray_present = True
try:
raw_byte_arr = bytearray(raw_string)
except NameError:
raw_byte_arr = array.array('B', raw_string)
bytearray_present = False
if bytearray_present:
byte_str = str(raw_byte_arr)
else:
byte_str = raw_byte_arr.tostring()
try:
buff = io.BytesIO(byte_str)
except AttributeError:
buff = io.StringIO(byte_str)
num_entries = read_unsigned_char(buff)
self._callback.start_hash(self._key, num_entries, self._expiry, info={'encoding':'zipmap', 'sizeof_value':len(raw_string)})
while True :
Expand Down

0 comments on commit 5460787

Please sign in to comment.