<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright 2013 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""This file contains a parser for extracting metadata."""

import calendar
import time
import datetime

from plaso.lib import errors
from plaso.lib import event
from plaso.lib import eventdata
from plaso.lib import parser
from plaso.lib import timelib

import hachoir_parser
import hachoir_metadata
import hachoir_core

__author__ = '<NAME> (<EMAIL>)'


class Hachoir(parser.PlasoParser):
  """Parse meta data from files"""

  NAME = 'Hachoir'
  PARSER_TYPE = 'META'
  DATA_TYPE = 'metadata:hachoir'

  def Parse(self, filehandle):
    """Extract EventObjects from a file."""
    # TODO: Add a unit test for this parser.
    try:
      fstream = hachoir_core.stream.InputIOStream(filehandle, None, tags=[])
    except hachoir_core.error.HachoirError as exception:
      raise errors.UnableToParseFile(u'[%s] unable to parse file %s: %s' % (
          self.NAME, filehandle.name, exception))

    if not fstream:
      raise errors.UnableToParseFile(u'[%s] unable to parse file %s: %s' % (
          self.NAME, filehandle.name, 'Not fstream'))

    try:
      parser = hachoir_parser.guessParser(fstream)
    except hachoir_core.error.HachoirError as exception:
      raise errors.UnableToParseFile(u'[%s] unable to parse file %s: %s' % (
          self.NAME, filehandle.name, exception))

    if not parser:<commit_msg>Code review: 7393054: These files are missing unit tes<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright 2013 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""This file contains a parser for extracting metadata."""

import calendar
import time
import datetime

from plaso.lib import errors
from plaso.lib import event
from plaso.lib import eventdata
from plaso.lib import parser
from plaso.lib import timelib

import hachoir_parser
import hachoir_metadata
import hachoir_core

__author__ = '<NAME> (<EMAIL>)'


# Make hachoir parser "quiet" in it's otherwise excessive error reporting.
hachoir_core.config.quiet = True


class Hachoir(parser.PlasoParser):
  """Parse meta data from files"""

  NAME = 'Hachoir'
  PARSER_TYPE = 'META'
  DATA_TYPE = 'metadata:hachoir'

  def Parse(self, filehandle):
    """Extract EventObjects from a file."""
    # TODO: Add a unit test for this parser.
    try:
      fstream = hachoir_core.stream.InputIOStream(filehandle, None, tags=[])
    except hachoir_core.error.HachoirError as exception:
      raise errors.UnableToParseFile(u'[%s] unable to parse file %s: %s' % (
          self.NAME, filehandle.name, exception))

    if not fstream:
      raise errors.UnableToParseFile(u'[%s] unable to parse file %s: %s' % (
          self.NAME, filehandle.name, 'Not fstream'))

    try:
      parser = hachoir_parser.guessParser(fstream)
    except hachoir_core.error.HachoirError as exception:
      raise errors.UnableToParseFile(u'[%s] unable to parse file %s: %s' % (
          self.NAME, filehandle.name, exception))

    if not parser:
{'fraction_non_alphanumeric': 0.09572649572649573, 'fraction_numerical': 0.006105006105006105, 'mean_word_length': 3.8646080760095014, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4581593', 'n_tokens_mistral': 1256, 'n_tokens_neox': 1211, 'n_words': 451}