Schema validators and markers

Markers

Marker base class

class onctuous.validators.Marker(schema, msg=None)

Mark nodes for special treatment.

Optional Class

class onctuous.validators.Optional(schema, msg=None)

Mark a node in the schema as optional.

Required Class

class onctuous.validators.Required(schema, default=..., msg=None)

Mark a node in the schema as being required.

Extra Method

onctuous.validators.Extra(_)

Allow keys in the data that are not present in the schema.

Validators

Msg

onctuous.validators.Msg(schema, msg)

Report a user-friendly message if a schema fails to validate. Messages are only applied to invalid direct descendants of the schema.

Coerce

onctuous.validators.Coerce(target_type, msg=None)

Coerce a value to a type. If the input value of the validator is already of this type, tha value is retured immediately to prevent stupid crash like datetime(datime()). This way, Coerce can safely be used to make sure the type is OK.

If the type constructor throws a ValueError, the value will be marked as Invalid.

Parameters:target_type – target type for the coercion operation. May be any type

or callable.

IsTrue

onctuous.validators.IsTrue(msg=None)

Assert that a value is true, in the Python sense. “In the Python sense” means that implicitly false values, such as empty lists, dictionaries, etc. are treated as “false”:

IsFalse

onctuous.validators.IsFalse(msg=None)

Assert that a value is false, in the Python sense.

Boolean

onctuous.validators.Boolean(msg=None)

Convert human-readable boolean values to a bool.

Accepted values are 1, true, yes, on, enable, and their negatives. Non-string values are cast to bool.

Any

onctuous.validators.Any(*validators, **kwargs)

Use the first validated value.

Parameters:msg – Message to deliver to user if validation fails.
Returns:Return value of the first validator that passes.

All

onctuous.validators.All(*validators, **kwargs)

Value must pass all validators.

The output of each validator is passed as input to the next.

Parameters:msg – Message to deliver to user if validation fails.

Match

onctuous.validators.Match(pattern, msg=None)

Value must match the regular expression.

Pattern may also be a compiled regular expression:

Sub

onctuous.validators.Sub(pattern, substitution, msg=None)

Regex substitution.

Url

onctuous.validators.Url(msg=None)

Verify that the value is a URL.

IsFile

onctuous.validators.IsFile(msg=None)

Verify the file exists.

IsDir

onctuous.validators.IsDir(msg=None)

Verify the directory exists.

PathExists

onctuous.validators.PathExists(msg=None)

Verify the path exists, regardless of its type.

InRange

onctuous.validators.InRange(min=None, max=None, msg=None)

Limit a value to a range.

Either min or max may be omitted.

Raises Invalid:If the value is outside the range and clamp=False.

Clamp

onctuous.validators.Clamp(min=None, max=None, msg=None)

Clamp a value to a range.

Either min or max may be omitted.

Length

onctuous.validators.Length(min=None, max=None, msg=None)

The length of a value must be in a certain range.

ToLower

onctuous.validators.ToLower(v)

Transform a string to lower case.

ToUpper

onctuous.validators.ToUpper(v)

Transform a string to upper case.

Capitalize

onctuous.validators.Capitalize(v)

Capitalise a string.

Title

onctuous.validators.Title(v)

Title case a string.

Project Versions

Table Of Contents

Previous topic

Schema class

This Page