本文整理汇总了Python中pickle.Unpickler类的典型用法代码示例。如果您正苦于以下问题:Python Unpickler类的具体用法?Python Unpickler怎么用?Python Unpickler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Unpickler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, partIn, maxThreadsIn=8):
super(ValgrindAnalyzer, self).__init__()
self.release = None
self.plat = None
self.part = partIn
self.ignoreLibs = ['libm-2.5.so','libpthread-2.5.so', 'cmsRun']
self.libList = []
prodFileName = os.environ['CMSSW_RELEASE_BASE']+'/src/ReleaseProducts.list'
self.rpr = RelProdReader()
self.rpr.readProducts(prodFileName)
vgCmdFileName = os.environ['CMSSW_RELEASE_BASE']+'/qaLogs/vgCmds.pkl'
from pickle import Unpickler
vgCmdFile = open(vgCmdFileName, 'r')
vgCmdPklr = Unpickler(vgCmdFile)
self.vgCmds = vgCmdPklr.load()
vgCmdFile.close()
self.toDo = []
self.threadList = []
self.maxThreads = maxThreadsIn
self.threadStatus = {}
self.threadTiming = {}
示例2: load_brain
def load_brain(self):
"""
Load the actor and critic's configurations from the corresponding files.
:return: True if configuration loaded, False otherwise
"""
try:
# Open the file
with open("Config/actor.cfg", "rb") as cfg_file:
# Instantiate an Unpickler
unpickle = Unpickler(cfg_file)
# Load the object
self._actor = unpickle.load()
# Repeat the operation for the actor
with open("Config/critic.cfg", "rb") as cfg_file:
unpickle = Unpickler(cfg_file)
self._critic = unpickle.load()
# Return True because everything up to this point went well
return True
except IOError as error:
# Display a message detailing the error
print("No prevously recorded actor and/or critic configuration")
# Return False to warn that something bad happened, leaving the actor and critic in an unknown state
return False
示例3: recover_snapshot
def recover_snapshot(self):
file = open(path.join(self.basedir,fu.last_snapshot_file(self.basedir)),"rb")
if not file:
return None
logger.debug("Recovering snapshot from: " + file.name)
unpickler = Unpickler(file)
return unpickler.load()
示例4: __init__
def __init__(self, outFile, saveFile):
computerName=platform.node().capitalize()
userName=getpass.getuser().capitalize()
self.outFile=outFile
self.saveFile=saveFile
self._kinds={"kind":kind, "adjective":adjective,"entity":entity,"name":name,"thing":thing,"person":person,
"computer":computer,"user":user,"infinitive":infinitive,"pronoun":pronoun,
"male":male,"female":female,"place":place,"location":location,"number":number,
"time":time}
try:
infile = open(saveFile,'rb')
unpickle = Unpickler(infile)
kinds=unpickle.load()
self._loadKinds(kinds, "entity")
self._loadKinds(kinds, "adjective")
#globalsBak=globals().copy() #backup globals
globals().update(self._kinds) #inject dynamic classes into globals
self._entities,self._antecedents,self._names,self._adjectives=unpickle.load()
#globals().clear() #clear globals
#globals().update(globalsBak) #restore backup
infile.close
except: # IOError:
self._entities={computerName:computer(computerName,self,True),userName:user(userName,self,True),"Vibranium":thing("Vibranium",self)}
self._antecedents={"I":self._entities[userName],"you":self._entities[computerName]}
self._names={}
self._adjectives={}
for key,value in self._entities.items():
if value in self._names:
self._names[value].add(key)
else:
self._names[value]={key}
self._temp={} #stores 'a/an' objects, possessives, prepositional phrases, and numbers
示例5: loads
def loads(self, s):
up = Unpickler(BytesIO(s))
up.persistent_load = self._get_object
try:
return up.load()
except KeyError as e:
raise UnpicklingError("Could not find Node class for %s" % e)
示例6: testDeepCopyCanInvalidate
def testDeepCopyCanInvalidate(self):
"""
Tests regression for invalidation problems related to missing
readers and writers values in cloned objects (see
http://mail.zope.org/pipermail/zodb-dev/2008-August/012054.html)
"""
import ZODB.MappingStorage
database = DB(ZODB.blob.BlobStorage(
'blobs', ZODB.MappingStorage.MappingStorage()))
connection = database.open()
root = connection.root()
transaction.begin()
root['blob'] = Blob()
transaction.commit()
stream = StringIO()
p = Pickler(stream, 1)
p.dump(root['blob'])
u = Unpickler(stream)
stream.seek(0)
clone = u.load()
clone._p_invalidate()
# it should also be possible to open the cloned blob
# (even though it won't contain the original data)
clone.open()
# tearDown
database.close()
示例7: _reader
def _reader(self, data):
unpickler = Unpickler(StringIO(data))
while True:
try:
self._process(*unpickler.load())
except EOFError:
break
示例8: readData
def readData(self):
import config
pklFileName = config.siteInfo['qaPath']+'/navigator-summary.pkl'
pklIn = open(pklFileName,'r')
from pickle import Unpickler
upklr = Unpickler(pklIn)
self.data = upklr.load()
pklIn.close()
示例9: testPickleUnpickle
def testPickleUnpickle(self):
s = BytesIO()
p = Pickler(s)
p.dump(Allow)
s.seek(0)
u = Unpickler(s)
newAllow = u.load()
self.assertTrue(newAllow is Allow)
示例10: unpickle_outcomes
def unpickle_outcomes(fn, desired_iterations):
fh = open(fn, 'r')
unp = Unpickler(fh)
outcomes = unp.load()
fh.close()
kept_iterations = outcomes["ITERATIONS"]
if kept_iterations == desired_iterations:
return outcomes
raise IOError
示例11: unpack
def unpack(self, packet):
from pickle import Unpickler
from io import BytesIO
buffer = BytesIO(packet)
delegate = Unpickler(buffer)
delegate.persistent_load = lambda id: self.world.get_token(int(id))
return delegate.load()
示例12: loads
def loads(self, string):
f = StringIO(string)
unpickler = Unpickler(f)
unpickler.memo = self._unpicklememo
res = unpickler.load()
self._updatepicklememo()
#print >>debug, "loaded", res
#print >>debug, "unpicklememo", self._unpicklememo
return res
示例13: doUnPickling
def doUnPickling(option, pickleFile, loqt=None, url=""):
from pickle import Unpickler
if not os.path.isfile(pickleFile):
print "DEBUG:[doUnPickling] PickleFile does not exist."
doPickling(option, pickleFile, loqt, url)
f = open(pickleFile, "r")
if option == "STEMMED_QUERIES":
up = Unpickler(f)
unpkldData = up.load()
f.close()
print "DEBUG:[doUnPickling] Unpickled " + option + ": " # ,unpkldData
return unpkldData
elif option == "EXTFILE_MAP":
print "DEBUG:[doUnPickling] Unpickling ->" + option
up = Unpickler(f)
extfile_map_hash = up.load()
f.close()
return extfile_map_hash
elif option == "TERM_STATS":
print "DEBUG:[doUnPickling] Unpickling ->" + option
up = Unpickler(f)
term_id_hash = up.load()
docIdUniverse = up.load()
corpus_stats = up.load()
query_stats = up.load()
f.close()
# print "DEBUG:[doUnPickling] Unpickled "+option+": corpus_stats",corpus_stats
# print "DEBUG:[doUnPickling] Unpickled "+option+": query_stats",query_stats
return term_id_hash, docIdUniverse, corpus_stats, query_stats
else:
print "***ERROR***:[doPickling] Specify a correct option to UnPickle."
示例14: __init__
def __init__(self, *args, **kwargs):
Unpickler.__init__(self, *args, **kwargs)
self.dispatch[pickle.BININT] = lambda x: self.load_binint()
self.dispatch[pickle.BININT2] = lambda x: self.load_binint2()
self.dispatch[pickle.LONG4] = lambda x: self.load_long4()
self.dispatch[pickle.BINSTRING] = lambda x: self.load_binstring()
self.dispatch[pickle.BINUNICODE] = lambda x: self.load_binunicode()
self.dispatch[pickle.EXT2] = lambda x: self.load_ext2()
self.dispatch[pickle.EXT4] = lambda x: self.load_ext4()
self.dispatch[pickle.LONG_BINGET] = lambda x: self.load_long_binget()
self.dispatch[pickle.LONG_BINPUT] = lambda x: self.load_long_binput()
示例15: load_models
def load_models(self,model_files):
"""load model or list of models into self.model"""
if type(model_files)==str: model_files = [model_files]
i = 0
for mod_file in model_files:
model = open(mod_file,'r')
unPickled = Unpickler(model)
clf_RF = unPickled.load()
self.model.append(clf_RF)
model.close()
i += 1
return i