import unicodedata


def read_ss_table(table_fd):
    """
    Read a two-column translation table file for substitutions.

    Given an open file object, read and return the contents of a two-column
    translation table. If uppercase or lowercase variants of the source
    term are available, add records for these variants automatically. For a
    record with more than two columns, a RuntimeError exception is raised.

    """
    tab = []
    table_str = unicodedata.normalize('NFC', table_fd.read())
    for line in table_str.split('\n'):
        rec = line.split('|')
        if len(rec) == 2:
            tab.append(rec)
            term1, term2 = rec
            term1_lower = term1.lower()
            term1_upper = term1.upper()
            if term1 != term1_lower:
                tab.append([term1_lower, term2.lower()])
            if term1 != term1_upper:
                tab.append([term1_upper, term2.upper()])
        elif line.strip() != '':
            raise RuntimeError('Table error: ' + line.strip())
    return tab