forked from Uninett/nav
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
25 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import pickle | ||
|
||
from django.conf import settings | ||
from django.core.exceptions import ImproperlyConfigured | ||
|
||
|
||
class PickleSerializer: | ||
""" | ||
Simple wrapper around pickle to be used in signing.dumps()/loads() and | ||
cache backends. | ||
""" | ||
|
||
def __init__(self, protocol=None): | ||
if settings.SESSION_ENGINE == 'django.contrib.sessions.backends.signed_cookies': | ||
raise ImproperlyConfigured( | ||
"PickleSerializer cannot be used with signed_cookies SESSION_ENGINE" | ||
) | ||
self.protocol = pickle.HIGHEST_PROTOCOL if protocol is None else protocol | ||
|
||
def dumps(self, obj): | ||
return pickle.dumps(obj, self.protocol) | ||
|
||
def loads(self, data): | ||
return pickle.loads(data) |