mzURL.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:multiplierz 作者: BlaisProteomics 项目源码 文件源码
def check_mzURL(mz_server, file_name):
    '''Checks if an mzURL actually exists.

    mz_server should be the base URL of the server
    file_name is the name of the specific file (without its extension)
    '''

    if mz_server[-1] == '/':
        mz_server = mz_server[:-1]

    # Handle to libcurl object
    crl = pycurl.Curl()

    # set some general options
    crl.setopt(pycurl.FOLLOWLOCATION, True)
    crl.setopt(pycurl.URL, str(mz_server + '/files.txt'))

    output = cStringIO.StringIO()
    crl.setopt(pycurl.WRITEFUNCTION, output.write)

    try:
        for i in range(5):
            #print 'check mzurl %d' % i
            crl.perform()
            if output.getvalue():
                break
    except pycurl.error, e:
        return False

    for f in output.getvalue().splitlines():
        if os.path.splitext(f)[0].lower() == file_name.lower():
            return True
    else:
        return False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号