Table of Contents

Module: objecttree SessionUtil/objecttree.py

Functions   
basic_tree_to_instance_tree
escape_dictionary_key
instance_tree_to_basic_tree
is_simple_sequence
unescape_dictionary_key
write_basic_tree
write_sequence
write_simple_sequence
  basic_tree_to_instance_tree 
basic_tree_to_instance_tree ( btree,  name_to_class )

Exceptions   
ValueError, "Can't convert type " + str( t )
ValueError, 'Unknown class ' + classname
  escape_dictionary_key 
escape_dictionary_key ( key )

Make sure the word class does not occur as a dictionary key. Prefix a key that is class with a backslash. Also prefix all keys that start with a backslash with another backslash.

  instance_tree_to_basic_tree 
instance_tree_to_basic_tree (
        itree,
        already_converted=None,
        allow_conversion=1,
        )

A tree of instances and basic Python types is converted to a tree of only basic types (numbers, strings, None, tuples, lists, dictionaries).

Instances are replaced by dictionaries which include a key indicating the instance class name. Instance should have an attribute called state_attributes set to a sequence of attribute names. These are the only attributes that will be included in the basic tree.

An instance cannot appear more than once in the input tree. A dictionary key cannot be an instance.

These two restrictions could be lifted in a more complex implementation that makes unique copies of the instances and returns an object that gives the tree of basic types with references to unique instances, and a list of the unique instances converted to basic types. This has not been done since it is not currently needed.

Exceptions   
ValueError, "Can't convert type " + str( t )
ValueError, 'Instance appears more than once in tree ' + str( itree )
ValueError, 'Not allowed to convert instance ' + str( itree )
  is_simple_sequence 
is_simple_sequence ( seq )

A simple sequence is of length <= 4 and contains only numbers or None.

  unescape_dictionary_key 
unescape_dictionary_key ( key )

Remove leading backslash from string keys.

  write_basic_tree 
write_basic_tree (
        btree,
        file,
        indent='',
        start_of_line=1,
        )

Write a tree involving only basic Python types (numbers, strings, None, tuples, lists, dictionaries) to a file formatted for human readability.

Exceptions   
ValueError, "Can't write type " + str( t )
  write_sequence 
write_sequence (
        btree,
        file,
        indent,
        sindent,
        )

Write sequence elements on separate lines.

  write_simple_sequence 
write_simple_sequence (
        btree,
        file,
        indent,
        )

Write sequence elements on one line.


Table of Contents

This document was automatically generated on Tue Nov 5 16:56:39 2002 by HappyDoc version 2.0.1