<s> import json <EOL> try : <EOL> import cPickle as pickle <EOL> except ImportError : <EOL> import pickle <EOL> class BaseSerializer ( object ) : <EOL> """<STR_LIT>""" <EOL> def dumps ( self , obj ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def loads ( self , string ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> class PickleSerializer ( BaseSerializer ) : <EOL> """<STR_LIT>""" <EOL> def dumps ( self , obj ) : <EOL> return pickle . dumps ( obj ) <EOL> def loads ( self , string ) : <EOL> if string is None : <EOL> return <EOL> return pickle . loads ( string ) <EOL> class JSONSerializer ( BaseSerializer ) : <EOL> """<STR_LIT>""" <EOL> def dumps ( self , obj ) : <EOL> return json . dumps ( obj ) <EOL> def loads ( self , string ) : <EOL> if string is None : <EOL> return <EOL> return json . loads ( string ) </s>
