<commit_before># This file is part of the GOsa framework.
#
#  http://gosa-project.org
#
# Copyright:
#  (C) 2016 GONICUS GmbH, Germany, http://www.gonicus.de
#
# See the LICENSE file in the project's top-level directory for details.

from gosa.backend.objects.types import AttributeType
from gosa.common.components.jsonrpc_utils import Binary
import datetime


class AnyType(AttributeType):
    __alias__ = "AnyType"

    def is_valid_value(self, value):
        return True

    def values_match(self, value1, value2):
        return value1 == value2

    def _convert_from_string(self, value):
        return value

    def _convert_from_datetime(self, value):
        return value

    def _convert_to_boolean(self, value):
        return list(map(lambda x: not(x in ['', 'false', '0', 'False']), value))

    def _convert_to_string(self, value):
        return list(map(lambda x: str(x), value))

    def _convert_to_integer(self, value):
        return list(map(lambda x: int(x), value))

    def _convert_to_unicodestring(self, value):
        return list(map(lambda x: str(x), value))


class StringAttribute(AttributeType):
    __alias__ = "String"

    def _convert_from_string(self, value):
        return list(map(lambda x: x.decode('ascii') if type(x) == bytes else x, value))

    def is_valid_value(self, value):
        return not len(value) or all(map(lambda x: type(x) == str, value))

    def values_match(self, value1, value2):
        return value1 == value2

    def _convert_to_boolean(self, value):
        return list(map(lambda x: not(x in ['', 'false', '0', 'False']), value))

    def _convert_to_string(self, value):
        return list(map(lambda x: x.decode('ascii') if type(x) == bytes else x, value))

    def _convert_to_integer(self, value):
        return list(map(lambda x: int(x), value))

    def _convert_to_unicodestring(self, value):
        return list(map(lambda x: str(x), value))

    def _convert_from_datetime(self, value):
        return list(map(lambda x: str(x), value))

    def _convert_from_integer(self, value):
        return list(map(lambda x: str(x), value))

    def fixup(self, value):
        return self._convert_to_string(value)


class IntegerAttribute(AttributeType):
    __alias__ = "Integer"

    def _convert_to_integer(self, value):
        return value

    def _convert_from_integer(self, value):
        return value

    def is_valid_value(self, value):
        return not len(value) or all(map(lambda x: type(x) == int, value))

    def values_match(self, value1, value2):
        return value1 == value2

    def _convert_to_string(self, value):
        return list(map(lambda x: bytes(str(x), 'utf-8'), value))

    def _convert_to_unicodestring(self, value):
        return list(map(lambda x: str(x), value))

    def _convert_from_string(self, value):
        return list(map(lambda x: int(float(x)), value))

    def _convert_from_unicodestring(self, value):
        return list(map(lambda x: int(float(x)), value))


class BooleanAttribute(AttributeType):
    __alias__ = "Boolean"

    def is_valid_value(self, value):
        return not len(value) or all(map(lambda x: type(x) == bool, value))

    def _convert_to_boolean(self, value):
        return value

    def _convert_from_boolean(self, value):
        return value

    def values_match(self, value1, value2):
        return value1 == value2

    def _convert_to_string(self, value):
        return list(map(lambda x: bytes(str(x), 'utf-8'), value))

    def _convert_to_unicodestring(self, value):
        return list(map(lambda x: str(x), value))

    def _convert_from_string(self, value):
        return list(map(lambda x: not(x in ['', 'false', '0', 'False']), value))

    def _convert_from_unicodestring(self, value):
        return list(map(lambda x: not(x.decode('ascii') if type(x) == bytes else x in ['', 'false', '0', 'False']), value))


class BinaryAttribute(AttributeType):
    __alias__ = "Binary"

    def _convert_to_binary(self, value):
        return value

    def _convert_from_binary(self, value):
        return value

    def is_valid_value(self, value):
        return not len(value) or all(map(lambda x: type(x) == Binary, value))

    def values_match(self, value1, value2):
        return value1 == value2

    def _convert_to_string(self, value):
        return list(map(lambda x: bytes(str(x.get()), 'utf-8'), value))

    def _convert_to_unicodestring(self, value):
        return list(map(lambda x: str(x.get()), value))


class UnicodeStringAttribute(AttributeType):
    __alias__ = "UnicodeString"

    def _convert_from_unicodestring(self, value):
        return list(map(lambda x: x.decode('utf-8') if type(x) == bytes else x, value))

    def is_valid_value(self, value):
        return not len(value) or all(map(lambda x: type(x) == str, value))

    def values_match(self, value1, value2):
        return value1 == value2

    def _convert_to_string(self, value):
        return list(map(lambda x: x.decode('utf-8'), value))

    def _convert_to_unicodestring(self, value):
        return list(map(lambda x: x.decode('utf-8') if type(x) == bytes else x, value))

    def _convert_to_boolean(self, value):
        return list(map(lambda x: not(x in ['', 'false', '0', 'False']), value))

    def _convert_to_integer(self, value):
        return list(map(lambda x: int(x), value))

    def _convert_from_string(self, value):
        new_value = []
        for item in value:
            if not item and type(item) not in [bytes, str]:
                item = u""
            new_value.append(str(item))<commit_msg>- make conversion work with strs -<commit_after># This file is part of the GOsa framework.
#
#  http://gosa-project.org
#
# Copyright:
#  (C) 2016 GONICUS GmbH, Germany, http://www.gonicus.de
#
# See the LICENSE file in the project's top-level directory for details.

from gosa.backend.objects.types import AttributeType
from gosa.common.components.jsonrpc_utils import Binary
import datetime


class AnyType(AttributeType):
    __alias__ = "AnyType"

    def is_valid_value(self, value):
        return True

    def values_match(self, value1, value2):
        return value1 == value2

    def _convert_from_string(self, value):
        return value

    def _convert_from_datetime(self, value):
        return value

    def _convert_to_boolean(self, value):
        return list(map(lambda x: not(x in ['', 'false', '0', 'False']), value))

    def _convert_to_string(self, value):
        return list(map(lambda x: str(x), value))

    def _convert_to_integer(self, value):
        return list(map(lambda x: int(x), value))

    def _convert_to_unicodestring(self, value):
        return list(map(lambda x: str(x), value))


class StringAttribute(AttributeType):
    __alias__ = "String"

    def _convert_from_string(self, value):
        return list(map(lambda x: x.decode('ascii') if type(x) == bytes else x, value))

    def is_valid_value(self, value):
        return not len(value) or all(map(lambda x: type(x) == str, value))

    def values_match(self, value1, value2):
        return value1 == value2

    def _convert_to_boolean(self, value):
        return list(map(lambda x: not(x in ['', 'false', '0', 'False']), value))

    def _convert_to_string(self, value):
        return list(map(lambda x: x.decode('ascii') if type(x) == bytes else x, value))

    def _convert_to_integer(self, value):
        return list(map(lambda x: int(x), value))

    def _convert_to_unicodestring(self, value):
        return list(map(lambda x: str(x), value))

    def _convert_from_datetime(self, value):
        return list(map(lambda x: str(x), value))

    def _convert_from_integer(self, value):
        return list(map(lambda x: str(x), value))

    def fixup(self, value):
        return self._convert_to_string(value)


class IntegerAttribute(AttributeType):
    __alias__ = "Integer"

    def _convert_to_integer(self, value):
        return value

    def _convert_from_integer(self, value):
        return value

    def is_valid_value(self, value):
        return not len(value) or all(map(lambda x: type(x) == int, value))

    def values_match(self, value1, value2):
        return value1 == value2

    def _convert_to_string(self, value):
        return list(map(lambda x: bytes(str(x), 'utf-8'), value))

    def _convert_to_unicodestring(self, value):
        return list(map(lambda x: str(x), value))

    def _convert_from_string(self, value):
        return list(map(lambda x: int(float(x)), value))

    def _convert_from_unicodestring(self, value):
        return list(map(lambda x: int(float(x)), value))


class BooleanAttribute(AttributeType):
    __alias__ = "Boolean"

    def is_valid_value(self, value):
        return not len(value) or all(map(lambda x: type(x) == bool, value))

    def _convert_to_boolean(self, value):
        return value

    def _convert_from_boolean(self, value):
        return value

    def values_match(self, value1, value2):
        return value1 == value2

    def _convert_to_string(self, value):
        return list(map(lambda x: bytes(str(x), 'utf-8'), value))

    def _convert_to_unicodestring(self, value):
        return list(map(lambda x: str(x), value))

    def _convert_from_string(self, value):
        return list(map(lambda x: not(x in ['', 'false', '0', 'False']), value))

    def _convert_from_unicodestring(self, value):
        return list(map(lambda x: not(x.decode('ascii') if type(x) == bytes else x in ['', 'false', '0', 'False']), value))


class BinaryAttribute(AttributeType):
    __alias__ = "Binary"

    def _convert_to_binary(self, value):
        return value

    def _convert_from_binary(self, value):
        return value

    def is_valid_value(self, value):
        return not len(value) or all(map(lambda x: type(x) == Binary, value))

    def values_match(self, value1, value2):
        return value1 == value2

    def _convert_to_string(self, value):
        return list(map(lambda x: bytes(str(x.get()), 'utf-8'), value))

    def _convert_to_unicodestring(self, value):
        return list(map(lambda x: str(x.get()), value))


class UnicodeStringAttribute(AttributeType):
    __alias__ = "UnicodeString"

    def _convert_from_unicodestring(self, value):
        return list(map(lambda x: x.decode('utf-8') if type(x) == bytes else x, value))

    def is_valid_value(self, value):
        return not len(value) or all(map(lambda x: type(x) == str, value))

    def values_match(self, value1, value2):
        return value1 == value2

    def _convert_to_string(self, value):
        return list(map(lambda x: x.decode('utf-8') if type(x) == bytes else x, value))

    def _convert_to_unicodestring(self, value):
        return list(map(lambda x: x.decode('utf-8') if type(x) == bytes else x, value))

    def _convert_to_boolean(self, value):
        return list(map(lambda x: not(x in ['', 'false', '0', 'False']), value))

    def _convert_to_integer(self, value):
        return list(map(lambda x: int(x), value))

    def _convert_from_string(self, value):
        new_value = []
        for item in value:
            if not item and type(item) not in [bytes, str]:
                item = u""
            new_value.append(str(item))
{'fraction_non_alphanumeric': 0.12642450142450143, 'fraction_numerical': 0.006944444444444444, 'mean_word_length': 3.396477495107632, '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': '4324110', 'n_tokens_mistral': 3686, 'n_tokens_neox': 3566, 'n_words': 990}