(*args, **kwargs)
return ReportHook(bar)
For use with urllib.request.urlretrieve.

    with pbar.reporthook() as hook:
        urllib.request.urlretrieve(url, filename, reporthook=hook)
For use with urllib.request.urlretrieve.
For use with urllib . request . urlretrieve .
def reporthook(*args, **kwargs):
    '''
    For use with urllib.request.urlretrieve.

    with pbar.reporthook() as hook:
        urllib.request.urlretrieve(url, filename, reporthook=hook)
    '''
    kwargs2 = dict(unit_scale=True, miniters=1)
    kwargs2.update(kwargs)
    bar = __call__(None, *args, **kwargs2)
    class ReportHook(object):
        def __init__(self, t):
            self.t = t
        def __call__(self, b=1, bsize=1, tsize=None):
            if hasattr(self.t, 'total'):
                if tsize is not None:
                    self.t.total = tsize
            if hasattr(self.t, 'update'):
                self.t.update(b * bsize - self.t.n)
        def __enter__(self):
            return self
        def __exit__(self, *exc):
            if hasattr(self.t, '__exit__'):
                self.t.__exit__(*exc)
    return ReportHook(bar)
def reporthook ( * args , * * kwargs ) : kwargs2 = dict ( unit_scale = True , miniters = 1 ) kwargs2 . update ( kwargs ) bar = __call__ ( None , * args , * * kwargs2 ) class ReportHook ( object ) : def __init__ ( self , t ) : self . t = t def __call__ ( self , b = 1 , bsize = 1 , tsize = None ) : if hasattr ( self . t , 'total' ) : if tsize is not None : self . t . total = tsize if hasattr ( self . t , 'update' ) : self . t . update ( b * bsize - self . t . n ) def __enter__ ( self ) : return self def __exit__ ( self , * exc ) : if hasattr ( self . t , '__exit__' ) : self . t . __exit__ ( * exc ) return ReportHook ( bar )