Search for a pypi package.

    \b
    Examples:
        \b
        pypi search requests
        pypi search 'requests oauth'
        pypi search requests -n 20
        pypi search 'requests toolbelt' --web

def search(query, n_results, web):
    """Search for a pypi package.

    \b
    Examples:
        \b
        pypi search requests
        pypi search 'requests oauth'
        pypi search requests -n 20
        pypi search 'requests toolbelt' --web

    """
    if web:
        secho(u'Opening search page for "{0}"...'.format(query), bold=True)
        url = SEARCH_URL.format(query=urlquote(query))
        click.launch(url)
    else:
        searcher = Searcher()
        results = searcher.search(query, n=n_results)
        first_line = style(u'Search results for "{0}"\n'.format(query),
                           bold=True)
        echo_via_pager(
            first_line +
            '\n'.join([format_result(result) for result in results])
        )