Ñò †°Ic@sddkTddkTddklZddkZdgZdefd„ƒYZdd„Zd„Zd „Z d „Z d efd „ƒYZ dS( iÿÿÿÿ(t*(t_NtSchemacBseZdZgZgZeZeZeZ eZ e Z hZ gZhedƒd6edƒd6edƒd6ZdZd „Zd „Zd „Zd „Zd„Zd„ZeieƒZd„ZeieƒZd„ZeieƒZd„Zd„Zd„ZRS(sG A schema validates a dictionary of values, applying different validators (be key) to the different values. If allow_extra_fields=True, keys without validators will be allowed; otherwise they will raise Invalid. If filter_extra_fields is set to true, then extra fields are not passed back in the results. Validators are associated with keys either with a class syntax, or as keyword arguments (class syntax is usually easier). Something like:: class MySchema(Schema): name = Validators.PlainText() phone = Validators.PhoneNumber() These will not be available as actual instance variables, but will be collected in a dictionary. To remove a validator in a subclass that is present in a superclass, set it to None, like:: class MySubSchema(MySchema): name = None Note that missing fields are handled at the Schema level. Missing fields can have the 'missing' message set to specify the error message, or if that does not exist the *schema* message 'missingValue' is used. s*The input field %(name)s was not expected.t notExpecteds Missing valuet missingValues7The input must be dict-like (not a %(type)s: %(value)r)t badDictTypetfieldstchained_validatorstpre_validatorscCsÙti||ƒ|itfjo|Sxz|iƒD]l\}}|djoq5nt|ƒo||i|R?R@RRRAtpre((s5/usr/lib/python2.6/site-packages/formencode/schema.pyt _from_pythonÑst  )        !         cCsY|dj o8|i|ijo|i|_n|ii|ƒn|ii|ƒdS(N(R(RRH(RRR;((s5/usr/lib/python2.6/site-packages/formencode/schema.pytadd_chained_validators  cCsX|dj o:|i|ijo|iiƒ|_n||i|     \ B      ic CsNt|tƒo5yt|ƒSWqJttfj ot|ƒSXnt|tƒo~|iƒ}|iƒdd|i g}|D]D\}}|dj o+|d|t |dt |ƒdƒfq„q„~ƒSt|t ƒoRdd|i g}|D].}|dj o|dt |d|ƒqüqü~ƒSt|tƒo|SdS(Ns%s t s%s: %stindentis%s(R6t ExceptiontstrtUnicodeDecodeErrortUnicodeEncodeErrortunicodeR7R tsortRFR(R9tlentlistt basestring(tvRctlt_[1]tkRt_[2]((s5/usr/lib/python2.6/site-packages/formencode/schema.pyR9@s(  C 3cCsOxH|D]@}||jot||||ƒ||>> def validate(form_values, state, validator): ... if form_values.get('country', 'US') == 'US': ... if not form_values.get('state'): ... return {'state': 'You must enter a state'} ... if not form_values.get('country'): ... form_values['country'] = 'US' This tests that the field 'state' must be filled in if the country is US, and defaults that country value to 'US'. The ``validator`` argument is the SimpleFormValidator instance, which you can use to format messages or keep configuration state in if you like (for simple ad hoc validation you are unlikely to need it). To create a validator from that function, you would do:: >>> from formencode.schema import SimpleFormValidator >>> validator = SimpleFormValidator(validate) >>> validator.to_python({'country': 'US', 'state': ''}, None) Traceback (most recent call last): ... Invalid: state: You must enter a state >>> validator.to_python({'state': 'IL'}, None) {'country': 'US', 'state': 'IL'} The validate function can either return a single error message (that applies to the whole form), a dictionary that applies to the fields, None which means the form is valid, or it can raise Invalid. Note that you may update the value_dict *in place*, but you cannot return a new value. Another way to instantiate a validator is like this:: >>> @SimpleFormValidator.decorate() ... def MyValidator(value_dict, state): ... return None # or some more useful validation After this ``MyValidator`` will be a ``SimpleFormValidator`` instance (it won't be your function). tfunccCst|iddƒ|_dS(NRZ(R)R€R(RZ(RR((s5/usr/lib/python2.6/site-packages/formencode/schema.pyRµscCs³|iƒ}|i|||ƒ}|p|St|tƒot|||ƒ‚n]t|tƒo"tt|ƒ||d|ƒ‚n+t|tƒo |‚ntd|ƒ‚|S(NR#sInvalid error value: %r(RPR€R6RlRR7R9t TypeError(RR:RR=((s5/usr/lib/python2.6/site-packages/formencode/schema.pyR&¸s    c s‡‡fd†}|S(Ncs ˆ|ˆS(N((R€(tkwR(s5/usr/lib/python2.6/site-packages/formencode/schema.pyt decoratorÎs((RR‚Rƒ((R‚Rs5/usr/lib/python2.6/site-packages/formencode/schema.pytdecorateÍs(sfunc( RXRYRZt__unpackargs__R4R"RR&R!R„t classmethod(((s5/usr/lib/python2.6/site-packages/formencode/schema.pyRs.   ( t interfacestapiRR`t__all__R RR9R8RrRvR(((s5/usr/lib/python2.6/site-packages/formencode/schema.pyts    ÿ9