예제 #1
0
    def __setitem__(self, key, value):  # @ReservedAssignment
        if trace_queries:
            logger.debug('W %s' % str(key))

        self.check_existence()

        filename = self.filename_for_key(key)
        dirname = os.path.dirname(filename)
        if not os.path.exists(dirname):
            os.makedirs(dirname)
            
        protocol = pickle.HIGHEST_PROTOCOL
        try:
            paranoid = False
            if paranoid:        
                safe_pickle_dump(value, filename, protocol)
            else:
                with open(filename, 'wb') as f:
                    pickle.dump(value, f, protocol)

        except Exception as e:
            msg = ('Cannot set key %s: cannot pickle object '
                    'of class %s: %s' % (key, value.__class__.__name__, e))
            logger.error(msg)
            logger.exception(e)
            emsg = find_pickling_error(value)
            logger.error(emsg)
            raise SerializationError(msg + '\n' + emsg)
예제 #2
0
    def __setitem__(self, key, value):  # @ReservedAssignment
        if trace_queries:
            logger.debug('W %s' % str(key))

        self.check_existence()

        filename = self.filename_for_key(key)
        protocol = pickle.HIGHEST_PROTOCOL
        try:
#             paranoid = False
#             if paranoid or self.compress:  # safe_pickle_dump can take care of .gz
            safe_pickle_dump(value, filename, protocol)
#             else:
#                 if False:
#                     f = open(filename, 'wb', buffering=-1)
#                     pickle.dump(value, f, protocol)
#                 else:
#                     with open(filename, 'wb', buffering=-1) as f:
#                         pickle.dump(value, f, protocol)

        except Exception as e:
            msg = ('Cannot set key %s: cannot pickle object '
                    'of class %s: %s' % (key, value.__class__.__name__, e))
            logger.error(msg)
            logger.exception(e)
            emsg = find_pickling_error(value)
            logger.error(emsg)
            raise SerializationError(msg + '\n' + emsg)
예제 #3
0
    def __setitem__(self, key, value):  # @ReservedAssignment
        if trace_queries:
            logger.debug('W %s' % str(key))

        self.check_existence()

        filename = self.filename_for_key(key)

        try:
            safe_pickle_dump(value, filename)
            assert os.path.exists(filename)

        except BaseException as e:
            msg = ('Cannot set key %s: cannot pickle object '
                   'of class %s: %s' % (key, value.__class__.__name__, e))
            logger.error(msg)
            logger.exception(e)
            emsg = find_pickling_error(value)
            logger.error(emsg)
            raise SerializationError(msg + '\n' + emsg)
예제 #4
0
    def __setitem__(self, key, value):  # @ReservedAssignment
        if trace_queries:
            logger.debug('W %s' % str(key))

        self.check_existence()

        filename = self.filename_for_key(key)

        try:
            safe_pickle_dump(value, filename)
            assert os.path.exists(filename)
        except KeyboardInterrupt:
            raise
        except BaseException as e:
            msg = ('Cannot set key %s: cannot pickle object '
                   'of class %s: %s' % (key, value.__class__.__name__, e))
            logger.error(msg)
            logger.exception(e)
            emsg = find_pickling_error(value)
            logger.error(emsg)
            raise SerializationError(msg + '\n' + emsg)