def download(self, spec, tmpdir):
if not isinstance(spec,Requirement):<EOL><INDENT>scheme = URL_SCHEME(spec)<EOL>if scheme:<EOL><INDENT>found = self._download_url(scheme.group(<NUM_LIT:1>), spec, tmpdir)<EOL>base, fragment = egg_info_for_url(spec)<EOL>if base.endswith('<STR_LIT>'):<EOL><INDENT>found = self.gen_setup(found,fragment,tmpdir)<EOL><DEDENT>return found<EOL><DEDENT>elif os.path.exists(spec):<EOL><INDENT>return spec<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>spec = Requirement.parse(spec)<EOL><DEDENT>except ValueError:<EOL><INDENT>raise DistutilsError(<EOL>"<STR_LIT>" %<EOL>(spec,)<EOL>)<EOL><DEDENT><DEDENT><DEDENT>return getattr(self.fetch_distribution(spec, tmpdir),'<STR_LIT:location>',None)<EOL>
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.