[Lxml-checkins] r35241 - in lxml/branch/nscleanup/src/lxml: . tests
scoder at codespeak.net
scoder at codespeak.net
Mon Dec 4 10:25:32 CET 2006
Author: scoder
Date: Mon Dec 4 10:25:29 2006
New Revision: 35241
Modified:
lxml/branch/nscleanup/src/lxml/etree.pyx
lxml/branch/nscleanup/src/lxml/proxy.pxi
lxml/branch/nscleanup/src/lxml/tests/test_etree.py
Log:
cleanup, new test case and bugfix for stupid typo
Modified: lxml/branch/nscleanup/src/lxml/etree.pyx
==============================================================================
--- lxml/branch/nscleanup/src/lxml/etree.pyx (original)
+++ lxml/branch/nscleanup/src/lxml/etree.pyx Mon Dec 4 10:25:29 2006
@@ -323,16 +323,7 @@
# XXX too many prefixes in use - this is pretty bad!
return NULL
- c_ns = tree.xmlNewNs(c_node, c_href, c_prefix)
- return c_ns
- c_doc_ns = self._c_doc.oldNs
- if c_doc_ns is NULL:
- # this will create the XML namespace:
- c_doc_ns = tree.xmlSearchNs(self._c_doc, c_node, 'xml')
- while c_doc_ns.next is not NULL:
- c_doc_ns = c_doc_ns.next
- c_doc_ns.next = c_ns
- return c_ns
+ return tree.xmlNewNs(c_node, c_href, c_prefix)
cdef void _setNodeNs(self, xmlNode* c_node, char* href):
"Lookup namespace structure and set it for the node."
Modified: lxml/branch/nscleanup/src/lxml/proxy.pxi
==============================================================================
--- lxml/branch/nscleanup/src/lxml/proxy.pxi (original)
+++ lxml/branch/nscleanup/src/lxml/proxy.pxi Mon Dec 4 10:25:29 2006
@@ -1,4 +1,4 @@
-# Proxy functions
+# Proxy functions and low level node allocation stuff
# Proxies represent elements, their reference is stored in the C
# structure of the respective node to avoid multiple instantiation of
@@ -234,7 +234,7 @@
else:
c_ns = c_ns.next
- # make sure ns declaration of element and its attributes is stored
+ # make sure the namespace of an element and its attributes is declared
# in this document
c_node = c_element
while c_node is not NULL:
@@ -249,7 +249,6 @@
if c_ns is not NULL:
# not in cache, must find a replacement from this document
c_new_ns = doc._findOrBuildNodeNs(c_node, c_ns.href, c_ns.prefix)
- print "FOUND:", c_new_ns.href
if c_cache_last >= c_cache_size:
# must resize cache
if c_cache_size == 0:
@@ -269,12 +268,13 @@
c_ns_new_cache[c_cache_last] = c_new_ns
c_ns_old_cache[c_cache_last] = c_node.ns
c_cache_last = c_cache_last + 1
- c_node.ns = c_ns
+ c_node.ns = c_new_ns
if c_node is c_element:
+ # after the element, continue with its attributes
c_node = <xmlNode*>c_element.properties
else:
c_node = c_node.next
-
+
# traverse to next element, start with children
c_node = c_element.children
while c_node is not NULL and \
@@ -317,6 +317,7 @@
break
c_element = c_node
+ # cleanup
if c_ns_new_cache is not NULL:
python.PyMem_Free(c_ns_new_cache)
if c_ns_old_cache is not NULL:
Modified: lxml/branch/nscleanup/src/lxml/tests/test_etree.py
==============================================================================
--- lxml/branch/nscleanup/src/lxml/tests/test_etree.py (original)
+++ lxml/branch/nscleanup/src/lxml/tests/test_etree.py Mon Dec 4 10:25:29 2006
@@ -943,6 +943,25 @@
print etree.tostring(e1)
print etree.tostring(e2)
+ def test_namespaces_reuse_after_move(self):
+ Element = self.etree.Element
+ ElementTree = self.etree.ElementTree
+
+ ns_href = "http://a.b.c"
+ one = self.etree.parse(
+ StringIO('<foo><bar xmlns:ns="%s"><ns:baz/></bar></foo>' % ns_href))
+ baz = one.getroot()[0][0]
+
+ two = self.etree.parse(
+ StringIO('<root xmlns:ns="%s"/>' % ns_href))
+ two.getroot().append(baz)
+ del one # make sure the source document is deallocated
+
+ self.assertEquals('{%s}baz' % ns_href, baz.tag)
+ self.assertEquals(
+ '<root xmlns:ns="%s"><ns:baz/></root>' % ns_href,
+ self.etree.tostring(two))
+
def test_element_nsmap(self):
etree = self.etree
More information about the lxml-checkins
mailing list