Python pickle.Unpickler() Examples

The following are code examples for showing how to use pickle.Unpickler(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: 3D-HourGlass-Network   Author: Naman-ntc   File: inflateScript.py    MIT License 6 votes vote down vote up
def inflate(opt = None):
	if opt is not None:
		model3d = HourglassNet3D(opt.nChannels, opt.nStack, opt.nModules, opt.numReductions, ref.nJoints)
		Inflate.nChannels = opt.nChannels
		Inflate.nStack = opt.nStack
		Inflate.nModules = opt.nModules
		Inflate.nRegFrames = opt.nRegFrames
		Inflate.nJoints = ref.nJoints
	else :
		model3d = HourglassNet3D()
	pickle.Unpickler = partial(pickle.Unpickler, encoding="latin1")
	pickle.load = partial(pickle.load, encoding="latin1")
	if opt is not None:
		model = torch.load(opt.Model2D)
	else:
		model = torch.load('models/hgreg-3d.pth') #, map_location=lambda storage, loc: storage)

	Inflate.inflateHourglassNet(model3d, model)

	torch.save(model3d,open('inflatedModel.pth','wb'))

	return model3d 
Example 2
Project: D-VAE   Author: muhanzhang   File: pkl_utils.py    MIT License 6 votes vote down vote up
def load(f, persistent_load=PersistentNdarrayLoad):
    """Load a file that was dumped to a zip file.

    :param f: The file handle to the zip file to load the object from.
    :type f: file

    :param persistent_load: The persistent loading function to use for
        unpickling. This must be compatible with the `persisten_id` function
        used when pickling.
    :type persistent_load: callable, optional

    .. versionadded:: 0.8
    """
    with closing(zipfile.ZipFile(f, 'r')) as zip_file:
        p = pickle.Unpickler(BytesIO(zip_file.open('pkl').read()))
        p.persistent_load = persistent_load(zip_file)
        return p.load() 
Example 3
Project: pyblish-win   Author: pyblish   File: shelve.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def __getitem__(self, key):
        try:
            value = self.cache[key]
        except KeyError:
            f = StringIO(self.dict[key])
            value = Unpickler(f).load()
            if self.writeback:
                self.cache[key] = value
        return value 
Example 4
Project: pyblish-win   Author: pyblish   File: shelve.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def set_location(self, key):
        (key, value) = self.dict.set_location(key)
        f = StringIO(value)
        return (key, Unpickler(f).load()) 
Example 5
Project: pyblish-win   Author: pyblish   File: shelve.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def next(self):
        (key, value) = self.dict.next()
        f = StringIO(value)
        return (key, Unpickler(f).load()) 
Example 6
Project: pyblish-win   Author: pyblish   File: shelve.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def previous(self):
        (key, value) = self.dict.previous()
        f = StringIO(value)
        return (key, Unpickler(f).load()) 
Example 7
Project: pyblish-win   Author: pyblish   File: shelve.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def first(self):
        (key, value) = self.dict.first()
        f = StringIO(value)
        return (key, Unpickler(f).load()) 
Example 8
Project: pyblish-win   Author: pyblish   File: test_pickle.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def loads(self, buf):
        f = StringIO(buf)
        u = pickle.Unpickler(f)
        return u.load() 
Example 9
Project: pyblish-win   Author: pyblish   File: test_pickle.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def loads(self, buf):
        class PersUnpickler(pickle.Unpickler):
            def persistent_load(subself, obj):
                return self.persistent_load(obj)
        f = StringIO(buf)
        u = PersUnpickler(f)
        return u.load() 
Example 10
Project: FalltoSkyBot   Author: Sakiut   File: casino.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def start():
	if os.path.exists(fileName):
		f = open(fileName, "rb")
		d = pickle.Unpickler(f)
		data = d.load()
		f.close()
	else:
		data = {}

	return data

######################################################################################################################## 
Example 11
Project: FalltoSkyBot   Author: Sakiut   File: moderation.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def start():
	if os.path.exists(fileName):
		f = open(fileName, "rb")
		d = pickle.Unpickler(f)
		data = d.load()
		f.close()
	else:
		data = {}

	return data

##################################################################################################################################################### 
Example 12
Project: WhooshSearch   Author: rokartnaz   File: loading.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def __init__(self, f, objmap, shortcuts=None):
        pickle.Unpickler.__init__(self, f)

        if shortcuts:
            objmap = dict((k % shortcuts, v % shortcuts)
                          for k, v in objmap.items())
        self._objmap = objmap 
Example 13
Project: 3D-HourGlass-Network   Author: Naman-ntc   File: inflateScript.py    MIT License 5 votes vote down vote up
def inflate(opt = None):
	if opt is not None:
		model3d = Pose3D(opt.nChannels, opt.nStack, opt.nModules, opt.numReductions, opt.nRegModules, opt.nRegFrames, ref.nJoints, ref.temporal)
		Inflate.nChannels = opt.nChannels
		Inflate.nStack = opt.nStack
		Inflate.nModules = opt.nModules
		Inflate.nRegFrames = opt.nRegFrames
		Inflate.nJoints = ref.nJoints
		Inflate.scheme = opt.scheme
		Inflate.mult = opt.mult
	else :
		opt = opts().parse()
		Inflate.nChannels = opt.nChannels
		Inflate.nStack = opt.nStack
		Inflate.nModules = opt.nModules
		Inflate.nRegFrames = opt.nRegFrames
		Inflate.nJoints = ref.nJoints
		Inflate.scheme = opt.scheme
		model3d = Pose3D(opt.nChannels, opt.nStack, opt.nModules, opt.numReductions, opt.nRegModules, opt.nRegFrames, ref.nJoints, ref.temporal)
	pickle.Unpickler = partial(pickle.Unpickler, encoding="latin1")
	pickle.load = partial(pickle.load, encoding="latin1")
	if opt is not None:
		model = torch.load(opt.Model2D)
	else:
		model = torch.load('models/xingy.pth') #, map_location=lambda storage, loc: storage)

	Inflate.inflatePose3D(model3d, model)

	torch.save(model3d,open('inflatedModel.pth','wb'))

	return model3d


#inflate() 
Example 14
Project: NiujiaoDebugger   Author: MrSrc   File: shelve.py    GNU General Public License v3.0 5 votes vote down vote up
def __getitem__(self, key):
        try:
            value = self.cache[key]
        except KeyError:
            f = BytesIO(self.dict[key.encode(self.keyencoding)])
            value = Unpickler(f).load()
            if self.writeback:
                self.cache[key] = value
        return value 
Example 15
Project: NiujiaoDebugger   Author: MrSrc   File: shelve.py    GNU General Public License v3.0 5 votes vote down vote up
def set_location(self, key):
        (key, value) = self.dict.set_location(key)
        f = BytesIO(value)
        return (key.decode(self.keyencoding), Unpickler(f).load()) 
Example 16
Project: NiujiaoDebugger   Author: MrSrc   File: shelve.py    GNU General Public License v3.0 5 votes vote down vote up
def next(self):
        (key, value) = next(self.dict)
        f = BytesIO(value)
        return (key.decode(self.keyencoding), Unpickler(f).load()) 
Example 17
Project: NiujiaoDebugger   Author: MrSrc   File: shelve.py    GNU General Public License v3.0 5 votes vote down vote up
def previous(self):
        (key, value) = self.dict.previous()
        f = BytesIO(value)
        return (key.decode(self.keyencoding), Unpickler(f).load()) 
Example 18
Project: NiujiaoDebugger   Author: MrSrc   File: shelve.py    GNU General Public License v3.0 5 votes vote down vote up
def first(self):
        (key, value) = self.dict.first()
        f = BytesIO(value)
        return (key.decode(self.keyencoding), Unpickler(f).load()) 
Example 19
Project: recruit   Author: Frank-qlu   File: pickle_compat.py    Apache License 2.0 5 votes vote down vote up
def find_class(self, module, name):
            # override superclass
            key = (module, name)
            module, name = _class_locations_map.get(key, key)
            return super(Unpickler, self).find_class(module, name) 
Example 20
Project: recruit   Author: Frank-qlu   File: pickle_compat.py    Apache License 2.0 5 votes vote down vote up
def load(fh, encoding=None, compat=False, is_verbose=False):
    """load a pickle, with a provided encoding

    if compat is True:
       fake the old class hierarchy
       if it works, then return the new type objects

    Parameters
    ----------
    fh : a filelike object
    encoding : an optional encoding
    compat : provide Series compatibility mode, boolean, default False
    is_verbose : show exception output
    """

    try:
        fh.seek(0)
        if encoding is not None:
            up = Unpickler(fh, encoding=encoding)
        else:
            up = Unpickler(fh)
        up.is_verbose = is_verbose

        return up.load()
    except (ValueError, TypeError):
        raise 
Example 21
Project: rainmachine-developer-resources   Author: sprinkler   File: rmParserUserData.py    GNU General Public License v3.0 5 votes vote down vote up
def RMUserData_convertFromSQLite(data):
    if data == None:
        return None

    inputStream = StringIO(data)
    unpickler = pickle.Unpickler(inputStream)
    return unpickler.load() 
Example 22
Project: rainmachine-developer-resources   Author: sprinkler   File: rmParserParams.py    GNU General Public License v3.0 5 votes vote down vote up
def RMParserParams_convertFromSQLite(data):
    if data == None:
        return None

    inputStream = StringIO(data)
    unpickler = pickle.Unpickler(inputStream)
    return unpickler.load() 
Example 23
Project: FUTU_Stop_Loss   Author: BigtoC   File: pickle_compat.py    MIT License 5 votes vote down vote up
def find_class(self, module, name):
            # override superclass
            key = (module, name)
            module, name = _class_locations_map.get(key, key)
            return super(Unpickler, self).find_class(module, name) 
Example 24
Project: FUTU_Stop_Loss   Author: BigtoC   File: pickle_compat.py    MIT License 5 votes vote down vote up
def load(fh, encoding=None, compat=False, is_verbose=False):
    """load a pickle, with a provided encoding

    if compat is True:
       fake the old class hierarchy
       if it works, then return the new type objects

    Parameters
    ----------
    fh: a filelike object
    encoding: an optional encoding
    compat: provide Series compatibility mode, boolean, default False
    is_verbose: show exception output
    """

    try:
        fh.seek(0)
        if encoding is not None:
            up = Unpickler(fh, encoding=encoding)
        else:
            up = Unpickler(fh)
        up.is_verbose = is_verbose

        return up.load()
    except:
        raise 
Example 25
Project: ironpython2   Author: IronLanguages   File: shelve.py    Apache License 2.0 5 votes vote down vote up
def __getitem__(self, key):
        try:
            value = self.cache[key]
        except KeyError:
            f = StringIO(self.dict[key])
            value = Unpickler(f).load()
            if self.writeback:
                self.cache[key] = value
        return value 
Example 26
Project: ironpython2   Author: IronLanguages   File: shelve.py    Apache License 2.0 5 votes vote down vote up
def set_location(self, key):
        (key, value) = self.dict.set_location(key)
        f = StringIO(value)
        return (key, Unpickler(f).load()) 
Example 27
Project: ironpython2   Author: IronLanguages   File: shelve.py    Apache License 2.0 5 votes vote down vote up
def next(self):
        (key, value) = self.dict.next()
        f = StringIO(value)
        return (key, Unpickler(f).load()) 
Example 28
Project: ironpython2   Author: IronLanguages   File: shelve.py    Apache License 2.0 5 votes vote down vote up
def previous(self):
        (key, value) = self.dict.previous()
        f = StringIO(value)
        return (key, Unpickler(f).load()) 
Example 29
Project: ironpython2   Author: IronLanguages   File: shelve.py    Apache License 2.0 5 votes vote down vote up
def first(self):
        (key, value) = self.dict.first()
        f = StringIO(value)
        return (key, Unpickler(f).load()) 
Example 30
Project: ironpython2   Author: IronLanguages   File: test_pickle.py    Apache License 2.0 5 votes vote down vote up
def loads(self, buf):
        f = StringIO(buf)
        u = pickle.Unpickler(f)
        return u.load() 
Example 31
Project: ironpython2   Author: IronLanguages   File: test_pickle.py    Apache License 2.0 5 votes vote down vote up
def loads(self, buf):
        f = StringIO(buf)
        u = pickle.Unpickler(f)
        return u.load() 
Example 32
Project: ironpython2   Author: IronLanguages   File: test_pickle.py    Apache License 2.0 5 votes vote down vote up
def loads(self, buf):
        class PersUnpickler(pickle.Unpickler):
            def persistent_load(subself, obj):
                return self.persistent_load(obj)
        f = StringIO(buf)
        u = PersUnpickler(f)
        return u.load() 
Example 33
Project: ironpython2   Author: IronLanguages   File: test_cPickle.py    Apache License 2.0 5 votes vote down vote up
def test_unpickler(self, module=cPickle, verbose=True):
        s = StringIO()
        TestBank.selph = self
        for test in TestBank.tests:
            obj, pickle_lists, display_name = TestBank.normalize(test)
            expected = normalized_repr(obj)

            if verbose: print "Testing %s..." % display_name,

            for proto in range(3):
                if proto not in pickle_lists:
                    continue

                if verbose: print proto,

                pickles = pickle_lists[proto]
                if not isinstance(pickles, tuple):
                    pickles = (pickles,)

                pickle_num = 0

                for pickle in pickles:
                    unpickler = module.Unpickler(s)
                    s.truncate(0)
                    s.write(pickle.replace('<', '').replace('>', ''))
                    s.seek(0)
                    unpickled_obj = unpickler.load()
                    actual = normalized_repr(unpickled_obj)

                    if expected != actual:
                        print
                        self.fail('Wrong unpickled value:\n'
                            'with pickle %d %r\n'
                            'expected\n'
                            '%r, got\n'
                            '%r' % (pickle_num, pickle, expected, actual))

                    pickle_num += 1

            if verbose: print 'ok' 
Example 34
Project: Reinforcement-Learning-Branch-and-Bound   Author: yudasong   File: Coach.py    MIT License 5 votes vote down vote up
def loadTrainExamples(self):
        modelFile = os.path.join(self.args.load_folder_file[0], self.args.load_folder_file[1])
        examplesFile = modelFile+".examples"
        if not os.path.isfile(examplesFile):
            print(examplesFile)
            r = input("File with trainExamples not found. Continue? [y|n]")
            if r != "y":
                sys.exit()
        else:
            print("File with trainExamples found. Read it.")
            with open(examplesFile, "rb") as f:
                self.trainExamplesHistory = Unpickler(f).load()
            f.closed
            # examples based on the model were already collected (loaded)
            self.skipFirstSelfPlay = True 
Example 35
Project: Reinforcement-Learning-Branch-and-Bound   Author: yudasong   File: REINFORCE.py    MIT License 5 votes vote down vote up
def loadTrainExamples(self):
        modelFile = os.path.join(self.args.load_folder_file[0], self.args.load_folder_file[1])
        examplesFile = modelFile+".examples"
        if not os.path.isfile(examplesFile):
            print(examplesFile)
            r = input("File with trainExamples not found. Continue? [y|n]")
            if r != "y":
                sys.exit()
        else:
            print("File with trainExamples found. Read it.")
            with open(examplesFile, "rb") as f:
                self.trainExamplesHistory = Unpickler(f).load()
            f.closed
            # examples based on the model were already collected (loaded)
            self.skipFirstSelfPlay = True 
Example 36
Project: Reinforcement-Learning-Branch-and-Bound   Author: yudasong   File: ActorCritic.py    MIT License 5 votes vote down vote up
def loadTrainExamples(self):
        modelFile = os.path.join(self.args.load_folder_file[0], self.args.load_folder_file[1])
        examplesFile = modelFile+".examples"
        if not os.path.isfile(examplesFile):
            print(examplesFile)
            r = input("File with trainExamples not found. Continue? [y|n]")
            if r != "y":
                sys.exit()
        else:
            print("File with trainExamples found. Read it.")
            with open(examplesFile, "rb") as f:
                self.trainExamplesHistory = Unpickler(f).load()
            f.closed
            # examples based on the model were already collected (loaded)
            self.skipFirstSelfPlay = True 
Example 37
Project: vnpy_crypto   Author: birforce   File: pickle_compat.py    MIT License 5 votes vote down vote up
def find_class(self, module, name):
            # override superclass
            key = (module, name)
            module, name = _class_locations_map.get(key, key)
            return super(Unpickler, self).find_class(module, name) 
Example 38
Project: vnpy_crypto   Author: birforce   File: pickle_compat.py    MIT License 5 votes vote down vote up
def load(fh, encoding=None, compat=False, is_verbose=False):
    """load a pickle, with a provided encoding

    if compat is True:
       fake the old class hierarchy
       if it works, then return the new type objects

    Parameters
    ----------
    fh: a filelike object
    encoding: an optional encoding
    compat: provide Series compatibility mode, boolean, default False
    is_verbose: show exception output
    """

    try:
        fh.seek(0)
        if encoding is not None:
            up = Unpickler(fh, encoding=encoding)
        else:
            up = Unpickler(fh)
        up.is_verbose = is_verbose

        return up.load()
    except:
        raise 
Example 39
Project: Blockly-rduino-communication   Author: technologiescollege   File: shelve.py    GNU General Public License v3.0 5 votes vote down vote up
def __getitem__(self, key):
        try:
            value = self.cache[key]
        except KeyError:
            f = BytesIO(self.dict[key.encode(self.keyencoding)])
            value = Unpickler(f).load()
            if self.writeback:
                self.cache[key] = value
        return value 
Example 40
Project: Blockly-rduino-communication   Author: technologiescollege   File: shelve.py    GNU General Public License v3.0 5 votes vote down vote up
def set_location(self, key):
        (key, value) = self.dict.set_location(key)
        f = BytesIO(value)
        return (key.decode(self.keyencoding), Unpickler(f).load()) 
Example 41
Project: Blockly-rduino-communication   Author: technologiescollege   File: shelve.py    GNU General Public License v3.0 5 votes vote down vote up
def next(self):
        (key, value) = next(self.dict)
        f = BytesIO(value)
        return (key.decode(self.keyencoding), Unpickler(f).load()) 
Example 42
Project: Blockly-rduino-communication   Author: technologiescollege   File: shelve.py    GNU General Public License v3.0 5 votes vote down vote up
def previous(self):
        (key, value) = self.dict.previous()
        f = BytesIO(value)
        return (key.decode(self.keyencoding), Unpickler(f).load()) 
Example 43
Project: Blockly-rduino-communication   Author: technologiescollege   File: shelve.py    GNU General Public License v3.0 5 votes vote down vote up
def first(self):
        (key, value) = self.dict.first()
        f = BytesIO(value)
        return (key.decode(self.keyencoding), Unpickler(f).load()) 
Example 44
Project: IronHydra   Author: microdee   File: shelve.py    MIT License 5 votes vote down vote up
def __getitem__(self, key):
        try:
            value = self.cache[key]
        except KeyError:
            f = StringIO(self.dict[key])
            value = Unpickler(f).load()
            if self.writeback:
                self.cache[key] = value
        return value 
Example 45
Project: IronHydra   Author: microdee   File: shelve.py    MIT License 5 votes vote down vote up
def set_location(self, key):
        (key, value) = self.dict.set_location(key)
        f = StringIO(value)
        return (key, Unpickler(f).load()) 
Example 46
Project: IronHydra   Author: microdee   File: shelve.py    MIT License 5 votes vote down vote up
def next(self):
        (key, value) = self.dict.next()
        f = StringIO(value)
        return (key, Unpickler(f).load()) 
Example 47
Project: IronHydra   Author: microdee   File: shelve.py    MIT License 5 votes vote down vote up
def previous(self):
        (key, value) = self.dict.previous()
        f = StringIO(value)
        return (key, Unpickler(f).load()) 
Example 48
Project: IronHydra   Author: microdee   File: shelve.py    MIT License 5 votes vote down vote up
def first(self):
        (key, value) = self.dict.first()
        f = StringIO(value)
        return (key, Unpickler(f).load()) 
Example 49
Project: deepjets   Author: deepjets   File: tasksystem.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def checkExec():
        if "--forkExecProc" in sys.argv:
            try:
                import better_exchook
            except ImportError:
                pass    # Doesn't matter.
            else:
                better_exchook.install()
            argidx = sys.argv.index("--forkExecProc")
            writeFileNo = int(sys.argv[argidx + 1])
            readFileNo = int(sys.argv[argidx + 2])
            readend = os.fdopen(readFileNo, "r")
            writeend = os.fdopen(writeFileNo, "w")
            unpickler = Unpickler(readend)
            name = unpickler.load()
            if ExecingProcess.Verbose: print("ExecingProcess child %s (pid %i)" % (name, os.getpid()))
            try:
                target = unpickler.load()
                args = unpickler.load()
            except EOFError:
                print("Error: unpickle incomplete")
                raise SystemExit
            ret = target(*args)
            # IOError is probably broken pipe. That probably means that the parent died.
            try: Pickler(writeend).dump(ret)
            except IOError: pass
            try: readend.close()
            except IOError: pass
            try: writeend.close()
            except IOError: pass
            if ExecingProcess.Verbose: print("ExecingProcess child %s (pid %i) finished" % (name, os.getpid()))
            raise SystemExit 
Example 50
Project: deepjets   Author: deepjets   File: tasksystem.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def recv(self):
        self._check_closed()
        self._check_readable()
        buf = self.conn.recv_bytes()
        f = StringIO(buf)
        return Unpickler(f).load()