Browse files

Use StringIO instead of BytesIO for Python 2.5

  • Loading branch information...
1 parent 9b67020 commit 54607873bcc1284912f93005136bb739aab9b0da Mark Costello committed Mar 22, 2013
Showing with 14 additions and 2 deletions.
  1. +14 −2 rdbtools/parser.py
View
16 rdbtools/parser.py
@@ -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 :

0 comments on commit 5460787

Please sign in to comment.