(blocks, block_size, total_size, bar_function)
callback function for urlretrieve that is called when connection is
    created and when once for each block

    draws adaptive progress bar in terminal/console

    use sys.stdout.write() instead of "print,", because it allows one more
    symbol at the line end without linefeed on Windows

    :param blocks: number of blocks transferred so far
    :param block_size: in bytes
    :param total_size: in bytes, can be -1 if server doesn't return it
    :param bar_function: another callback function to visualize progress
callback function for urlretrieve that is called when connection is
    created and when once for each block
callback function for urlretrieve that is called when connection is created and when once for each block
def callback_progress(blocks, block_size, total_size, bar_function):
    """callback function for urlretrieve that is called when connection is
    created and when once for each block

    draws adaptive progress bar in terminal/console

    use sys.stdout.write() instead of "print,", because it allows one more
    symbol at the line end without linefeed on Windows

    :param blocks: number of blocks transferred so far
    :param block_size: in bytes
    :param total_size: in bytes, can be -1 if server doesn't return it
    :param bar_function: another callback function to visualize progress
    """
    global __current_size
 
    width = min(100, get_console_width())

    if sys.version_info[:3] == (3, 3, 0):  # regression workaround
        if blocks == 0:  # first call
            __current_size = 0
        else:
            __current_size += block_size
        current_size = __current_size
    else:
        current_size = min(blocks*block_size, total_size)
    progress = bar_function(current_size, total_size, width)
    if progress:
        sys.stdout.write("\r" + progress)
def callback_progress ( blocks , block_size , total_size , bar_function ) : global __current_size width = min ( 100 , get_console_width ( ) ) if sys . version_info [ : 3 ] == ( 3 , 3 , 0 ) : # regression workaround if blocks == 0 : # first call __current_size = 0 else : __current_size += block_size current_size = __current_size else : current_size = min ( blocks * block_size , total_size ) progress = bar_function ( current_size , total_size , width ) if progress : sys . stdout . write ( "\r" + progress )