예제 #1
0
    def load(self):
        """Read a pickled object representation from the open file.

        Return the reconstituted object hierarchy specified in the file.
        """
        # Check whether Unpickler was initialized correctly. This is
        # only needed to mimic the behavior of _pickle.Unpickler.dump().
        if not hasattr(self, "_file_read"):
            raise pickle.UnpicklingError(
                "Unpickler.__init__() was not called by "
                "%s.__init__()" % (self.__class__.__name__, ))
        self._unframer = pickle._Unframer(self._file_read, self._file_readline)
        self.read = self._unframer.read
        self.readline = self._unframer.readline
        self.mark = object()  # any new unique object
        self.metastack = []  # for compatability with Python 3.6
        self.stack = []
        self.append = self.stack.append
        self.proto = 0
        read = self.read
        dispatch = self.dispatch
        if self.call_back is not None:
            self.call_back('Loading...')
            self.call_back(0, os.path.getsize(self.path))
            cur = 0
        n = 0
        try:
            while True:
                n += 1
                if n == 1024:
                    n = 0
                    if self.stop_check is not None and self.stop_check():
                        self.file.close()
                        raise pickle._Stop(None)
                    if self.call_back is not None:
                        cur += 1
                        self.call_back(cur)
                key = read(1)
                if not key:
                    raise EOFError
                assert isinstance(key, (bytes, bytearray))
                dispatch[key[0]](self)
        except pickle._Stop as stopinst:
            return stopinst.value
예제 #2
0
    def load(self):
        """Read a pickled object representation from the open file.

        Return the reconstituted object hierarchy specified in the file.
        """
        # Check whether Unpickler was initialized correctly. This is
        # only needed to mimic the behavior of _pickle.Unpickler.dump().
        if not hasattr(self, "_file_read"):
            raise pickle.UnpicklingError("Unpickler.__init__() was not called by "
                                  "%s.__init__()" % (self.__class__.__name__,))
        self._unframer = pickle._Unframer(self._file_read, self._file_readline)
        self.read = self._unframer.read
        self.readline = self._unframer.readline
        self.mark = object()  # any new unique object
        self.metastack = [] # for compatability with Python 3.6
        self.stack = []
        self.append = self.stack.append
        self.proto = 0
        read = self.read
        dispatch = self.dispatch
        if self.call_back is not None:
            self.call_back('Loading...')
            self.call_back(0, os.path.getsize(self.path))
            cur = 0
        n = 0
        try:
            while True:
                n+=1
                if n == 1024:
                    n = 0
                    if self.stop_check is not None and self.stop_check():
                        self.file.close()
                        raise pickle._Stop(None)
                    if self.call_back is not None:
                        cur += 1
                        self.call_back(cur)
                key = read(1)
                if not key:
                    raise EOFError
                assert isinstance(key, (bytes, bytearray))
                dispatch[key[0]](self)
        except pickle._Stop as stopinst:
            return stopinst.value
예제 #3
0
 def load_stop(self):
     value = self.stack.pop()
     value = self.finalize(value)
     raise pickle._Stop(value)
예제 #4
0
 async def load_stop(self):
     value = self.stack.pop()
     raise _Stop(value)
예제 #5
0
 def load_stop(self):
     value = self.stack.pop()
     value = self.finalize(value)
     raise pickle._Stop(value)