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

Use only the highest, premium quality pickler available at runtime. #156

Merged
merged 1 commit into from
Jun 2, 2017
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
10 changes: 9 additions & 1 deletion pymemcache/serde.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
FLAG_COMPRESSED = 1 << 3 # unused, to main compatability with python-memcached
FLAG_TEXT = 1 << 4

# Pickle protocol version (-1 for highest available to runtime)
# Warning with `0`: If somewhere in your value lies a slotted object,
# ie defines `__slots__`, even if you do not include it in your pickleable
# state via `__getstate__`, python will complain with something like:
# TypeError: a class that defines __slots__ without defining __getstate__
# cannot be pickled
PICKLE_VERSION = -1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because -1 is always the highest protocol.

Copy link
Contributor Author

@akatrevorjay akatrevorjay Jun 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can use the const if you want, but using -1 is pretty standard imo and doesn't have an attr lookup tax (which is of course not worth mentioning though)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, in python 3 the default is the new py3+ pickle. But in pymemcache, we always use zero and it unfortunately is a pretty broken version :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cgordon looks like you added this originally any specific reason for the old behavior? Looks like this is based on https://github.com/linsomniac/python-memcached/blob/5b75728565393d53768f4622fdd43e3e742c4741/memcache.py

Also this is a a backwards incompatible change.

Perhaps it would be better to make this field an argument that can be set?



def python_memcache_serializer(key, value):
flags = 0
Expand All @@ -55,7 +63,7 @@ def python_memcache_serializer(key, value):
else:
flags |= FLAG_PICKLE
output = BytesIO()
pickler = pickle.Pickler(output, 0)
pickler = pickle.Pickler(output, PICKLE_VERSION)
pickler.dump(value)
value = output.getvalue()

Expand Down