<commit_before>from __future__ import unicode_literals, division, absolute_import
from builtins import *  # pylint: disable=unused-import, redefined-builtin
from past.builtins import basestring

import logging

from flexget import plugin
from flexget.config_schema import one_or_more
from flexget.event import event

log = logging.getLogger('require_field')


class FilterRequireField(object):
    """
    Rejects entries without defined field.

    Example::

      require_field: imdb_url
    """

    schema = one_or_more({'type': 'string'})

    @plugin.priority(32)
    def on_task_filter(self, task, config):
        if isinstance(config, basestring):
            config = [config]
        for entry in task.entries:
            for field in config:
                if entry.get(field) is None:
                    entry.reject('Required field %s is not present' % field)
                    break


@event('plugin.register')
def register_plugin():
    plugin.register(FilterRequireField, 'require_field', api_ver=2)
<commit_msg>[fix] require_field - Improve check logic.<commit_after>from __future__ import unicode_literals, division, absolute_import
from builtins import *  # pylint: disable=unused-import, redefined-builtin
from past.builtins import basestring

import logging

from flexget import plugin
from flexget.config_schema import one_or_more
from flexget.event import event

log = logging.getLogger('require_field')


class FilterRequireField(object):
    """
    Rejects entries without defined field.

    Example::

      require_field: imdb_url
    """

    schema = one_or_more({'type': 'string'})

    @plugin.priority(32)
    def on_task_filter(self, task, config):
        if isinstance(config, basestring):
            config = [config]
        for entry in task.entries:
            for field in config:
                if field not in entry:
                    entry.reject('Required field %s is not present' % field)
                    break


@event('plugin.register')
def register_plugin():
    plugin.register(FilterRequireField, 'require_field', api_ver=2)

{'fraction_non_alphanumeric': 0.08743430482560917, 'fraction_numerical': 0.002866698518872432, 'mean_word_length': 3.1547619047619047, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5381495', 'n_tokens_mistral': 597, 'n_tokens_neox': 574, 'n_words': 167}