def ParseFileObject(self, parser_mediator, file_object):
    """Parses an Opera typed history 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.
    """
    data = file_object.read(self._HEADER_READ_SIZE)
    if not data.startswith(b'<?xml'):
      raise errors.UnableToParseFile(
          'Not an Opera typed history file [not a XML]')

    _, _, data = data.partition(b'\n')
    if not data.startswith(b'<typed_history'):
      raise errors.UnableToParseFile(
          'Not an Opera typed history file [wrong XML root key]')

    # For ElementTree to work we need to work on a file object seeked
    # to the beginning.
    file_object.seek(0, os.SEEK_SET)

    xml = ElementTree.parse(file_object)

    for history_item in xml.iterfind('typed_history_item'):
      event_data = OperaTypedHistoryEventData()
      event_data.entry_type = history_item.get('type', None)
      event_data.url = history_item.get('content', None)

      if event_data.entry_type == 'selected':
        event_data.entry_selection = 'Filled from autocomplete.'
      elif event_data.entry_type == 'text':
        event_data.entry_selection = 'Manually typed.'

      last_typed_time = history_item.get('last_typed', None)
      if last_typed_time is None:
        parser_mediator.ProduceExtractionWarning('missing last typed time.')
        continue

      date_time = dfdatetime_time_elements.TimeElements()

      try:
        date_time.CopyFromStringISO8601(last_typed_time)
      except ValueError as exception:
        parser_mediator.ProduceExtractionWarning(
            'unsupported last typed time: {0:s} with error: {1!s}.'.format(
                last_typed_time, exception))
        continue

      event = time_events.DateTimeValuesEvent(
          date_time, definitions.TIME_DESCRIPTION_LAST_VISITED)
      parser_mediator.ProduceEventWithEventData(event, event_data)
def ParseFileObject ( self , parser_mediator , file_object ) : data = file_object . read ( self . _HEADER_READ_SIZE ) if not data . startswith ( b'<?xml' ) : raise errors . UnableToParseFile ( 'Not an Opera typed history file [not a XML]' ) _ , _ , data = data . partition ( b'\n' ) if not data . startswith ( b'<typed_history' ) : raise errors . UnableToParseFile ( 'Not an Opera typed history file [wrong XML root key]' ) file_object . seek ( 0 , os . SEEK_SET ) xml = ElementTree . parse ( file_object ) for history_item in xml . iterfind ( 'typed_history_item' ) : event_data = OperaTypedHistoryEventData ( ) event_data . entry_type = history_item . get ( 'type' , None ) event_data . url = history_item . get ( 'content' , None ) if event_data . entry_type == 'selected' : event_data . entry_selection = 'Filled from autocomplete.' elif event_data . entry_type == 'text' : event_data . entry_selection = 'Manually typed.' last_typed_time = history_item . get ( 'last_typed' , None ) if last_typed_time is None : parser_mediator . ProduceExtractionWarning ( 'missing last typed time.' ) continue date_time = dfdatetime_time_elements . TimeElements ( ) try : date_time . CopyFromStringISO8601 ( last_typed_time ) except ValueError as exception : parser_mediator . ProduceExtractionWarning ( 'unsupported last typed time: {0:s} with error: {1!s}.' . format ( last_typed_time , exception ) ) continue event = time_events . DateTimeValuesEvent ( date_time , definitions . TIME_DESCRIPTION_LAST_VISITED ) parser_mediator . ProduceEventWithEventData ( event , event_data )
Parses an Opera typed history 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.