# Buggy code
def ParseFileObject(self, parser_mediator, file_object, **kwargs):
    """Parses a CUPS IPP file-like object.

    Args:
      parser_mediator (ParserMediator): mediates interactions between parsers
          and other components, such as storage and dfvfs.
      file_object (dfvfs.FileIO): file-like object.

    Raises:
      UnableToParseFile: when the file cannot be parsed.
    """
    try:
        header = self.CUPS_IPP_HEADER.parse_stream(file_object)
    except (IOError, construct.FieldError) as exception:
        raise errors.UnableToParseFile(
            "Unable to parse CUPS IPP Header with error: {0:s}".format(exception)
        )

    if (
        header.major_version != self.IPP_MAJOR_VERSION
        or header.minor_version != self.IPP_MINOR_VERSION
    ):
        raise errors.UnableToParseFile(
            "[{0:s}] Unsupported version number.".format(self.NAME)
        )

    if header.operation_id != self.IPP_OP_ID:
        # Warn if the operation ID differs from the standard one. We should be
        # able to parse the file nonetheless.
        logging.debug(
            "[{0:s}] Unsupported operation identifier in file: {1:s}.".format(
                self.NAME, parser_mediator.GetDisplayName()
            )
        )

    # Read the pairs extracting the name and the value.
    data_dict = {}
    name, value = self._ReadPair(parser_mediator, file_object)
    while name or value:
        # Translate the known "name" CUPS IPP to a generic name value.
        pretty_name = self.NAME_PAIR_TRANSLATION.get(name, name)
        data_dict.setdefault(pretty_name, []).append(value)
        name, value = self._ReadPair(parser_mediator, file_object)

    # TODO: Refactor to use a lookup table to do event production.
    time_dict = {}
    for key, value in data_dict.items():
        if key.startswith("date-time-") or key.startswith("time-"):
            time_dict[key] = value
            del data_dict[key]

    # TODO: Find a better solution than to have join for each attribute.
    event_data = CupsIppEventData()
    event_data.application = self._ListToString(data_dict.get("application", None))
    event_data.computer_name = self._ListToString(data_dict.get("computer_name", None))
    event_data.copies = data_dict.get("copies", 0)[0]
    event_data.data_dict = data_dict
    event_data.doc_type = self._ListToString(data_dict.get("doc_type", None))
    event_data.job_id = self._ListToString(data_dict.get("job_id", None))
    event_data.job_name = self._ListToString(data_dict.get("job_name", None))
    event_data.user = self._ListToString(data_dict.get("user", None))
    event_data.owner = self._ListToString(data_dict.get("owner", None))
    event_data.printer_id = self._ListToString(data_dict.get("printer_id", None))
    event_data.uri = self._ListToString(data_dict.get("uri", None))

    time_value = time_dict.get("date-time-at-creation", None)
    if time_value is not None:
        date_time = dfdatetime_posix_time.PosixTimeInMicroseconds(
            timestamp=time_value[0]
        )
        event = time_events.DateTimeValuesEvent(
            date_time, eventdata.EventTimestamp.CREATION_TIME
        )
        parser_mediator.ProduceEventWithEventData(event, event_data)

    time_value = time_dict.get("date-time-at-processing", None)
    if time_value is not None:
        date_time = dfdatetime_posix_time.PosixTimeInMicroseconds(
            timestamp=time_value[0]
        )
        event = time_events.DateTimeValuesEvent(
            date_time, eventdata.EventTimestamp.START_TIME
        )
        parser_mediator.ProduceEventWithEventData(event, event_data)

    time_value = time_dict.get("date-time-at-completed", None)
    if time_value is not None:
        date_time = dfdatetime_posix_time.PosixTimeInMicroseconds(
            timestamp=time_value[0]
        )
        event = time_events.DateTimeValuesEvent(
            date_time, eventdata.EventTimestamp.END_TIME
        )
        parser_mediator.ProduceEventWithEventData(event, event_data)

    time_value = time_dict.get("time-at-creation", None)
    if time_value is not None:
        date_time = dfdatetime_posix_time.PosixTime(timestamp=time_value[0])
        event = time_events.DateTimeValuesEvent(
            date_time, eventdata.EventTimestamp.CREATION_TIME
        )
        parser_mediator.ProduceEventWithEventData(event, event_data)

    time_value = time_dict.get("time-at-processing", None)
    if time_value is not None:
        date_time = dfdatetime_posix_time.PosixTime(timestamp=time_value[0])
        event = time_events.DateTimeValuesEvent(
            date_time, eventdata.EventTimestamp.START_TIME
        )
        parser_mediator.ProduceEventWithEventData(event, event_data)

    time_value = time_dict.get("time-at-completed", None)
    if time_value is not None:
        date_time = dfdatetime_posix_time.PosixTime(timestamp=time_value[0])
        event = time_events.DateTimeValuesEvent(
            date_time, eventdata.EventTimestamp.END_TIME
        )
        parser_mediator.ProduceEventWithEventData(event, event_data)


# Traceback (TypeError)
Traceback (most recent call last):
File "plaso/multi_processing/worker_process.py", line 208, in _ProcessPathSpec
extraction_worker.ProcessPathSpec(parser_mediator, path_spec)
File "plaso/engine/worker.py", line 767, in ProcessPathSpec
self._ProcessFileEntry(mediator, file_entry)
File "plaso/engine/worker.py", line 592, in _ProcessFileEntry
mediator, file_entry, data_stream.name)
File "plaso/engine/worker.py", line 686, in _ProcessFileEntryDataStream
mediator, file_entry, data_stream_name)
File "plaso/engine/worker.py", line 304, in _ExtractContentFromDataStream
mediator, file_entry, data_stream_name)
File "plaso/engine/extractors.py", line 298, in ParseDataStream
file_object=file_object)
File "plaso/engine/extractors.py", line 269, in _ParserFileEntryWithParsers
parser_mediator, parser, file_entry, file_object=file_object)
File "plaso/engine/extractors.py", line 203, in _ParseFileEntryWithParser
parser.Parse(parser_mediator, file_object)
File "plaso/parsers/interface.py", line 269, in Parse
self.ParseFileObject(parser_mediator, file_object, **kwargs)
File "plaso/parsers/cups_ipp.py", line 332, in ParseFileObject
event_data.copies = data_dict.get(u'copies', 0)[0]
TypeError: 'int' object has no attribute '__getitem__'

# Fixed code
def ParseFileObject(self, parser_mediator, file_object, **kwargs):
    """Parses a CUPS IPP file-like object.

    Args:
      parser_mediator (ParserMediator): mediates interactions between parsers
          and other components, such as storage and dfvfs.
      file_object (dfvfs.FileIO): file-like object.

    Raises:
      UnableToParseFile: when the file cannot be parsed.
    """
    try:
        header = self.CUPS_IPP_HEADER.parse_stream(file_object)
    except (IOError, construct.FieldError) as exception:
        raise errors.UnableToParseFile(
            "Unable to parse CUPS IPP Header with error: {0:s}".format(exception)
        )

    if (
        header.major_version != self.IPP_MAJOR_VERSION
        or header.minor_version != self.IPP_MINOR_VERSION
    ):
        raise errors.UnableToParseFile(
            "[{0:s}] Unsupported version number.".format(self.NAME)
        )

    if header.operation_id != self.IPP_OP_ID:
        # Warn if the operation ID differs from the standard one. We should be
        # able to parse the file nonetheless.
        logging.debug(
            "[{0:s}] Unsupported operation identifier in file: {1:s}.".format(
                self.NAME, parser_mediator.GetDisplayName()
            )
        )

    data_dict = self._ReadPairs(parser_mediator, file_object)

    time_dict = {}

    for name in self._POSIX_TIME_VALUE_NAMES:
        value = data_dict.get(name, None)
        if value is not None:
            time_dict[name] = value
            del data_dict[name]

    event_data = CupsIppEventData()
    event_data.application = self._GetStringValue(data_dict, "application")
    event_data.computer_name = self._GetStringValue(data_dict, "computer_name")
    event_data.copies = data_dict.get("copies", [0])[0]
    event_data.data_dict = data_dict
    event_data.doc_type = self._GetStringValue(data_dict, "doc_type")
    event_data.job_id = self._GetStringValue(data_dict, "job_id")
    event_data.job_name = self._GetStringValue(data_dict, "job_name")
    event_data.user = self._GetStringValue(data_dict, "user")
    event_data.owner = self._GetStringValue(data_dict, "owner")
    event_data.printer_id = self._GetStringValue(data_dict, "printer_id")
    event_data.uri = self._GetStringValue(data_dict, "uri")

    for name, usage in iter(self._POSIX_TIME_IN_MICROSECOND_VALUES.items()):
        time_values = time_dict.get(name, [])
        for time_value in time_values:
            date_time = dfdatetime_posix_time.PosixTimeInMicroseconds(
                timestamp=time_value
            )
            event = time_events.DateTimeValuesEvent(date_time, usage)
            parser_mediator.ProduceEventWithEventData(event, event_data)

    for name, usage in iter(self._POSIX_TIME_VALUES.items()):
        time_values = time_dict.get(name, [])
        for time_value in time_values:
            date_time = dfdatetime_posix_time.PosixTime(timestamp=time_value)
            event = time_events.DateTimeValuesEvent(date_time, usage)
            parser_mediator.ProduceEventWithEventData(event, event_data)