Beispiel #1
0
    def realsave(self, obj):
        def _name(obj):
            try:
                name = getattr(obj, '__name__', None)
                if name is not None:
                    return ': %s' % name
            except Exception:
                pass

            return ''

        def _loc(obj):
            try:
                fn = getattr(obj, '__file__', None)
                if fn is not None:
                    return ' @%s' % (fn,)

                obj = getattr(obj, 'im_func', obj)
                code = getattr(obj, '__code__', None)
                if code is not None:
                    return ' @%s:%s' % (code.co_filename, code.co_firstlineno)
            except Exception:
                pass

            return ''

        try:
            Pickler.save(self, obj)
        except TypeError:
            logger.error('Failed to serialize %s%s%s',
                         type(obj), _name(obj), _loc(obj))
            raise
Beispiel #2
0
 def save(self, obj):
     desc = "object of type %s" % (describe_type(obj))
     # , describe_value(obj, 100))
     #  self.stack.append(describe_value(obj, 120))
     self.stack.append(desc)
     Pickler.save(self, obj)
     self.stack.pop()
Beispiel #3
0
    def realsave(self, obj):
        def _name(obj):
            try:
                name = getattr(obj, '__name__', None)
                if name is not None:
                    return ': %s' % name
            except Exception:
                pass

            return ''

        def _loc(obj):
            try:
                fn = getattr(obj, '__file__', None)
                if fn is not None:
                    return ' @%s' % (fn, )

                obj = getattr(obj, 'im_func', obj)
                code = getattr(obj, '__code__', None)
                if code is not None:
                    return ' @%s:%s' % (code.co_filename, code.co_firstlineno)
            except Exception:
                pass

            return ''

        try:
            Pickler.save(self, obj)
        except TypeError:
            logger.error('Failed to serialize %s%s%s', type(obj), _name(obj),
                         _loc(obj))
            raise
Beispiel #4
0
 def save(self, obj):
     desc = 'object of type %s' % (describe_type(obj))
     # , describe_value(obj, 100))
     # self.stack.append(describe_value(obj, 120))
     self.stack.append(desc)
     Pickler.save(self, obj)
     self.stack.pop()
Beispiel #5
0
 def save(self, filepath):
     to_save = {
         'regressor': self.regressor,
         'user_svd': self.user_svd,
         'item_svd': self.item_svd
     }
     with open(filepath, 'wb') as handle:
         saver = Pickler(handle, protocol=HIGHEST_PROTOCOL)
         saver.save(to_save)
Beispiel #6
0
    def save(self, obj):
        # Check the memo
        x = self.memo.get(id(obj))
        if x:
            self.write(self.get(x[0]))
            return

        if isinstance(obj, State):
            md = obj.__METADATA__
            typ = md['type']
            if typ == 'instance':
                self._state_instance(obj)
            elif typ in ['newobj', 'reduce']:
                self._state_reduce(obj)
            elif typ in ['class']:
                self._save_global(obj)
        else:
            Pickler.save(self, obj)
    def save(self, obj):
        # Check the memo
        x = self.memo.get(id(obj))
        if x:
            self.write(self.get(x[0]))
            return

        if isinstance(obj, State):
            md = obj.__METADATA__
            typ = md['type']
            if typ == 'instance':
                self._state_instance(obj)
            elif typ in ['newobj', 'reduce']:
                self._state_reduce(obj)
            elif typ in ['class']:
                self._save_global(obj)
        else:
            Pickler.save(self, obj)
Beispiel #8
0
 def save(self, o):
     self.depth += 1
     if self.depth == 1:
         return Pickler.save(self, o)
     self.depth -= 1
     return
Beispiel #9
0
 def save(self, filepath):
     with open(filepath, 'wb') as handle:
         saver = Pickler(handle, protocol=HIGHEST_PROTOCOL)
         saver.save(self.fm)