'Locate and/or download `spec` to `tmpdir`, returning a local path
`spec` may be a ``Requirement`` object, or a string containing a URL,
an existing local filename, or a project/version requirement spec
(i.e. the string form of a ``Requirement`` object).  If it is the URL
of a .py file with an unambiguous ``#egg=name-version`` tag (i.e., one
that escapes ``-`` as ``_`` throughout), a trivial ``setup.py`` is
automatically created alongside the downloaded file.
If `spec` is a ``Requirement`` object or a string containing a
project/version requirement spec, this method returns the location of
a matching distribution (possibly after downloading it to `tmpdir`).
If `spec` is a locally existing file or directory name, it is simply
returned unchanged.  If `spec` is a URL, it is downloaded to a subpath
of `tmpdir`, and the local filename is returned.  Various errors may be
raised if a problem occurs during downloading.'

def download(self, spec, tmpdir):

    if (not isinstance(spec, Requirement)):
        scheme = URL_SCHEME(spec)
        if scheme:
            found = self._download_url(scheme.group(1), spec, tmpdir)
            (base, fragment) = egg_info_for_url(spec)
            if base.endswith('.py'):
                found = self.gen_setup(found, fragment, tmpdir)
            return found
        elif os.path.exists(spec):
            return spec
        else:
            try:
                spec = Requirement.parse(spec)
            except ValueError:
                raise DistutilsError(('Not    a    URL,    existing    file,    or    requirement    spec:    %r' % (spec,)))
    return getattr(self.fetch_distribution(spec, tmpdir), 'location', None)
