diff options
| author | Ask Solem <ask@celeryproject.org> | 2012-08-29 15:46:46 +0100 |
|---|---|---|
| committer | Ask Solem <ask@celeryproject.org> | 2012-08-29 15:46:46 +0100 |
| commit | f1fe4e6881916e6993d7aa548f9d8601562a225e (patch) | |
| tree | 9a4bb4ef2c84bbbe916f1f60c54101ec2b6ea9da /kombu/serialization.py | |
| parent | c0244d514efe1694576683b6355ab123b809f620 (diff) | |
| parent | b7c5f069a42aa400fffdf3c49f626fe7871ab8e4 (diff) | |
| download | kombu-asynchronous-broadcasts.tar.gz | |
Merge branch 'master' into asynchronous-broadcastsasynchronous-broadcasts
Diffstat (limited to 'kombu/serialization.py')
| -rw-r--r-- | kombu/serialization.py | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/kombu/serialization.py b/kombu/serialization.py index 94a57ae1..5942408b 100644 --- a/kombu/serialization.py +++ b/kombu/serialization.py @@ -11,6 +11,7 @@ Serialization utilities. from __future__ import absolute_import import codecs +import os import sys import pickle as pypickle @@ -57,16 +58,24 @@ else: # cPickle.loads does not support buffer() objects, # but we can just create a StringIO and use load. if sys.version_info[0] == 3: - from io import StringIO + from io import BytesIO else: try: - from cStringIO import StringIO # noqa + from cStringIO import StringIO as BytesIO # noqa except ImportError: - from StringIO import StringIO # noqa + from StringIO import StringIO as BytesIO # noqa + +#: Kombu requires Python 2.5 or later so we use protocol 2 by default. +#: There's a new protocol (3) but this is only supported by Python 3. +pickle_protocol = int(os.environ.get('PICKLE_PROTOCOL', 2)) + +#: Kombu requires Python 2.5 or later so we use protocol 2 by default. +#: There's a new protocol (3) but this is only supported by Python 3. +pickle_protocol = int(os.environ.get('PICKLE_PROTOCOL', 2)) def pickle_loads(s, load=pickle_load): - return load(StringIO(s)) + return load(BytesIO(s)) class SerializerRegistry(object): @@ -327,7 +336,11 @@ else: def register_pickle(): """The fastest serialization method, but restricts you to python clients.""" - registry.register('pickle', pickle.dumps, unpickle, + + def dumps(obj, dumper=pickle.dumps): + return dumper(obj, protocol=pickle_protocol) + + registry.register('pickle', dumps, unpickle, content_type='application/x-python-serialize', content_encoding='binary') |
