<s> """<STR_LIT>""" <EOL> import zlib <EOL> import cPickle <EOL> try : <EOL> from cyordereddict import OrderedDict <EOL> except : <EOL> from collections import OrderedDict <EOL> def pack_blob ( obj ) : <EOL> return buffer ( zdumps ( obj ) ) <EOL> def unpack_genotype_blob ( blob ) : <EOL> return cPickle . loads ( zlib . decompress ( blob ) ) <EOL> def unpack_ordereddict_blob ( blob ) : <EOL> blob_val = cPickle . loads ( zlib . decompress ( blob ) ) <EOL> if blob_val is not None : <EOL> return OrderedDict ( blob_val ) <EOL> return None <EOL> def zdumps ( obj ) : <EOL> return zlib . compress ( cPickle . dumps ( obj , cPickle . HIGHEST_PROTOCOL ) , <NUM_LIT:9> ) <EOL> def zloads ( obj ) : <EOL> return cPickle . loads ( zlib . decompress ( obj ) ) <EOL> try : <EOL> import snappy <EOL> import numpy as np <EOL> except ImportError : <EOL> pass <EOL> lookup = { dt ( <NUM_LIT:1> ) . dtype . char : dt for dt in ( np . uint8 , np . uint32 , np . int32 , <EOL> np . float32 , np . int64 , np . float64 , np . bool_ ) } <EOL> SEP = '<STR_LIT>' <EOL> def snappy_pack_blob ( obj , sep = SEP ) : <EOL> if obj is None : return '<STR_LIT>' <EOL> c = obj . dtype . char <EOL> if c == '<STR_LIT:S>' : return '<STR_LIT:S>' + snappy . compress ( sep . join ( obj ) ) <EOL> return buffer ( c + snappy . compress ( obj . tobytes ( ) ) ) <EOL> def snappy_unpack_blob ( blob , sep = SEP ) : <EOL> if len ( blob ) == <NUM_LIT:0> : return None <EOL> if blob [ <NUM_LIT:0> ] == '<STR_LIT:S>' : <EOL> return np . array ( snappy . decompress ( blob [ <NUM_LIT:1> : ] ) . split ( sep ) ) <EOL> dt = lookup [ blob [ <NUM_LIT:0> ] ] <EOL> arr = np . frombuffer ( snappy . decompress ( blob [ <NUM_LIT:1> : ] ) , dtype = dt ) <EOL> if blob [ <NUM_LIT:0> ] == '<STR_LIT:?>' : <EOL> arr . setflags ( write = True ) <EOL> return arr <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> import doctest <EOL> print ( doctest . testmod ( ) ) </s>
