(url, filename=None, reporthook=None, data=None)
return result
Retrieve a URL into a temporary location on disk.

    Requires a URL argument. If a filename is passed, it is used as
    the temporary file location. The reporthook argument should be
    a callable that accepts a block number, a read size, and the
    total file size of the URL target. The data argument should be
    valid URL encoded data.

    If a filename is passed and the URL points to a local resource,
    the result is a copy from local file to new file.

    Returns a tuple containing the path to the newly created
    data file as well as the resulting HTTPMessage object.
Retrieve a URL into a temporary location on disk.
Retrieve a URL into a temporary location on disk .
def urlretrieve(url, filename=None, reporthook=None, data=None):
    """
    Retrieve a URL into a temporary location on disk.

    Requires a URL argument. If a filename is passed, it is used as
    the temporary file location. The reporthook argument should be
    a callable that accepts a block number, a read size, and the
    total file size of the URL target. The data argument should be
    valid URL encoded data.

    If a filename is passed and the URL points to a local resource,
    the result is a copy from local file to new file.

    Returns a tuple containing the path to the newly created
    data file as well as the resulting HTTPMessage object.
    """
    url_type, path = _splittype(url)

    with contextlib.closing(urlopen(url, data)) as fp:
        headers = fp.info()

        # Just return the local path and the "headers" for file://
        # URLs. No sense in performing a copy unless requested.
        if url_type == "file" and not filename:
            return os.path.normpath(path), headers

        # Handle temporary file setup.
        if filename:
            tfp = open(filename, 'wb')
        else:
            tfp = tempfile.NamedTemporaryFile(delete=False)
            filename = tfp.name
            _url_tempfiles.append(filename)

        with tfp:
            result = filename, headers
            bs = 1024*8
            size = -1
            read = 0
            blocknum = 0
            if "content-length" in headers:
                size = int(headers["Content-Length"])

            if reporthook:
                reporthook(blocknum, bs, size)

            while True:
                block = fp.read(bs)
                if not block:
                    break
                read += len(block)
                tfp.write(block)
                blocknum += 1
                if reporthook:
                    reporthook(blocknum, bs, size)

    if size >= 0 and read < size:
        raise ContentTooShortError(
            "retrieval incomplete: got only %i out of %i bytes"
            % (read, size), result)

    return result
def urlretrieve ( url , filename = None , reporthook = None , data = None ) : url_type , path = _splittype ( url ) with contextlib . closing ( urlopen ( url , data ) ) as fp : headers = fp . info ( ) # Just return the local path and the "headers" for file:// # URLs. No sense in performing a copy unless requested. if url_type == "file" and not filename : return os . path . normpath ( path ) , headers # Handle temporary file setup. if filename : tfp = open ( filename , 'wb' ) else : tfp = tempfile . NamedTemporaryFile ( delete = False ) filename = tfp . name _url_tempfiles . append ( filename ) with tfp : result = filename , headers bs = 1024 * 8 size = - 1 read = 0 blocknum = 0 if "content-length" in headers : size = int ( headers [ "Content-Length" ] ) if reporthook : reporthook ( blocknum , bs , size ) while True : block = fp . read ( bs ) if not block : break read += len ( block ) tfp . write ( block ) blocknum += 1 if reporthook : reporthook ( blocknum , bs , size ) if size >= 0 and read < size : raise ContentTooShortError ( "retrieval incomplete: got only %i out of %i bytes" % ( read , size ) , result ) return result