<commit_before># Copyright (c) 2013 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.


import simplejson as json

from uuid import uuid4
from logging import getLogger

from gofer.constants import MODEL_VERSION, AUTHENTICATION


log = getLogger(__name__)


# --- constants --------------------------------------------------------------

VERSION = '0.5'


# --- exceptions -------------------------------------------------------------


class InvalidDocument(Exception):
    """
    Base for all message/document validation.
    """

    CODE = {
        MODEL_VERSION: 'MODEL: version not valid',
        AUTHENTICATION: 'SECURITY: message authentication failed'
    }

    def __init__(self, code, document, details):
        """
        :param code: The validation code.  Must be in: CODE.
        :param document: The invalid document.
        :param details: A detailed description of what failed.
        """
        Exception.__init__(self, ' : '.join((self.CODE[code], details)))
        assert code in InvalidDocument.CODE
        self.code = code
        self.document = document
        self.details = details


class InvalidVersion(InvalidDocument):

    def __init__(self, document, details):
        """
        :param document: The invalid document.
        :type document: str
        :param details: A detailed description.
        :type details: str
        """
        InvalidDocument.__init__(self, MODEL_VERSION, document, details)


# --- utils ------------------------------------------------------------------


def getuuid():
    return str(uuid4())


def validate(document):
    """
    Determine whether the specified document is valid.
    :param document: The document to evaluate.
    :type document: Document<commit_msg>exception details optional.<commit_after># Copyright (c) 2013 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.


import simplejson as json

from uuid import uuid4
from logging import getLogger

from gofer.constants import MODEL_VERSION, AUTHENTICATION


log = getLogger(__name__)


# --- constants --------------------------------------------------------------

VERSION = '0.5'


# --- exceptions -------------------------------------------------------------


class InvalidDocument(Exception):
    """
    Base for all message/document validation.
    """

    CODE = {
        MODEL_VERSION: 'MODEL: version not valid',
        AUTHENTICATION: 'SECURITY: message authentication failed'
    }

    def __init__(self, code, document, details=None):
        """
        :param code: The validation code.  Must be in: CODE.
        :param document: The invalid document.
        :param details: A detailed description of what failed.
        """
        Exception.__init__(self, ' : '.join((self.CODE[code], details or '')))
        assert code in InvalidDocument.CODE
        self.code = code
        self.document = document
        self.details = details


class InvalidVersion(InvalidDocument):

    def __init__(self, document, details):
        """
        :param document: The invalid document.
        :type document: str
        :param details: A detailed description.
        :type details: str
        """
        InvalidDocument.__init__(self, MODEL_VERSION, document, details)


# --- utils ------------------------------------------------------------------


def getuuid():
    return str(uuid4())


def validate(document):
    """
    Determine whether the specified document is valid.
    :param document: The document to evaluate.
    :type document: Document
{'fraction_non_alphanumeric': 0.16692702521758537, 'fraction_numerical': 0.005802276277616604, 'mean_word_length': 2.178723404255319, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5910816', 'n_tokens_mistral': 1119, 'n_tokens_neox': 1074, 'n_words': 420}