def parse_keytab(keytab):
try:<EOL><INDENT>out = subprocess.check_output(['<STR_LIT>', '<STR_LIT>', keytab],<EOL>stderr=subprocess.PIPE)<EOL><DEDENT>except OSError:<EOL><INDENT>raise KerberosError("<STR_LIT>")<EOL><DEDENT>except subprocess.CalledProcessError:<EOL><INDENT>raise KerberosError("<STR_LIT>".format(keytab))<EOL><DEDENT>principals = []<EOL>for line in out.splitlines():<EOL><INDENT>if isinstance(line, bytes):<EOL><INDENT>line = line.decode('<STR_LIT:utf-8>')<EOL><DEDENT>try:<EOL><INDENT>kvno, principal, = re.split(r'<STR_LIT>', line.strip('<STR_LIT:U+0020>'), <NUM_LIT:1>)<EOL><DEDENT>except ValueError:<EOL><INDENT>continue<EOL><DEDENT>else:<EOL><INDENT>if not kvno.isdigit():<EOL><INDENT>continue<EOL><DEDENT>principals.append(tuple(principal.split('<STR_LIT:@>')) + (int(kvno),))<EOL><DEDENT><DEDENT>return list(OrderedDict.fromkeys(principals).keys())<EOL>
Read the contents of a KRB5 keytab file, returning a list of
    credentials listed within

    Parameters
    ----------
    keytab : `str`
        path to keytab file

    Returns
    -------
    creds : `list` of `tuple`
        the (unique) list of `(username, realm, kvno)` as read from the
        keytab file

    Examples
    --------
    >>> from gwpy.io.kerberos import parse_keytab
    >>> print(parse_keytab("creds.keytab"))
    [('albert.einstein', 'LIGO.ORG', 1)]