<commit_before># No shebang line, this module is meant to be imported
#
# Copyright 2014 <NAME>
#
# 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.

"""
Job Types
=========

Objects and classes for working with the job type models.
"""

import ast
import logging

from flask import flash
from flask.ext.admin.babel import gettext
from wtforms import Form, StringField, TextAreaField, IntegerField, BooleanField
from wtforms.validators import ValidationError, DataRequired, required

from pyfarm.master.admin.baseview import SQLModelView
from pyfarm.master.application import SessionMixin
from pyfarm.models.jobtype import JobType, JobTypeVersion
from pyfarm.models.core.cfg import MAX_JOBTYPE_LENGTH


admin_log = logging.getLogger("flask-admin.sqla")


class LimitedLength(DataRequired):
    """Validates that a given field is the proper length"""
    def __init__(self, length):
        super(LimitedLength, self).__init__()
        self.length = length

    def __call__(self, form, field):
        if len(field.data) > self.length:
            raise ValidationError(
                "Max length for %s is %s" % (repr(field.name), self.length))


def unique_name(_, field):
    """Validates that a unique job type name is being created"""
    model = JobType.query.filter_by(name=field.data).first()<commit_msg>use '_' for the variable name since it's unused<commit_after># No shebang line, this module is meant to be imported
#
# Copyright 2014 <NAME>
#
# 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.

"""
Job Types
=========

Objects and classes for working with the job type models.
"""

import ast
import logging

from flask import flash
from flask.ext.admin.babel import gettext
from wtforms import Form, StringField, TextAreaField, IntegerField, BooleanField
from wtforms.validators import ValidationError, DataRequired, required

from pyfarm.master.admin.baseview import SQLModelView
from pyfarm.master.application import SessionMixin
from pyfarm.models.jobtype import JobType, JobTypeVersion
from pyfarm.models.core.cfg import MAX_JOBTYPE_LENGTH


admin_log = logging.getLogger("flask-admin.sqla")


class LimitedLength(DataRequired):
    """Validates that a given field is the proper length"""
    def __init__(self, length):
        super(LimitedLength, self).__init__()
        self.length = length

    def __call__(self, _, field):
        if len(field.data) > self.length:
            raise ValidationError(
                "Max length for %s is %s" % (repr(field.name), self.length))


def unique_name(_, field):
    """Validates that a unique job type name is being created"""
    model = JobType.query.filter_by(name=field.data).first()
{'fraction_non_alphanumeric': 0.08641975308641975, 'fraction_numerical': 0.0043895747599451305, 'mean_word_length': 4.186344238975818, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6864583', 'n_tokens_mistral': 1019, 'n_tokens_neox': 981, 'n_words': 403}