-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathserialization.py
More file actions
37 lines (28 loc) · 918 Bytes
/
serialization.py
File metadata and controls
37 lines (28 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"Mixins for serializing objects."
import json
try:
import cPickle as pickle
except ImportError:
import _pickle as pickle
class PassThroughSerializer(object):
"Don't serialize."
def serialize(self, obj):
"Support for serializing objects stored in Redis."
return obj
def deserialize(self, obj):
"Support for deserializing objects stored in Redis."
return obj
class PickleSerializer(PassThroughSerializer):
"Serialize values using pickle."
def serialize(self, obj):
return pickle.dumps(obj)
def deserialize(self, obj):
"Deserialize values using pickle."
return pickle.loads(obj)
class JSONSerializer(PassThroughSerializer):
"Serialize values using JSON."
def serialize(self, obj):
return json.dumps(obj)
def deserialize(self, obj):
"Deserialize values using JSON."
return json.loads(obj)