Example #1
0
 def check(Unpickler):
     for proto in range(pickle.HIGHEST_PROTOCOL + 1):
         unpickler = Unpickler(io.BytesIO(self.dumps('abc', proto)))
         self.assertEqual(unpickler.load(), 'abc')
     unpickler = Unpickler(io.BytesIO())
     self.assertEqual(unpickler.persistent_load('def'), 'def')
     r = weakref.ref(unpickler)
     del unpickler
     self.assertIsNone(r())
Example #2
0
 def __getitem__(self, key):
     try:
         return self.__vars__[key]
     except:
         try:
             with open(f'{self.name}.blue', 'rb') as fp:
                 p = Unpickler(fp)
                 data = p.load().__vars__.get(key)
             if data is None:
                 raise
             else:
                 return data
         except:
             raise KeyError(f"Key '{key}' does not exist.")
Example #3
0
 def loadTrainExamples(self, examples_file):
     if not os.path.isfile(examples_file):
         print(examples_file)
         print("File with trainExamples not found.")
         sys.exit()
     else:
         print("File with trainExamples found. Read it.")
         with open(examples_file, "rb") as f:
             return Unpickler(f).load()
Example #4
0
def unpickle_old_pyfits(fn):
    """
    This function unpickles everything in the specified filename, and
    correctly adapts pyfits files pre 2.3 to the new module structure.
    """
    
    import _pickle
    from _pickle import Unpickler
    import imp,sys

    def fg(modname,classname):        
        if 'NP_pyfits' in modname:
            modname = modname.replace('NP_pyfits','core')
            
        if '.' in modname:
            mod = __import__(modname,fromlist=[0])
        else:
            mod = __import__(modname)
            
        return getattr(mod,classname)
    
    objs = []
    if isinstance(fn, str):
        f = open(fn)
    else:
        f = fn
    
    try:
        u = Unpickler(f)
        #u.find_class = fg
        #u.find_global = fg
        
        while True:
            objs.append(u.load())
            
    except EOFError:
        pass
    finally:
        if isinstance(fn, str):
            f.close()
    if len(objs) == 1:
        return objs[0]
    else:
        return objs
Example #5
0
 def check(Unpickler):
     for proto in range(pickle.HIGHEST_PROTOCOL + 1):
         unpickler = Unpickler(io.BytesIO(self.dumps('abc', proto)))
         self.assertEqual(unpickler.load(), 'abc')
     unpickler = Unpickler(io.BytesIO())
     self.assertEqual(unpickler.persistent_load('def'), 'def')
     r = weakref.ref(unpickler)
     del unpickler
     self.assertIsNone(r())
Example #6
0
    def __init__(self, name, **kwargs):

        self.name = name
        self.__vars__ = {}
        self.__blues__ = {}

        try:
            with open(f'{self.name}.blue', 'rb') as fp:
                p = Unpickler(fp)
                q = p.load()
                self.__vars__ = q.__vars__
                self.__blues__ = q.__blues__
                self.__loaded__ = q
        except:
            with open(f'{self.name}.blue', 'wb') as fp:
                p = Pickler(fp)
                p.dump(self)
Example #7
0
def loadlastturn():
	global justloaded, boardwidth, boardheight, gamemods, whoseturn, phase, subphase, action, subaction
	file = open('lastturn', 'rb')
	loader = Unpickler(file)
	clear(summoners)
	clear(teams)
	clear(board)
	clear(modifiers)
	clear(gamemods)

	extend(summoners, loader.load())
	extend(teams, loader.load())
	extend(board, loader.load())
	boardwidth = loader.load()
	boardheight = loader.load()
	extend(modifiers, loader.load())
	extend(gamemods, loader.load())
	cachepics()
	whoseturn = loader.load()
	phase = loader.load()
	subphase = loader.load()
	file.close()

	justloaded = True
	phase()
Example #8
0
def load_input():
    global inp
    print("Loading...")
    pf = open(options.pickle, "rb")
    inp = Unpickler(pf).load()
    pf.close()