python类UnpicklingError()的实例源码

indexer.py 文件源码 项目:Question-Answering-System 作者: AdityaAS 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def load_tokc(self):
        try:
            with open(self.base_fname + '.tokc', mode='rb') as f:
                self.tokc = pickle.load(f)
            if not self.tokc:
                raise IndexLoadError
        except (IOError, pickle.UnpicklingError):
            raise IndexLoadError
git_drover.py 文件源码 项目:depot_tools 作者: webrtc-uwp 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def _restore_drover(workdir):
    """Restores a saved drover state contained within a workdir.

    Args:
      workdir: A string containing the path to the workdir used by drover.
    """
    try:
      with open(os.path.join(workdir, '.git', 'drover'), 'rb') as f:
        drover = cPickle.load(f)
        drover._process_options()
        return drover
    except (IOError, cPickle.UnpicklingError):
      raise Error('%r is not git drover workdir' % workdir)
PickleRPC.py 文件源码 项目:w4py 作者: Cito 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def findGlobal(self, module, klass):
        """Find class name."""
        if (module, klass) not in self.allowedGlobals():
            raise UnpicklingError("For security reasons, you can\'t unpickle"
                " objects from module %s with type %s." % (module, klass))
        g = {}
        exec 'from %s import %s as theClass' % (module, klass) in g
        return g['theClass']
dbshelve.py 文件源码 项目:pisi 作者: examachine 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def decode(self, data):
        try:
            return cPickle.loads(data)
        except cPickle.UnpicklingError:
            raise CodingError()
store.py 文件源码 项目:Meiji 作者: GiovanniBalestrieri 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def loads(self, s):
        up = Unpickler(BytesIO(s))
        up.persistent_load = self._get_object
        try:
            return up.load()
        except KeyError, e:
            raise UnpicklingError("Could not find Node class for %s" % e)
store.py 文件源码 项目:prophet 作者: MKLab-ITI 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def loads(self, s):
        up = Unpickler(BytesIO(s))
        up.persistent_load = self._get_object
        try:
            return up.load()
        except KeyError, e:
            raise UnpicklingError("Could not find Node class for %s" % e)
serialize.py 文件源码 项目:iReminder 作者: r-kan 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def load(pickle_file):
    """output: is_exist, value"""
    try:
        pickle_fd = open(pickle_file, "r")
    except IOError as err:
        if errno.ENOENT == err.errno:
            debug("cache file does not exist: %s" % pickle_file)
            return False, None
        assert False
    try:
        value = cPickle.load(pickle_fd)
        return True, value
    except (ValueError, UnpicklingError, EOFError):
        error("cannot read pickle file: %s, suggest re-fetch the pickle file" % pickle_file)
        assert False
ngamsMWA_MIT_PushFiles.py 文件源码 项目:ngas 作者: ICRAR 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def main():
    opts = parseOptions()
    if (not opts):
        exit(1)
    #pushUrl = opts.push_url
    obsList = opts.obs_list.split(',')
    host = opts.push_host
    port = int(opts.port)

    client = ngamsPClient.ngamsPClient(host, port, timeOut = NGAMS_SOCK_TIMEOUT_DEF)

    toUrl = getPushURL("%s:%d" % (host, port), gateway = proxy_archive)
    stageUrl = 'http://%s/ASYNCLISTRETRIEVE' % opts.data_mover

    for obsNum in obsList:
        print "Checking observation: %s" % obsNum
        files = getFileIdsByObsNum(obsNum)
        deliverFileIds = []
        for fileId in files:
            # first check if MIT has it or not
            if (not hasMITGotIt(client, fileId)):
                deliverFileIds.append(fileId)
                """
                fileName = getFileFullPath(fileId)
                if (not os.path.exists(fileName)):
                    print "\tFile %s does not exist" % fileName
                    continue
                onTape = ngamsMWACortexTapeApi.isFileOnTape(fileName)
                if (1 == onTape):
                    stageFile(fileName)
                print "\tPushing file %s to MIT" % fileId
                archiveFile(fileName, client)
                """
            else:
                print "\tFile %s is already at MIT. Skip it." % fileId

        myReq = AsyncListRetrieveRequest(deliverFileIds, toUrl)
        strReq = pickle.dumps(myReq)
        try:
            print "Sending async retrieve request to the data mover %s" % opts.data_mover
            request = urllib2.Request(stageUrl)
            base64string = base64.encodestring('ngasmgr:ngas$dba').replace('\n', '')
            request.add_header("Authorization", "Basic %s" % base64string)
            strRes = urllib2.urlopen(request, data = strReq, timeout = NGAMS_SOCK_TIMEOUT_DEF).read()
            myRes = pickle.loads(strRes)
            #strRes = urllib2.urlopen(stageUrl, data = strReq, timeout = NGAMS_SOCK_TIMEOUT_DEF).read()
            #myRes = pickle.loads(strRes)
            if (myRes):
                print myRes.errorcode
            else:
                print 'Response is None when async staging files for obsNum %s' % obsNum
        except (UnpicklingError, socket.timeout) as uerr:
            print "Something wrong while sending async retrieve request for obsNum %s, %s" % (obsNum, str(uerr))
__init__.py 文件源码 项目:heliopy 作者: heliopython 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def loadpickle(fln):
    """
    load a pickle and return content as dictionary

    Parameters
    ==========
    fln : string
        filename

    Returns
    =======
    out : dict
        dictionary with content from file

    See Also
    ========
    savepickle

    Examples
    ========
    **note**: If fln is not found, but the same filename with '.gz'
           is found, will attempt to open the .gz as a gzipped file.

    >>> d = loadpickle('test.pbin')
    """
    if not os.path.exists(fln) and os.path.exists(fln + '.gz'):
        gzip = True
        fln += '.gz'
    else:
        try:
            with open(fln, 'rb') as fh:
                try: #Py3k
                    return pickle.load(fh, encoding='latin1')
                except TypeError:
                    return pickle.load(fh)
        except pickle.UnpicklingError: #maybe it's a gzip?
            gzip = True
        else:
            gzip = False
    if gzip:
        try:
            import zlib
            with open(fln, 'rb') as fh:
                stream = zlib.decompress(fh.read(), 16 + zlib.MAX_WBITS)
                try: #Py3k
                    return pickle.loads(stream, encoding='latin1')
                except TypeError:
                    return pickle.loads(stream)
        except MemoryError:
            import gzip
            with open(fln) as fh:
                gzh = gzip.GzipFile(fileobj=fh)
                try: #Py3k
                    contents = pickle.load(gzh, encoding='latin1')
                except TypeError:
                    contents = pickle.load(gzh)
                gzh.close()
            return contents


# -----------------------------------------------


问题


面经


文章

微信
公众号

扫码关注公众号