Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug causing bools (and other subclasses) to get incorrectly serialized #4

Merged
merged 1 commit into from
Mar 5, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions memcache.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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. 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 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 pass
elif isinstance(val, int): elif type(val) == int:
flags |= Client._FLAG_INTEGER flags |= Client._FLAG_INTEGER
val = "%d" % val val = "%d" % val
# force no attempt to compress this silly string. # force no attempt to compress this silly string.
min_compress_len = 0 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: else:
flags |= Client._FLAG_PICKLE flags |= Client._FLAG_PICKLE
file = BytesIO() file = BytesIO()
Expand Down Expand Up @@ -930,7 +929,7 @@ def send_cmd(self, cmd):
self.socket.sendall((cmd + '\r\n').encode('ascii')) self.socket.sendall((cmd + '\r\n').encode('ascii'))
else: else:
self.socket.sendall(cmd + '\r\n'.encode('ascii')) self.socket.sendall(cmd + '\r\n'.encode('ascii'))



def send_cmds(self, cmds): def send_cmds(self, cmds):
""" cmds already has trailing \r\n's applied """ """ cmds already has trailing \r\n's applied """
Expand Down