Package ptree
[hide private]
[frames] | no frames]

Source Code for Package ptree

 1  # 
 2  # ptree -- An xml.etree implementation with parent pointers. 
 3  # 
 4  # -------------------------------------------------------------------- 
 5  # The ptree package is 
 6  # 
 7  # Copyright (c) 2007 by Edward Loper 
 8  # 
 9  # By obtaining, using, and/or copying this software and/or its 
10  # associated documentation, you agree that you have read, understood, 
11  # and will comply with the following terms and conditions: 
12  # 
13  # Permission to use, copy, modify, and distribute this software and 
14  # its associated documentation for any purpose and without fee is 
15  # hereby granted, provided that the above copyright notice appears in 
16  # all copies, and that both that copyright notice and this permission 
17  # notice appear in supporting documentation. 
18  # 
19  # THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 
20  # INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN 
21  # NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR 
22  # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 
23  # OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 
24  # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 
25  # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 
26  # -------------------------------------------------------------------- 
27   
28  """ 
29  Two drop-in replacements for xml.etree.ElementTree with elements that 
30  automatically keep track of parent pointers.  This package defines two 
31  objects, each of which provide the same interface as the 
32  xml.etree.ElementTree module: 
33   
34    - ptree.ParentedTree: Each element keeps track of a single parent 
35      pointer, returned by the element's `parent()` method.  Elements 
36      may have at most one parent; i.e., subtrees may not be shared. 
37      Any attempt to do use a single element as a child for multiple 
38      parents will generate a ValueError. 
39   
40    - ptree.MultiParentedTree: Each element keeps track of a list of 
41      parent pointers, returned by the element's `parents()` method. 
42      Elements may have zero or more parients; i.e., subtrees may be 
43      shraed.  If a single Element is used as multiple children of the 
44      same parent, then that parent will appear multiple times in the 
45      parents list. 
46   
47  Aside from addition of parent pointers, these two objects should act 
48  identically to xml.etree.ElementTree. 
49   
50  Note: Mixing of etree implementations is not supported.  I.e., you 
51  should never construct a tree that combines elements from ParentedTree 
52  with elements from MultiParentedTree, or elements from either of these 
53  implementations with elements from any other implementation.  Doing so 
54  may result in incorrect parent pointers and ValueError exceptions. 
55  """ 
56   
57  __all__ = ['ParentedTree', 'MultiParentedTree', 
58             'etreeimpl', 'elements'] 
59   
60  from etreeimpl import ElementTreeImplementation 
61  from elements import * 
62   
63  ParentedTree = ElementTreeImplementation(_ParentedElement) 
64  MultiParentedTree = ElementTreeImplementation(_MultiParentedElement) 
65   
66  # Pretend they're modules 
67  import sys 
68  sys.modules['ptree.ParentedTree'] = ParentedTree 
69  sys.modules['ptree.MultiParentedTree'] = MultiParentedTree 
70