Fields

Fields are the validation/cleaning mechanic of tinyobj. Each is responsible for receiving a value (from the database, for example), cleaning it, and returning the cleaned value. A reference to the original value is not kept at this time, so reserializing the data for your specific use case is left as an exercise to the reader.

The base object is Field, of which TinyObj will detect subclasses to use as fields:

class tinyobj.fields.Field[source]

base for other fields

clean(value)[source]

clean a value, returning the cleaned value

initialize(value=())[source]

initialize returns a cleaned value or the default, raising ValueErrors as necessary.

Subclasses

tinyobj implements a number of fields to do validation, etc.

class tinyobj.fields.NumberField(t=<type 'float'>, allow_negative=True, allow_positive=True)[source]

accept and validate numbers

takes a type to convert values to, can be (EG) float, int, long, or complex.

clean(value)[source]

clean a value, converting and performing bounds checking

class tinyobj.fields.BoolField(default=False)[source]

accept and validate boolean values

note that this field will just call bool on values, this may not be your desired behavior so you might want to implement a subclass that parses truthy/falsey values in a way specific to your application

class tinyobj.fields.TextField[source]

accept and validate text.

Uses the Python implementation’s appropriate unicode value (IE unicode on 2.x and str on 3.x)

class tinyobj.fields.NoValidationField[source]

doesn’t validate at all, but returns the value passed (defaulting to None)