def load(fp, separator=DEFAULT, index_separator=DEFAULT, cls=dict, list_cls=list):
converter = None<EOL>output = cls()<EOL>arraykeys = set()<EOL>for line in fp:<EOL><INDENT>if converter is None:<EOL><INDENT>if isinstance(line, six.text_type):<EOL><INDENT>converter = six.u<EOL><DEDENT>else:<EOL><INDENT>converter = six.b<EOL><DEDENT>default_separator = converter('<STR_LIT:|>')<EOL>default_index_separator = converter('<STR_LIT:_>')<EOL>newline = converter('<STR_LIT:\n>')<EOL>if separator is DEFAULT:<EOL><INDENT>separator = default_separator<EOL><DEDENT>if index_separator is DEFAULT:<EOL><INDENT>index_separator = default_index_separator<EOL><DEDENT><DEDENT>key, value = line.strip().split(separator, <NUM_LIT:1>)<EOL>keyparts = key.split(index_separator)<EOL>try:<EOL><INDENT>index = int(keyparts[-<NUM_LIT:1>])<EOL>endwithint = True<EOL><DEDENT>except ValueError:<EOL><INDENT>endwithint = False<EOL><DEDENT>if len(keyparts) > <NUM_LIT:1> and endwithint:<EOL><INDENT>basekey = key.rsplit(index_separator, <NUM_LIT:1>)[<NUM_LIT:0>]<EOL>if basekey not in arraykeys:<EOL><INDENT>arraykeys.add(basekey)<EOL><DEDENT>if basekey in output:<EOL><INDENT>if not isinstance(output[basekey], dict):<EOL><INDENT>output[basekey] = {-<NUM_LIT:1>: output[basekey]}<EOL><DEDENT><DEDENT>else:<EOL><INDENT>output[basekey] = {}<EOL><DEDENT>output[basekey][index] = value<EOL><DEDENT>else:<EOL><INDENT>if key in output and isinstance(output[key], dict):<EOL><INDENT>output[key][-<NUM_LIT:1>] = value<EOL><DEDENT>else:<EOL><INDENT>output[key] = value<EOL><DEDENT><DEDENT><DEDENT>for key in arraykeys:<EOL><INDENT>output[key] = list_cls(pair[<NUM_LIT:1>] for pair in sorted(six.iteritems(output[key])))<EOL><DEDENT>return output<EOL>
Load an object from the file pointer.

    :param fp: A readable filehandle.
    :param separator: The separator between key and value.  Defaults to u'|' or b'|', depending on the types.
    :param index_separator: The separator between key and index.  Defaults to u'_' or b'_', depending on the types.
    :param cls: A callable that returns a Mapping that is filled with pairs.  The most common alternate option would be OrderedDict.
    :param list_cls: A callable that takes an iterable and returns a sequence.