def download_file(url, filename=None, show_progress=draw_pbar):
if filename is None:<EOL><INDENT>filename = url.split('<STR_LIT:/>')[-<NUM_LIT:1>]<EOL><DEDENT>r = requests.get(url, stream=True)<EOL>size = int(r.headers['<STR_LIT>'].strip())<EOL>seen = <NUM_LIT:0><EOL>show_progress(<NUM_LIT:0>, size)<EOL>seen = <NUM_LIT><EOL>with open(filename, '<STR_LIT:wb>') as f:<EOL><INDENT>for chunk in r.iter_content(chunk_size=<NUM_LIT>):<EOL><INDENT>seen += <NUM_LIT><EOL>show_progress(seen, size)<EOL>if chunk:<EOL><INDENT>f.write(chunk)<EOL>f.flush()<EOL><DEDENT><DEDENT><DEDENT>return filename<EOL>
Download a file and show progress

url: the URL of the file to download
filename: the filename to download it to (if not given, uses the url's filename part)
show_progress: callback function to update a progress bar

the show_progress function shall take two parameters: `seen` and `size`, and
return nothing.

This function returns the filename it has written the result to.