<s> import os <EOL> try : <EOL> from urllib2 import urlopen <EOL> except ImportError : <EOL> from urllib . request import urlopen <EOL> def _download ( url , filename ) : <EOL> file_name = url . split ( '<STR_LIT:/>' ) [ - <NUM_LIT:1> ] <EOL> u = urlopen ( url ) <EOL> f = open ( filename , '<STR_LIT:wb>' ) <EOL> meta = u . info ( ) <EOL> size = int ( meta . getheaders ( "<STR_LIT>" ) [ <NUM_LIT:0> ] ) <EOL> print ( "<STR_LIT>" % ( file_name , size ) ) <EOL> downloaded = <NUM_LIT:0> <EOL> block_sz = <NUM_LIT> <EOL> while True : <EOL> buffer = u . read ( block_sz ) <EOL> if not buffer : <EOL> break <EOL> downloaded += len ( buffer ) <EOL> f . write ( buffer ) <EOL> status = r"<STR_LIT>" % ( downloaded , downloaded * <NUM_LIT> / size ) <EOL> status = status + chr ( <NUM_LIT:8> ) * ( len ( status ) + <NUM_LIT:1> ) <EOL> print ( status ) , <EOL> print ( chr ( <NUM_LIT:8> ) + '<STR_LIT>' + '<STR_LIT:U+0020>' * ( len ( status ) + <NUM_LIT:1> ) ) <EOL> f . close ( ) <EOL> def get_terminal_size ( ) : <EOL> def ioctl_GWINSZ ( fd ) : <EOL> try : <EOL> import fcntl <EOL> import struct <EOL> import termios <EOL> cr = struct . unpack ( '<STR_LIT>' , fcntl . ioctl ( fd , termios . TIOCGWINSZ , <EOL> '<STR_LIT>' ) ) <EOL> except : <EOL> return None <EOL> return cr <EOL> cr = ioctl_GWINSZ ( <NUM_LIT:0> ) or ioctl_GWINSZ ( <NUM_LIT:1> ) or ioctl_GWINSZ ( <NUM_LIT:2> ) <EOL> if not cr : <EOL> try : <EOL> fd = os . open ( os . ctermid ( ) , os . O_RDONLY ) <EOL> cr = ioctl_GWINSZ ( fd ) <EOL> os . close ( fd ) <EOL> except : <EOL> pass <EOL> if not cr : <EOL> try : <EOL> cr = ( os . environ [ '<STR_LIT>' ] , os . environ [ '<STR_LIT>' ] ) <EOL> except : <EOL> cr = ( <NUM_LIT> , <NUM_LIT> ) <EOL> return int ( cr [ <NUM_LIT:1> ] ) , int ( cr [ <NUM_LIT:0> ] ) </s>
