Scheme Serialization (readwrite)

Scheme save/load routines.

orangecanvas.scheme.readwrite.dumps(obj, format='literal', prettyprint=False, pickle_fallback=False)

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

Indent an instance of a Element. Based on (http://effbot.org/zone/element-lib.htm#prettyprint).

orangecanvas.scheme.readwrite.literal_dumps(obj, prettyprint=False, indent=4)

Write obj into a string as a python literal.

orangecanvas.scheme.readwrite.parse_scheme(scheme, stream, error_handler=None, allow_pickle_data=False)

Parse a saved scheme from stream and populate a scheme instance (Scheme). error_handler if given will be called with an exception when a ‘recoverable’ error occurs. By default the exception is simply raised.

Parameters:
  • scheme (Scheme) – A scheme instance to populate with the contents of stream.
  • stream (file-like object) – A file like object opened for reading.
  • error_hander (function, optional) – A function to call with an exception instance when a recoverable error occurs.
  • allow_picked_data (bool, optional) – Specifically allow parsing of picked data streams.
orangecanvas.scheme.readwrite.parse_scheme_v_1_0(etree, scheme, error_handler, widget_registry=None, allow_pickle_data=False)

ElementTree Instance of an old .ows scheme format.

orangecanvas.scheme.readwrite.parse_scheme_v_2_0(etree, scheme, error_handler, widget_registry=None, allow_pickle_data=False)

Parse an ElementTree instance.

orangecanvas.scheme.readwrite.scheme_node_from_element(node_el, registry)

Create a SchemeNode from an Element instance.

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

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

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

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.sniff_version(stream)

Parse a scheme stream and return the scheme’s serialization version string.

orangecanvas.scheme.readwrite.string_eval(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)

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)

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