def keypair_field_data(request, include_empty_option=False):
    keypair_list = []
    try:
        keypairs = api.nova.keypair_list(request)
        keypair_list = [(kp.name, kp.name) for kp in keypairs]
    except Exception:
        exceptions.handle(request, _('Unable to retrieve key pairs.'))

    if not keypair_list:
        if include_empty_option:
            return [("", _("No key pairs available")), ]
        return []

    if include_empty_option:
        return [("", _("Select a key pair")), ] + keypair_list
    return keypair_list
Return the number of initial spaces in a string
dataset/ETHPy150Open openstack/horizon/openstack_dashboard/dashboards/project/instances/utils.py/keypair_field_data--crossover with--dataset/ETHPy150Open ipython/ipython-py3k/IPython/utils/text.py/num_ini_spaces