<commit_before># -*- coding: utf-8 -*-

from . import convs, widgets, fields
from ..utils import N_


class PasswordConv(convs.Char):

    def from_python(self, value):
        return dict([(field.name, None) for field in self.field.fields])

    def get_initial(self):
        return ''

    def to_python(self, value):
        etalon = value[list(value)[0]]
        for field in self.field.fields:
            self.assert_(value[field.name] == etalon,
                         N_('password and confirm mismatch'))
        self.assert_(etalon not in (None, '')  or self.null,
                     N_('password required'))
        return etalon


def PasswordSet(name='password',
                 min_length=3, max_length=200, null=True,
                 password_label=None, confirm_label='confir<PASSWORD>',
                 **kwargs):
        # class implementation has problem with Fieldset copying:
        # it requires to save all kwargs in object's __dict__
        char = convs.Char(min_length=min_length, max_length=max_length, null=null)
        items = (('pass', password_label), ('conf', confirm_label))
        
        kwargs['fields'] = [fields.Field(subfieldname,
                                         conv=char,
                                         label=label,
                                         widget=widgets.PasswordInput)
                            for subfieldname, label in items]
        kwargs.setdefault('conv', PasswordConv(null=null))
        kwargs.setdefault('template', 'fieldset-line')
        
        return fields.FieldSet(name, get_initial=lambda: '', **kwargs)
<commit_msg>PasswordConv fixes<commit_after># -*- coding: utf-8 -*-

from . import convs, widgets, fields
from ..utils import N_


class PasswordConv(convs.Char):

    error_mismatch = N_('password and confirm mismatch')
    error_required = N_('password required')

    def from_python(self, value):
        return dict([(field.name, None) for field in self.field.fields])

    def get_initial(self):
        return ''

    def to_python(self, value):
        etalon = value[list(value)[0]]
        for field in self.field.fields:
            self.assert_(value[field.name] == etalon,
                         self.error_mismatch)
        self.assert_(etalon not in (None, '')  or self.required,
                     self.error_required)
        return etalon


def PasswordSet(name='password',
                 min_length=3, max_length=200, null=True,
                 password_label=None, confirm_label='<PASSWORD>',
                 **kwargs):
        # class implementation has problem with Fieldset copying:
        # it requires to save all kwargs in object's __dict__
        char = convs.Char(min_length=min_length, max_length=max_length, null=null)
        items = (('pass', password_label), ('conf', confirm_label))
        
        kwargs['fields'] = [fields.Field(subfieldname,
                                         conv=char,
                                         label=label,
                                         widget=widgets.PasswordInput)
                            for subfieldname, label in items]
        kwargs.setdefault('conv', PasswordConv(null=null))
        kwargs.setdefault('template', 'fieldset-line')
        
        return fields.FieldSet(name, get_initial=lambda: '', **kwargs)

{'fraction_non_alphanumeric': 0.10784901138406232, 'fraction_numerical': 0.0035949670461354103, 'mean_word_length': 1.9732858414959928, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1429006', 'n_tokens_mistral': 897, 'n_tokens_neox': 862, 'n_words': 211}