def download(url, directory=None, bufsize=8192):
    pieces = urlparse.urlparse(url)
    path = pieces.path
    if not directory:
        directory = tempfile.mkdtemp(prefix='download')

    outputPath = os.path.join(directory, os.path.basename(path))

    # Handle user/password explicitly.

    if pieces.scheme.startswith('http') and pieces.username:
        # Initialize basic HTTP authentication for this URL.
        # See http://aspn.activestate.com/ASPN/docs/ActivePython/2.5/howto/urllib2/index.html
        #
        # NOTE: This is necessary because urllib doesn't handle URLs like
        # http://user:password@host:port/...

        # Get the user name and password from the URL.
        user, password = pieces.username, pieces.password

        netloc = pieces.hostname
        if pieces.port:
            pieces.hostname += ':%d' % pieces.port
        newPieces = (pieces.scheme, netloc, pieces.path, pieces.query, 
                     pieces.params, pieces.fragment)
        url = urlparse.urlunparse(newPieces)
        log.debug('Installing authorization handler for URL %s' % url)
        passwordMgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
        passwordMgr.add_password(realm=None,
                                 uri=url,
                                 user=user,
                                 passwd=password)
        authHandler = urllib2.HTTPBasicAuthHandler(passwordMgr)
        opener = urllib2.build_opener(authHandler)
        opener.open(url)
        urllib2.install_opener(opener)

    log.debug('Downloading "%s" to "%s"' % (url, outputPath))
    shutil.copyfileobj(urllib2.urlopen(url), open(outputPath, 'wb'), bufsize)

    return (outputPath, directory)
Generates a pretty set of lines.
dataset/ETHPy150Open AppScale/appscale/AppServer/lib/grizzled/grizzled/net/__init__.py/download--crossover with--dataset/ETHPy150Open enthought/mayavi/mayavi/tools/helper_functions.py/test_plot3d