'Given a spec, get the repository for its package.'

@_autospec
def repo_for_pkg(self, spec):

    if spec.namespace:
        fullspace = ('%s.%s' % (self.super_namespace, spec.namespace))
        if (fullspace not in self.by_namespace):
            raise UnknownNamespaceError(spec.namespace)
        return self.by_namespace[fullspace]
    for repo in self.repos:
        if (spec.name in repo):
            return repo
    return self.first_repo()
