<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def read_case(input, format=None):
 """ Returns a case object from the given input file object. The data format may be optionally specified. """

    # Map of data file types to readers.
    format_map = {"matpower": MATPOWERReader,
        "psse": PSSEReader, "pickle": PickleReader}

    # Read case data.
    if format_map.has_key(format):
        reader_klass = format_map[format]
        reader = reader_klass()
        case = reader.read(input)
    else:
        # Try each of the readers at random.
        for reader_klass in format_map.values():
            reader = reader_klass()
            try:
                case = reader.read(input)
                if case is not None:
                    break
            except:
                pass
        else:
            case = None

    return case