def validator(node, rrn):
        '''
        Colander validator that checks whether a given value is a valid
        Belgian national ID number .
        :raises colander.Invalid: If the value is no valid Belgian national ID number.
        '''

        def _valid(_rrn):
            x = 97 - (int(_rrn[:-2]) - (int(_rrn[:-2]) // 97) * 97)
            return int(_rrn[-2:]) == x

        if len(rrn) != 11:
            raise colander.Invalid(
                node,
                'Een rijksregisternummer moet 11 cijfers lang zijn.'
            )
        elif not _valid(rrn):
            valid_rrn = False
            if rrn[:1] == '0' or rrn[:1] == '1':
                rrn = '2' + rrn
                valid_rrn = _valid(rrn)
            if not valid_rrn:
                raise colander.Invalid(
                    node,
                    'Dit is geen correct rijksregisternummer.'
                )
def validator ( node , rrn ) : def _valid ( _rrn ) : x = 97 - ( int ( _rrn [ : - 2 ] ) - ( int ( _rrn [ : - 2 ] ) // 97 ) * 97 ) return int ( _rrn [ - 2 : ] ) == x if len ( rrn ) != 11 : raise colander . Invalid ( node , 'Een rijksregisternummer moet 11 cijfers lang zijn.' ) elif not _valid ( rrn ) : valid_rrn = False if rrn [ : 1 ] == '0' or rrn [ : 1 ] == '1' : rrn = '2' + rrn valid_rrn = _valid ( rrn ) if not valid_rrn : raise colander . Invalid ( node , 'Dit is geen correct rijksregisternummer.' )
Colander validator that checks whether a given value is a valid
        Belgian national ID number .
        :raises colander.Invalid: If the value is no valid Belgian national ID number.