dom

DOMDict

class wysdom.dom.DOMDict(value: Optional[Mapping[str, Any]] = None, json_dom_info: Optional[DOMInfo] = None, item_type: Optional[Schema] = None)

Bases: wysdom.dom.DOMObject.DOMObject, Generic[wysdom.dom.DOMDict.T_co]

An object with dynamic properties (corresponding to a Python dict).

Parameters
  • 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.

  • item_type – A Schema object specifying what constitutes a valid property of this object.

DOMElement

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

Bases: abc.ABC

Abstract base class for any DOM element.

Parameters
  • value – A data structure containing the data to populate this element.

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

  • kwargs – Keyword arguments.

abstract to_builtin()Any

Returns the contents of this DOM object as a Python builtin. Return type varies depending on the specific object type.

walk_elements()Iterator[wysdom.dom.DOMElement.DOMInfo]

Walk through the full tree structure within this DOM element. Returns an iterator of DOMInfo tuples in the form (element, document, parent element_key).

Returns

An iterator of DOMInfo tuples.

DOMInfo

class wysdom.dom.DOMInfo(element: Optional[DOMElement] = None, document: Optional[DOMElement] = None, parent: Optional[DOMElement] = None, element_key: Optional[str] = None)

Bases: tuple

Named tuple containing information about a DOM element’s position within the DOM.

Parameters
  • element – The DOMElement that this DOMInfo tuple provides information for.

  • document – The owning document for a DOMElement, if it exists.

  • parent – The parent element of a DOMElement, if it exists.

  • element_key – The key of a particular DOMElement in its parent element, if it can be referred to by a key (i.e. if it its parent element is a Mapping).

Create new instance of DOMInfo(element, document, parent, element_key)

property document

Alias for field number 1

property element

Alias for field number 0

property element_key

Alias for field number 3

property parent

Alias for field number 2

DOMList

class wysdom.dom.DOMList(value: Iterable, json_dom_info: Optional[wysdom.dom.DOMElement.DOMInfo] = None, item_type: Optional[wysdom.base_schema.Schema.Schema] = None)

Bases: wysdom.dom.DOMElement.DOMElement, collections.abc.MutableSequence, Generic[wysdom.dom.DOMList.T_co]

An array element (corresponding to a Python list).

Parameters
  • value – A list (or any Typing.Iterable) containing the data to populate this object’s items.

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

  • item_type – A Schema object specifying what constitutes a valid item in this array.

insert(index: int, item: Any)None

S.insert(index, value) – insert value before index

to_builtin()List[Any]

Returns the contents of this DOM object as a Python builtin.

Returns

A Python list containing this object’s data

walk_elements()Iterator[wysdom.dom.DOMElement.DOMInfo]

Walk through the full tree structure within this DOM element. Returns an iterator of DOMInfo tuples in the form (element, document, parent element_key).

Returns

An iterator of DOMInfo tuples.

DOMObject

class wysdom.dom.DOMObject(value: Mapping[str, Any] = None, json_dom_info: DOMInfo = None)

Bases: wysdom.dom.DOMElement.DOMElement, collections.abc.MutableMapping

An object with named properties.

Parameters
  • 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.

to_builtin()Dict[str, Any]

Returns the contents of this DOM object as a Python builtin.

Returns

A Python dict containing this object’s data

walk_elements()Iterator[wysdom.dom.DOMElement.DOMInfo]

Walk through the full tree structure within this DOM element. Returns an iterator of DOMInfo tuples in the form (element, document, parent element_key).

Returns

An iterator of DOMInfo tuples.

DOMProperties

class wysdom.dom.DOMProperties(properties: Optional[Dict[str, wysdom.base_schema.Schema.Schema]] = None, required: Optional[Set[str]] = None, additional_properties: Union[bool, wysdom.base_schema.Schema.Schema] = False)

Bases: object

A container for property information for a DOMObject.

Parameters
  • properties – A dictionary of Schema objects defining the expected names and types of a DOMObject’s properties.

  • required – A set of the property names that are required for an instance to be valid.

  • 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.

additional_properties: Union[bool, wysdom.base_schema.Schema.Schema] = False
properties: Dict[str, wysdom.base_schema.Schema.Schema] = None
required: Set[str] = None

functions

wysdom.dom.functions.document(element: wysdom.dom.DOMElement.DOMElement)Optional[wysdom.dom.DOMElement.DOMElement]

Retrieve the owning document for a DOMElement, if it exists.

Parameters

element – A DOM element

Returns

The owning document for that DOM element, or None if none exists

wysdom.dom.functions.dom(element: wysdom.dom.DOMElement.DOMElement)wysdom.dom.DOMElement.DOMInfo

Retrieve a DOMInfo object for a DOMElement containing information about that element’s position in the DOM.

Parameters

element – A DOM element

Returns

The DOMInfo object for that DOM element

wysdom.dom.functions.key(element: wysdom.dom.DOMElement.DOMElement)Optional[str]

Retrieve the key of a particular DOMElement in its parent element, if it can be referred to by a key (i.e. if it its parent element is a collections.abc.Mapping).

Parameters

element – A DOM element

Returns

The key of that DOM element in its parent, or None if it has no key

wysdom.dom.functions.parent(element: wysdom.dom.DOMElement.DOMElement)Optional[wysdom.dom.DOMElement.DOMElement]

Retrieve the parent element of a DOMElement, if it exists.

Parameters

element – A DOM element

Returns

The parent element of that DOM element, or None of none exists

wysdom.dom.functions.schema(element: wysdom.dom.DOMElement.DOMElement)wysdom.base_schema.Schema.Schema

Retrieve the Schema object for a particular DOMElement.

Parameters

element – A DOM element

Returns

The Schema object associated with that DOM element