Device properties retrieved from pickle
5843
def read_dev_prop(self, device_name):
        
        with open("{}.bin".format(device_name), "rb") as file:
            return pickle.load(file)["device"]
695326
def dump(self, obj):
        ''''''
        pickle.dump(obj, self._file, protocol=self._protocol)
776085
def memory_dump():
    
    import cPickle
    dump = open("memory.pickle", 'w')
    for obj in gc.get_objects():
        i = id(obj)
        size = sys.getsizeof(obj, 0)
        #    referrers = [id(o) for o in gc.get_referrers(obj) if hasattr(o, '__class__')]
        referents = [id(o) for o in gc.get_referents(obj) if hasattr(o, '__class__')]
        if hasattr(obj, '__class__'):
            cls = str(obj.__class__)
            cPickle.dump({'id': i, 'class': cls, 'size': size, 'referents': referents}, dump)
647068
def pickle_load(name, extension='.pkl'):
    
    filename = name + extension
    infile = open(filename, 'rb')
    data = pickle.load(infile)
    infile.close()
    return data
499271
def obj2bytes(obj, pk_protocol=py23.pk_protocol):
    
    return pickle.dumps(obj, protocol=pk_protocol)
1362237
def pickle_load(fname):
    """"""
    assert type(fname) is str and os.path.exists(fname)
    print("loaded",fname)
    return pickle.load(open(fname,"rb"))
630512
def save_pickle(obj, outfile, protocol=2):
    
    with open(outfile, 'wb') as f:
        pickle.dump(obj, f, protocol=protocol)

    return outfile
1142983
def device_info(index=None):
    
    if index is None:
        return (device_info(i) for i in range(_pa.Pa_GetDeviceCount()))
    else:
        info = _pa.Pa_GetDeviceInfo(index)
        if not info:
            raise RuntimeError("Invalid device")
        assert info.structVersion == 2

        if 'DirectSound' in hostapi_info(info.hostApi)['name']:
            enc = 'mbcs'
        else:
            enc = 'utf-8'

        return {'name': ffi.string(info.name).decode(encoding=enc,
                                                     errors='ignore'),
                'hostapi': info.hostApi,
                'max_input_channels': info.maxInputChannels,
                'max_output_channels': info.maxOutputChannels,
                'default_low_input_latency': info.defaultLowInputLatency,
                'default_low_output_latency': info.defaultLowOutputLatency,
                'default_high_input_latency': info.defaultHighInputLatency,
                'default_high_output_latency': info.defaultHighOutputLatency,
                'default_samplerate': info.defaultSampleRate}
686043
def store(self):
        
        with open(self.filename, "wb") as f:
            pickle.dump(self, f)
1367028
def load(self):
        """"""
        if self.is_persisted:
            with open(self.file_name, 'rb') as f:
                self.object_property = pickle.load(f)
786601
def _pickle_batch(self):
        
        # Pickle
        payload = pickle.dumps(self.batch)

        # Pack Message
        header = struct.pack("!L", len(payload))
        message = header + payload

        # Return Message
        return message
539969
def register_pickle():
    """"""
    import cPickle
    registry.register('pickle', cPickle.dumps, cPickle.loads,
                      content_type='application/x-python-serialize',
                      content_encoding='binary')
499169
def to_pickle(self, filename):
        """"""
        with open(filename, 'wb') as f:
            pickle.dump(self, f)
1050028
def unpickle_dict(items):
    ''''''
    pickled_keys = items.pop('_pickled', '').split(',')
    ret = {}
    for key, val in items.items():
        if key in pickled_keys:
            ret[key] = pickle.loads(val)
        else:
            ret[key] = val
    return ret
781212
def pickle_f2m(pth, rt=None):
    
    r = rt
    try:
        with open(pth, 'rb') as f:
            r = pickle.load(f)
    except Exception as err:
        sys.stderr.write('pickle_f2m(pth={}) with error: {}\n'.format(pth, err))
    return r
1243669
def load_state(self, fname=None):
        """"""
        with open(fname, 'rb') as fh:
            self.state = pickle.load(fh)
1138292
def get(self, k, default=None):
        '''
        
        '''

        k = self._enckey(k)
        v = self._f.get(k, None)
        if v is None: return default
        return pickle.loads(v)