'Find the most recent distribution which matches the given
requirement.
:param requirement: A requirement of the form \'foo (1.0)\' or perhaps
\'foo (>= 1.0, < 2.0, != 1.3)\'
:param prereleases: If ``True``, allow pre-release versions
to be located. Otherwise, pre-release versions
are not returned.
:return: A :class:`Distribution` instance, or ``None`` if no such
distribution could be located.'

def locate(self, requirement, prereleases=False):

    result = None
    r = parse_requirement(requirement)
    if (r is None):
        raise DistlibException(('Not    a    valid    requirement:    %r' % requirement))
    scheme = get_scheme(self.scheme)
    self.matcher = matcher = scheme.matcher(r.requirement)
    logger.debug('matcher:    %s    (%s)', matcher, type(matcher).__name__)
    versions = self.get_project(r.name)
    if versions:
        slist = []
        vcls = matcher.version_class
        for k in versions:
            try:
                if (not matcher.match(k)):
                    logger.debug('%s    did    not    match    %r', matcher, k)
                elif (prereleases or (not vcls(k).is_prerelease)):
                    slist.append(k)
                else:
                    logger.debug('skipping    pre-release    version    %s    of    %s', k, matcher.name)
            except Exception:
                logger.warning('error    matching    %s    with    %r', matcher, k)
                pass
        if (len(slist) > 1):
            slist = sorted(slist, key=scheme.key)
        if slist:
            logger.debug('sorted    list:    %s', slist)
            result = versions[slist[(-1)]]
    if (result and r.extras):
        result.extras = r.extras
    self.matcher = None
    return result
