Permalink
Browse files

Fix serialization of int/str subclasses, e.g. bool

Without this fix, bools would be deserialized as ints, e.g.
getting a key that was set as True would return 1.
  • Loading branch information...
1 parent df8d5c6 commit 5b9926cff18a7e4427ff12c032ad39f12c950a86 Marshall Quander committed Feb 6, 2013
Showing with 7 additions and 8 deletions.
  1. +7 −8 memcache.py
View
@@ -635,18 +635,17 @@ def _val_to_store_info(self, val, min_compress_len):
Transform val to a storable representation, returning a tuple of the flags, the length of the new value, and the new value itself.
"""
flags = 0
- if isinstance(val, str):
+
+ # check types exactly rather than using isinstance, or subclasses
+ # will be deserialized into instances of the parent class
+ # (most blatantly, bool --> int)
+ if type(val) == str:
pass
- elif isinstance(val, int):
+ elif type(val) == int:
flags |= Client._FLAG_INTEGER
val = "%d" % val
# force no attempt to compress this silly string.
min_compress_len = 0
- elif isinstance(val, int):
- flags |= Client._FLAG_LONG
- val = "%d" % val
- # force no attempt to compress this silly string.
- min_compress_len = 0
else:
flags |= Client._FLAG_PICKLE
file = BytesIO()
@@ -930,7 +929,7 @@ def send_cmd(self, cmd):
self.socket.sendall((cmd + '\r\n').encode('ascii'))
else:
self.socket.sendall(cmd + '\r\n'.encode('ascii'))
-
+
def send_cmds(self, cmds):
""" cmds already has trailing \r\n's applied """

0 comments on commit 5b9926c

Please sign in to comment.