How to use the klepto._pickle.dump function in klepto

To help you get started, we’ve selected a few klepto examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github uqfoundation / klepto / klepto / _archives.py View on Github external
def _store(self, key, value, input=False):
        "store output (and possibly input) in a subdirectory"
        _key = TEMP+hash(random(), 'md5')
        # create an input file when key is not suitable directory name
        if self._fname(key) != key: input=True #XXX: errors if protocol=0,1?
        # create a temporary directory, and dump the results
        try:
            _file = os.path.join(self._mkdir(_key), self._file)
            if input: _args = os.path.join(self._getdir(_key), self._args)
            if self.__state__['serialized']:
                protocol = self.__state__['protocol']
                if self.__state__['fast']:
                    protocol = None if type(protocol) is str else protocol
                    compression = self.__state__['compression']
                    _pickle.dump(value, _file, compress=compression,
                                               protocol=protocol)
                    if input: _pickle.dump(key, _args, compress=compression,
                                                       protocol=protocol)
                else:
                    if type(protocol) is str: #XXX: assumes json
                        pik,mode,kwd = json,'w',{}
                    else: #XXX: byref?
                        pik,mode,kwd = dill,'wb',{'protocol':protocol}
                    with open(_file, mode) as f:
                        pik.dump(value, f, **kwd)
                    if input:
                        with open(_args, mode) as f:
                            pik.dump(key, f, **kwd)
            else: # try to get an import for the object
                try: memo = getimportable(value, alias='memo', byname=False)
                except AttributeError: #XXX: HACKY... get classes by name
github uqfoundation / klepto / klepto / _archives.py View on Github external
"store output (and possibly input) in a subdirectory"
        _key = TEMP+hash(random(), 'md5')
        # create an input file when key is not suitable directory name
        if self._fname(key) != key: input=True #XXX: errors if protocol=0,1?
        # create a temporary directory, and dump the results
        try:
            _file = os.path.join(self._mkdir(_key), self._file)
            if input: _args = os.path.join(self._getdir(_key), self._args)
            if self.__state__['serialized']:
                protocol = self.__state__['protocol']
                if self.__state__['fast']:
                    protocol = None if type(protocol) is str else protocol
                    compression = self.__state__['compression']
                    _pickle.dump(value, _file, compress=compression,
                                               protocol=protocol)
                    if input: _pickle.dump(key, _args, compress=compression,
                                                       protocol=protocol)
                else:
                    if type(protocol) is str: #XXX: assumes json
                        pik,mode,kwd = json,'w',{}
                    else: #XXX: byref?
                        pik,mode,kwd = dill,'wb',{'protocol':protocol}
                    with open(_file, mode) as f:
                        pik.dump(value, f, **kwd)
                    if input:
                        with open(_args, mode) as f:
                            pik.dump(key, f, **kwd)
            else: # try to get an import for the object
                try: memo = getimportable(value, alias='memo', byname=False)
                except AttributeError: #XXX: HACKY... get classes by name
                    memo = getimportable(value, alias='memo')
                #XXX: class instances and such fail... abuse pickle here?