Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
"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?