<commit_before>#!/usr/bin/env python
#coding=utf-8
import copy
from toughlib.btforms import  attrget
from toughlib.btforms import storage
from toughlib.btforms import AttributeList

class Form(object):

    def __init__(self, *inputs, **kw):
        self.inputs = inputs
        self.valid = True
        self.note = None
        self.validators = kw.pop('validators', [])

    def __call__(self, x=None):
        o = copy.deepcopy(self)
        if x: o.validates(x)
        return o

    @property
    def errors(self):
        return ",".join([u"%s error,%s" % (i.description, i.note) for i in self.inputs if i.note])

    def validates(self, source=None, _validate=True, **kw):
        source = source or kw
        out = True
        for i in self.inputs:
            v = attrget(source, i.name)
            if _validate:
                out = i.validate(v) and out
            else:
                i.set_value(v)
        if _validate:
            out = out and self._validate(source)
            self.valid = out
        return out

    def _validate(self, value):
        self.value = value
        for v in self.validators:
            if not v.valid(value):
                self.note = v.msg
                return False
        return True

    def fill(self, source=None, **kw):
        return self.validates(source, _validate=False, **kw)
<commit_msg>fix: dataform bug<commit_after>#!/usr/bin/env python
#coding=utf-8
import copy
from toughlib.btforms import  attrget
from toughlib.btforms import storage
from toughlib.btforms import AttributeList

class Form(object):

    def __init__(self, *inputs, **kw):
        self.inputs = inputs
        self.valid = True
        self.note = None
        self.validators = kw.pop('validators', [])

    def __call__(self, x=None):
        o = copy.deepcopy(self)
        if x: o.validates(x)
        return o

    @property
    def errors(self):
        return ",".join([u"%s error,%s" % (i.description, i.note) for i in self.inputs if i.note])

    def validates(self, source=None, _validate=True, **kw):
        source = source or kw
        out = True
        for i in self.inputs:
            if i.name in source:
                v = attrget(source, i.name)
            else:
                v = i.value
            if _validate:
                out = i.validate(v) and out
            else:
                i.set_value(v)
        if _validate:
            out = out and self._validate(source)
            self.valid = out
        return out

    def _validate(self, value):
        self.value = value
        for v in self.validators:
            if not v.valid(value):
                self.note = v.msg
                return False
        return True

    def fill(self, source=None, **kw):
        return self.validates(source, _validate=False, **kw)

{'fraction_non_alphanumeric': 0.1052257376466406, 'fraction_numerical': 0.0007109847138286527, 'mean_word_length': 1.8168168168168168, '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': '2241108', 'n_tokens_mistral': 855, 'n_tokens_neox': 828, 'n_words': 243}