user_objects

UserObject

class wysdom.UserObject(value: Optional[Mapping[str, Any]] = None, json_dom_info: Optional[wysdom.dom.DOMElement.DOMInfo] = None, **kwargs: Any)

Bases: wysdom.dom.DOMObject.DOMObject

Base class for user-defined DOM objects.

Parameters
  • value – A dict-like object to populate the underlying data object’s keys. May be provided alone or in conjunction with keyword arguments.

  • json_dom_info – A named tuple with parameters (element, document, parent, element_key) which specify this object’s position in a larger document object model. This is only required if you need to set these values when creating an object manually: when objects are created as part of a DOM specification, these values are populated automatically.

  • kwargs – Keyword arguments to be used to populate the underlying data object’s keys. May be provided alone or in conjunction with value.

  • value – A dict (or any collections.abc.Mapping) containing the data to populate this object’s properties.

  • json_dom_info – A DOMInfo named tuple containing information about this object’s position in the DOM.

UserProperties

class wysdom.user_objects.UserProperties(user_class: Type[wysdom.user_objects.UserObject.UserObject], additional_properties: Union[bool, wysdom.base_schema.Schema.Schema] = False)

Bases: wysdom.dom.DOMProperties.DOMProperties

A container for property information for a UserObject subclass.

Parameters
  • user_class – The subclass of UserObject to extract properties from. Properties will be extracted from the class’s UserProperty descriptors.

  • additional_properties – Defines whether a DOMObject permits additional dynamically-named properties. Can be True or False, or can be set to a specific Schema to restrict the permitted types of any additional properties.

UserProperty

class wysdom.UserProperty(property_type: Union[Type, wysdom.base_schema.Schema.Schema], optional: Optional[bool] = None, name: Optional[str] = None, default: Optional[Any] = None, default_function: Optional[Callable] = None, persist_defaults: Optional[bool] = None, pattern: Optional[str] = None)

Bases: object

A data descriptor for creating attributes in user-defined subclasses of UserObject which are mapped to keys in the underlying data object and to the properties key in the object’s JSON schema.

Parameters
  • property_type

    The data type or schema for this property. Must be one of:

    • A primitive Python type (str, int, bool, float)

    • A subclass of UserObject

    • An instance of Schema

  • optional – Determines whether this property is optional in the underlying data object. If default or default_function are set, this will default to True, otherwise False.

  • name – The name of this property in the underlying data object. If not provided, this defaults to the name of the attribute on the UserObject instance that owns the property.

  • default – A static value which provides a default value for this property. Cannot be set in conjunction with default_function.

  • default_function – A function which provides a default value for this property. The function must have a single positional argument, self, which is passed the UserObject instance that owns the property. Cannot be set in conjunction with default.

  • persist_defaults – If this property is set to True and a UserProperty has either the default or default_function property, when the UserProperty returns a default value that value will also be explicitly stored in the underlying data object. This is often desirable behavior if the UserProperty returns another object and your code expects it to return the same object instance each time it is accessed.

  • pattern – A regex pattern to validate the values of this property against. Use only for str properties.

ListProperty

class wysdom.ListProperty(items: Union[Type, wysdom.base_schema.Schema.Schema], optional: Optional[bool] = None, name: Optional[str] = None, default: Optional[Any] = None, default_function: Optional[Callable] = None, persist_defaults: Optional[bool] = None)

Bases: wysdom.user_objects.UserProperty.UserProperty

A data descriptor for creating attributes in user-defined subclasses of UserObject with a property_type of SchemaArray.

Parameters
  • items

    The permitted data type or schema for the items of the underlying SchemaArray. Must be one of:

    A primitive Python type (str, int, bool, float) A subclass of UserObject. An instance of Schema.

  • optional – Determines whether this property is optional in the underlying data object. If default or default_function are set, this will default to True, otherwise False.

  • name – The name of this property in the underlying data object. If not provided, this defaults to the name of the attribute on the UserObject instance that owns the property.

  • default – A static value which provides a default value for this property. Cannot be set in conjunction with default_function.

  • default_function – A function which provides a default value for this property. The function must have a single positional argument, self, which is passed the UserObject instance that owns the property. Cannot be set in conjunction with default.

  • persist_defaults – If this property is set to True and a UserProperty has either the default or default_function property, when the UserProperty returns a default value that value will also be explicitly stored in the underlying data object. This is often desirable behavior if the UserProperty returns another object and your code expects it to return the same object instance each time it is accessed.

DictProperty

class wysdom.DictProperty(items: Union[Type, wysdom.base_schema.Schema.Schema], optional: Optional[bool] = None, name: Optional[str] = None, default: Optional[Any] = None, default_function: Optional[Callable] = None, persist_defaults: Optional[bool] = None, key_pattern: Optional[str] = None)

Bases: wysdom.user_objects.UserProperty.UserProperty

A data descriptor for creating attributes in user-defined subclasses of UserObject with a property_type of SchemaDict.

Parameters
  • items

    The permitted data type or schema for the properties of the underlying SchemaDict. Must be one of:

    A primitive Python type (str, int, bool, float) A subclass of UserObject. An instance of Schema.

  • optional – Determines whether this property is optional in the underlying data object. If default or default_function are set, this will default to True, otherwise False.

  • name – The name of this property in the underlying data object. If not provided, this defaults to the name of the attribute on the UserObject instance that owns the property.

  • default – A static value which provides a default value for this property. Cannot be set in conjunction with default_function.

  • default_function – A function which provides a default value for this property. The function must have a single positional argument, self, which is passed the UserObject instance that owns the property. Cannot be set in conjunction with default.

  • persist_defaults – If this property is set to True and a UserProperty has either the default or default_function property, when the UserProperty returns a default value that value will also be explicitly stored in the underlying data object. This is often desirable behavior if the UserProperty returns another object and your code expects it to return the same object instance each time it is accessed.

  • key_pattern – A regex pattern to validate the keys of the dictionary against.