From ee9c620963553a3a959cdfc517f1e0818a21e9c0 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Mon, 23 Nov 2015 12:59:55 -0600 Subject: expose the PickleSerializer --- docs/api/session.rst | 1 + pyramid/session.py | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/docs/api/session.rst b/docs/api/session.rst index dde9d20e9..474e2bb32 100644 --- a/docs/api/session.rst +++ b/docs/api/session.rst @@ -17,4 +17,5 @@ .. autofunction:: BaseCookieSessionFactory + .. autoclass:: PickleSerializer diff --git a/pyramid/session.py b/pyramid/session.py index fa85fe69c..51f9de620 100644 --- a/pyramid/session.py +++ b/pyramid/session.py @@ -133,13 +133,25 @@ def check_csrf_token(request, return True class PickleSerializer(object): - """ A Webob cookie serializer that uses the pickle protocol to dump Python - data to bytes.""" + """ A serializer that uses the pickle protocol to dump Python + data to bytes. + + This is the default serializer used by Pyramid. + + ``protocol`` may be specified to control the version of pickle used. + Defaults to :attr:`pickle.HIGHEST_PROTOCOL`. + + """ + def __init__(self, protocol=pickle.HIGHEST_PROTOCOL): + self.protocol = protocol + def loads(self, bstruct): + """Accept bytes and return a Python object.""" return pickle.loads(bstruct) def dumps(self, appstruct): - return pickle.dumps(appstruct, pickle.HIGHEST_PROTOCOL) + """Accept a Python object and return bytes.""" + return pickle.dumps(appstruct, self.protocol) def BaseCookieSessionFactory( serializer, -- cgit v1.2.3