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 (http://effbot.org/zone/element-lib.htm#prettyprint).

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

Write obj into a string as a python literal.

Note

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

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

    Warning

    The exact type of the values will be lost.

Returns:

repr – String representation of obj

Return type:

str

See also

ast.literal_eval

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

  • ValueError – If obj is a recursive structure.

orangecanvas.scheme.readwrite.parse_ows_etree_v_2_0(tree: ElementTree) _scheme[source]

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.

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

orangecanvas.scheme.readwrite.string_eval(source: str) str[source]

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

>>> string_eval("'a string'")
a string
orangecanvas.scheme.readwrite.terminal_eval(source: str) str | bytes | int | float | complex | bool | None[source]

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

>>> terminal_eval("True")
True
orangecanvas.scheme.readwrite.tuple_eval(source: str) tuple[source]

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')