

Invalid: Please enter a valid IP address (a.b.c.d) or IP network (a.b.c.d/e) to_python ( 'asdf' ) Traceback (most recent call last). Invalid: The network size (bits) must be within the range of 8-32 (not '1') > cidr. Invalid: The octets must be within the range of 0-255 (not '299') > cidr. to_python ( '299.0.0.1' ) Traceback (most recent call last). Messages badType: The input must be a string (not a %(type)s: %(value)r) empty: Please enter a value noneType: The input must be a string (not None) base64encode ( value ) ¶Įncode a string in base64, stripping whitespace and removing If you overwrite one of the internal methods, you usually These parameters are handled at the level of the external _validate_other() will not be called when accept_python: If True (the default), then. from_python()) is invalid, this value will be returned. if_invalid_python: If set, when the Python value (converted with if_invalid: If set, then when this validator would raise Invalid during strip: If true and the input is a string, strip it (occurs before empty not_empty: If true, then if an empty value is given raise an error. To false (empty list, empty string, None, etc), but not the 0 orįalse objects. They should be reusable andĪll subclasses can take the arguments/instance variables: if_empty: If set, then this value will be returned if the input evaluates Validators should have no internal state besides the If the declarative.Declarative model doesn’t work for this. Subclasses can also override the _init_() method Raised in at least one these four methods, not matter which. You should make sure that all possible validation errors are _validate_python() however._validate_python(value, state): Validates a Python value, either the result of.

_convert_to_python() in some reasonable way, returningĪ string._validate_other(value, state): Validates the source, before. Only meant to convert the value, not to fully validate it._convert_from_python(value, state): Should undo. The converted value, or raises an Invalid exception if theĬonversion cannot be done. None of these have to be overridden, only the ones thatĪre appropriate for the validator._convert_to_python(value, state): This method converts the source to a Python value. Important internal methods that can be overridden. These two external methods make use of the following four TheĪrgument for this exception is the (potentially HTML-formatted)Įrror message to give the om_python(value, state): Reverses. Value is not valid, an Invalid exception is raised. to_python(value, state): Attempts to convert the value. Validators have two important external methods. There is no formal distinction made here. A subclass can validate, convert, or do both. FancyValidator ( *args, **kw ) ¶įancyValidator is the (abstract) superclass for various validatorsĪnd converters. This to accumulate all possible messages. Not useful for functional, except to inspect what values areĪvailable. Return any validators that this validator contains. The placement of all the messages? Well, probably so. That messages could be unpacked into a rendered form to see Messages that a validator or compound validator (like Schemas)Ĭan Should this produce a more structured set of messages, so Intended for documentation purposes, to show someone all the Return a dictionary of all the messages of this validator, andĪny subvalidators if present. See IValidator for more, andįancyValidator for the more common (and more featureful) class. If encode_variables is true, then this will return a flatĭictionary, encoded with variable_encode class formencode.api. Returns the error as a simple data structure – lists, _init_ ( msg, value, state, error_list=None, error_dict=None ) ¶ unpack_errors ( encode_variables=False, dict_char='.', list_char='-' ) ¶

error_dict: Like error_list, but for dictionary compound validators. Values – valid values will have None instead of an exception.

The list will be the same length as the number of error_list: If this was a compound validator that takes a repeating value,Īnd sub-validator(s) had errors, then this is a list of thoseĮxceptions. state: The state that went with this validator. str(self): The message describing the error, with values substituted. substituteArgs: The arguments (a dictionary) to go with msg. You want HTML quoting of values, you can apply that. Public attributes: msg: The message, without values substituted. This is raised in response to invalid input. Invalid ( msg, value, state, error_list=None, error_dict=None ) ¶ Returns whether obj is a validator object or not. These functions are used mostly internally by FormEncode.Ĭore classes for validation.
