<s> from blitzdb . backends . file . utils import JsonEncoder <EOL> import json <EOL> import sys <EOL> import six <EOL> if six . PY3 : <EOL> import pickle as cPickle <EOL> else : <EOL> import cPickle <EOL> """<STR_LIT>""" <EOL> class JsonSerializer ( object ) : <EOL> @ classmethod <EOL> def serialize ( cls , data ) : <EOL> if six . PY3 : <EOL> if isinstance ( data , bytes ) : <EOL> return json . dumps ( data . decode ( '<STR_LIT:utf-8>' ) , cls = JsonEncoder , ensure_ascii = False ) . encode ( '<STR_LIT:utf-8>' ) <EOL> else : <EOL> return json . dumps ( data , cls = JsonEncoder , ensure_ascii = False ) . encode ( '<STR_LIT:utf-8>' ) <EOL> else : <EOL> return json . dumps ( data , cls = JsonEncoder , ensure_ascii = False ) . encode ( '<STR_LIT:utf-8>' ) <EOL> @ classmethod <EOL> def deserialize ( cls , data ) : <EOL> if six . PY3 : <EOL> return json . loads ( data . decode ( '<STR_LIT:utf-8>' ) ) <EOL> else : <EOL> return json . loads ( data . decode ( '<STR_LIT:utf-8>' ) ) <EOL> class PickleSerializer ( object ) : <EOL> @ classmethod <EOL> def serialize ( cls , data ) : <EOL> return cPickle . dumps ( data , cPickle . HIGHEST_PROTOCOL ) <EOL> @ classmethod <EOL> def deserialize ( cls , data ) : <EOL> return cPickle . loads ( data ) <EOL> try : <EOL> import cjson <EOL> class CJsonSerializer ( object ) : <EOL> @ classmethod <EOL> def serialize ( cls , data ) : <EOL> return cjson . encode ( data ) <EOL> @ classmethod <EOL> def deserialize ( cls , data ) : <EOL> return cjson . decode ( data ) <EOL> except ImportError : <EOL> pass </s>
