示例#1
0
    def test_multicall(self):
        progress = MockProgress()
        progress.write_bar(2.0, 1.0)
        progress.write_bar(2.0, 2.0)
        progress.activate()

        handler = CurlAdapter(progress)
        handler.callback(0.0, 0.0, 2.0, 1.0)
        handler.callback(0.0, 0.0, 2.0, 2.0)
        progress.verify()
示例#2
0
    def test_multicall(self):
        progress = MockProgress()
        progress.write_bar(2.0, 1.0)
        progress.write_bar(2.0, 2.0)
        progress.activate()

        handler = CurlAdapter(progress)
        handler.callback(0.0, 0.0, 2.0, 1.0)
        handler.callback(0.0, 0.0, 2.0, 2.0)
        progress.verify()
示例#3
0
    def test_unbounded(self):
        progress = MockProgress()
        progress.write_spin()
        progress.write_spin()
        progress.write_spin()
        progress.activate()

        handler = CurlAdapter(progress)
        handler.callback(0.0, 0.0, 0.0, 1.0)
        handler.callback(0.0, 0.0, 0.0, 2.0)
        handler.callback(0.0, 0.0, 0.0, 3.0)
        progress.verify()
示例#4
0
def get_remote_file_as_string(remote_url, progress=None):
    '''Returns the contents of a remote file as a string.'''
    result = StringIO()
    curl = pycurl.Curl()
    curl.setopt(curl.URL, remote_url)
    curl.setopt(curl.USERAGENT, 'pdk')
    curl.setopt(curl.FOLLOWLOCATION, True)
    curl.setopt(curl.MAXREDIRS, 5)
    curl.setopt(curl.AUTOREFERER, True)
    curl.setopt(curl.WRITEFUNCTION, result.write)
    curl.setopt(curl.NOPROGRESS, False)
    curl.setopt(curl.FAILONERROR, True)
    if not progress:
        progress = ConsoleProgress(remote_url)
    adapter = CurlAdapter(progress)
    curl.setopt(curl.PROGRESSFUNCTION, adapter.callback)
    curl_set_ssl(curl)
    curl_set_netrc(curl)

    try:
        progress.start()
        curl.perform()
        progress.done()
        curl.close()
    except pycurl.error, e:
        raise SemanticError, str(e)
示例#5
0
    def test_unbounded(self):
        progress = MockProgress()
        progress.write_spin()
        progress.write_spin()
        progress.write_spin()
        progress.activate()

        handler = CurlAdapter(progress)
        handler.callback(0.0, 0.0, 0.0, 1.0)
        handler.callback(0.0, 0.0, 0.0, 2.0)
        handler.callback(0.0, 0.0, 0.0, 3.0)
        progress.verify()
示例#6
0
def get_remote_file(remote_url,
                    local_filename,
                    trust_timestamp=False,
                    progress=None):
    '''Obtain a remote file via url.

    Copies the file to local_filename and attempts to set the last
    modified time.
    '''
    if os.path.exists(local_filename):
        mtime = os.stat(local_filename)[stat.ST_MTIME]
    else:
        mtime = None

    handle = LazyWriter(local_filename)

    curl = pycurl.Curl()
    curl.setopt(curl.URL, remote_url)
    curl.setopt(curl.USERAGENT, 'pdk')
    curl.setopt(curl.FOLLOWLOCATION, True)
    curl.setopt(curl.MAXREDIRS, 5)
    curl.setopt(curl.AUTOREFERER, True)
    curl.setopt(curl.WRITEFUNCTION, handle.write)
    curl.setopt(curl.NOPROGRESS, False)
    curl.setopt(curl.FAILONERROR, True)
    curl.setopt(curl.OPT_FILETIME, True)
    if mtime is not None and trust_timestamp:
        curl.setopt(curl.TIMEVALUE, mtime)
        curl.setopt(curl.TIMECONDITION, curl.TIMECONDITION_IFMODSINCE)
    if not progress:
        progress = ConsoleProgress(remote_url)
    adapter = CurlAdapter(progress)
    curl.setopt(curl.PROGRESSFUNCTION, adapter.callback)
    curl_set_ssl(curl)
    curl_set_netrc(curl)

    progress.start()
    curl.perform()
    progress.done()
    handle.close()
    mtime = curl.getinfo(curl.INFO_FILETIME)
    curl.close()
    if mtime != -1:
        os.utime(local_filename, (mtime, mtime))