Scheme Serialization (readwrite)

Scheme save/load routines.

exception orangecanvas.scheme.readwrite.InvalidFormatError[source]
exception orangecanvas.scheme.readwrite.UnknownWidgetDefinition[source]
exception orangecanvas.scheme.readwrite.UnsupportedFormatVersionError[source]
orangecanvas.scheme.readwrite.dumps(obj, format='literal', prettyprint=False, pickle_fallback=False)[source]

Serialize obj using format (‘json’ or ‘literal’) and return its string representation and the used serialization format (‘literal’, ‘json’ or ‘pickle’).

If pickle_fallback is True and the serialization with format fails object’s pickle representation will be returned

orangecanvas.scheme.readwrite.indent(element, level=0, indent='\t')[source]

Indent an instance of a Element. Based on (

orangecanvas.scheme.readwrite.literal_dumps(obj, indent=None, relaxed_types=True)[source]

Write obj into a string as a python literal.


set objects are not supported as the empty set is not representable as a literal.

  • obj (Any) –

  • indent (Optional[int]) – If not None then it is the indent for the pretty printer.

  • relaxed_types (bool) –

    Relaxed type checking. In addition to exact builtin numeric types, the numbers.Integer, numbers.Real are checked and allowed if their repr matches that of the builtin.


    The exact type of the values will be lost.


repr – String representation of obj

Return type


See also


  • TypeError – If obj contains non builtin types that cannot be represented as a literal value.

  • ValueError – If obj is a recursive structure.


Parset an xml.etree.ElementTree struct into a intermediate workflow representation.

orangecanvas.scheme.readwrite.scheme_to_etree(scheme, data_format='literal', pickle_fallback=False)[source]

Return an xml.etree.ElementTree representation of the scheme.

orangecanvas.scheme.readwrite.scheme_to_ows_stream(scheme, stream, pretty=False, pickle_fallback=False)[source]

Write scheme to a a stream in Orange Scheme .ows (v 2.0) format.

  • scheme (Scheme) – A Scheme instance to serialize.

  • stream (file-like object) – A file-like object opened for writing.

  • pretty (bool, optional) – If True the output xml will be pretty printed (indented).

  • pickle_fallback (bool, optional) – If True allow scheme node properties to be saves using pickle protocol if properties cannot be saved using the default notation.


Evaluate a python string literal source. Raise ValueError if source is not a string literal.

>>> string_eval("'a string'")
a string

Evaluate a python ‘constant’ (string, number, None, True, False) source. Raise ValueError is not a terminal literal.

>>> terminal_eval("True")

Evaluate a python tuple literal source where the elements are constrained to be int, float or string. Raise ValueError if not a tuple literal.

>>> tuple_eval("(1, 2, '3')")
(1, 2, '3')