comparison emeraldtree/ElementTree.py @ 13:99619772e57c

Move imports. emeraldtree/ElementTree.py: Move re and sys import. PEP8 compilance.
author Bastian Blank <bblank@thinkmo.de>
date Sat, 31 May 2008 16:28:41 +0200
parents 1eb02b658530
children 3d7555e0be1b
comparison
equal deleted inserted replaced
12:1eb02b658530 13:99619772e57c
118 # or the {@link #SubElement} factory function. 118 # or the {@link #SubElement} factory function.
119 # <p> 119 # <p>
120 # The {@link #ElementTree} class can be used to wrap an element 120 # The {@link #ElementTree} class can be used to wrap an element
121 # structure, and convert it from and to XML. 121 # structure, and convert it from and to XML.
122 ## 122 ##
123
124 import sys, re
125 123
126 class _SimpleElementPath(object): 124 class _SimpleElementPath(object):
127 # emulate pre-1.2 find/findtext/findall behaviour 125 # emulate pre-1.2 find/findtext/findall behaviour
128 def find(self, element, tag): 126 def find(self, element, tag):
129 for elem in element: 127 for elem in element:
970 # will be serialized with the given prefix, if at all possible. 968 # will be serialized with the given prefix, if at all possible.
971 # @raise ValueError If the prefix is reserved, or is otherwise 969 # @raise ValueError If the prefix is reserved, or is otherwise
972 # invalid. 970 # invalid.
973 971
974 def register_namespace(prefix, uri): 972 def register_namespace(prefix, uri):
973 import re
975 if re.match("ns\d+$", prefix): 974 if re.match("ns\d+$", prefix):
976 raise ValueError("Prefix format reserved for internal use") 975 raise ValueError("Prefix format reserved for internal use")
977 for k, v in _namespace_map.items(): 976 for k, v in _namespace_map.items():
978 if k == uri or v == prefix: 977 if k == uri or v == prefix:
979 del _namespace_map[k] 978 del _namespace_map[k]
1096 # 1095 #
1097 # @param elem An element tree or an individual element. 1096 # @param elem An element tree or an individual element.
1098 1097
1099 def dump(elem): 1098 def dump(elem):
1100 # debugging 1099 # debugging
1100 import sys
1101 if not isinstance(elem, ElementTree): 1101 if not isinstance(elem, ElementTree):
1102 elem = ElementTree(elem) 1102 elem = ElementTree(elem)
1103 elem.write(sys.stdout) 1103 elem.write(sys.stdout)
1104 tail = elem.getroot().tail 1104 tail = elem.getroot().tail
1105 if not tail or tail[-1] != "\n": 1105 if not tail or tail[-1] != "\n":