<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (C) 2008 <NAME>.
#
# Author: <NAME> <<EMAIL> at gmail dot com>
#
# This library is free software; you can redistribute it and/or modify 
# it under the terms of the GNU Lesser General Public License as published 
# by the Free Software Foundation; either version 2.1 of the License, or 
# (at your option) any later version.
#
# This library is distributed in the hope that it will be useful, but 
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
# License for more details.
#
# You should have received a copy of the GNU Lesser General Public License 
# along with this library; if not, write to the Free Software Foundation, 
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 

from umpa import utils

class Field(object):
    def __init__(self, bits, auto=False):
        """Set auto if you wish to take care about the field
        by the library. Then you will have to write how
        to manage the field.
        """
        self._bits = bits
        self._auto = auto
        self._value = None   # default value of the field

    def set(self, value):
        if self._is_valid(value):
            self._value = value
        else:
            raise

    def get(self):
        return self._value

    def _is_valid(self, val):
        """Should be overload by sub-classes.

        Otherwise always return true.
        """
        return True

class Flags(Field):
    """Most of protocols have a special field with bit-flags.
    For those fields we use this subclass of Field.
    """

    def __init__(self, auto=False, *names):
        Field.__init__(self, len(names), auto)

        self._ordered_fields = list(names)
        # we overwrite an attribute self._value
        # because we need a list instead of simple var here
        false_list = [ False for i in xrange(self._bits) ]
        self._value = dict(zip(self._ordered_fields, false_list))

    def _is_valid(self, name):
        return self._value.has_key(name)

    def _set_bit(self, names, value):
        for flag_name in names:
            if self._is_valid(flag_name):<commit_msg>Flags class cleaning part 2.<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (C) 2008 <NAME>.
#
# Author: <NAME> <<EMAIL> at <EMAIL> dot <EMAIL>>
#
# This library is free software; you can redistribute it and/or modify 
# it under the terms of the GNU Lesser General Public License as published 
# by the Free Software Foundation; either version 2.1 of the License, or 
# (at your option) any later version.
#
# This library is distributed in the hope that it will be useful, but 
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
# License for more details.
#
# You should have received a copy of the GNU Lesser General Public License 
# along with this library; if not, write to the Free Software Foundation, 
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 

from umpa import utils

class Field(object):
    def __init__(self, bits, auto=False):
        """Set auto if you wish to take care about the field
        by the library. Then you will have to write how
        to manage the field.
        """
        self._bits = bits
        self._auto = auto
        self._value = None   # default value of the field

    def set(self, value):
        if self._is_valid(value):
            self._value = value
        else:
            raise

    def get(self):
        return self._value

    def _is_valid(self, val):
        """Should be overload by sub-classes.

        Otherwise always return true.
        """
        return True

class Flags(Field):
    """Most of protocols have a special field with bit-flags.
    For those fields we use this subclass of Field.
    """

    def __init__(self, auto=False, *names):
        Field.__init__(self, len(names), auto)

        self._ordered_fields = names
        # we overwrite an attribute self._value
        # because we need a list instead of simple var here
        false_list = [ False for i in xrange(self._bits) ]
        self._value = dict(zip(self._ordered_fields, false_list))

    def _is_valid(self, name):
        return self._value.has_key(name)

    def _set_bit(self, names, value):
        for flag_name in names:
            if self._is_valid(flag_name):
{'fraction_non_alphanumeric': 0.08209780924983404, 'fraction_numerical': 0.009515379508740872, 'mean_word_length': 2.6334405144694535, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '884753', 'n_tokens_mistral': 1289, 'n_tokens_neox': 1229, 'n_words': 547}