コード例 #1
0
    def __classinit__(cls, new_attrs):
        FancyValidator.__classinit__(cls, new_attrs)
        # Don't bother doing anything if this is the most parent
        # Schema class (which is the only class with just
        # FancyValidator as a superclass):
        if cls.__bases__ == (FancyValidator, ):
            return cls
        # Scan through the class variables we've defined *just*
        # for this subclass, looking for validators (both classes
        # and instances):
        for key, value in new_attrs.iteritems():
            if key in ('pre_validators', 'chained_validators'):
                if is_validator(value):
                    msg = "Any validator with the name %s will be ignored." % \
                            (key,)
                    warnings.warn(msg, FERuntimeWarning)
                continue
            if is_validator(value):
                cls.fields[key] = value
                delattr(cls, key)
            # This last case means we're overwriting a validator
            # from a superclass:
            elif key in cls.fields:
                del cls.fields[key]

        for name, value in cls.fields.iteritems():
            cls.add_field(name, value)
コード例 #2
0
ファイル: schema.py プロジェクト: avanov/formencode
    def __classinit__(cls, new_attrs):
        FancyValidator.__classinit__(cls, new_attrs)
        # Don't bother doing anything if this is the most parent
        # Schema class (which is the only class with just
        # FancyValidator as a superclass):
        if cls.__bases__ == (FancyValidator,):
            return cls
        # Scan through the class variables we've defined *just*
        # for this subclass, looking for validators (both classes
        # and instances):
        for key, value in new_attrs.iteritems():
            if key in ('pre_validators', 'chained_validators'):
                if is_validator(value):
                    msg = "Any validator with the name %s will be ignored." % \
                            (key,)
                    warnings.warn(msg, FERuntimeWarning)
                continue
            if is_validator(value):
                cls.fields[key] = value
                delattr(cls, key)
            # This last case means we're overwriting a validator
            # from a superclass:
            elif key in cls.fields:
                del cls.fields[key]

        for name, value in cls.fields.iteritems():
            cls.add_field(name, value)
コード例 #3
0
ファイル: compound.py プロジェクト: avanov/formencode
 def __classinit__(cls, new_attrs):
     FancyValidator.__classinit__(cls, new_attrs)
     toAdd = []
     for name, value in new_attrs.iteritems():
         if is_validator(value) and value is not Identity:
             toAdd.append((name, value))
             # @@: Should we really delete too?
             delattr(cls, name)
     toAdd.sort()
     cls.validators.extend([value for _name, value in toAdd])
コード例 #4
0
 def __init__(self, *args, **kw):
     FancyValidator.__init__(self, *args, **kw)
     if no_country:
         warnings.warn(no_country, Warning, 2)