1   
 2   
 3   
 4   
 5   
 6   
 7   
 8   
 9   
10   
11   
12   
13   
14   
15   
16   
17   
18   
19   
20   
21   
22   
23   
24   
25   
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   
67  import sys 
68  sys.modules['ptree.ParentedTree'] = ParentedTree 
69  sys.modules['ptree.MultiParentedTree'] = MultiParentedTree 
70