def literal_theory(literal, theories, default_theory=None):
    """Return the theory that applies to LITERAL or None.

    :param: LITERAL is a Literal for which we want the schema
    :param: THEORIES is a dictionary mapping the name of the theory
           to the theory object
    :param: DEFAULT_THEORY is the theory to use if no theory is
           recorded as part of LITERAL
    :returns: the theory that applies to LITERAL or None
    """
    if theories is None:
        return
    active_theory = literal.table.service or default_theory
    if active_theory is None:
        return
    if active_theory not in theories:
        return
    return theories[active_theory]
