[lxml-dev] Bug: type annotation namespace-prefix goes missing

jholg at gmx.de jholg at gmx.de
Fri Feb 8 14:26:30 CET 2008


Hi Stefan,

 
> 

> their own siblings (as you did in your example). I changed the 
> implementation
> to copy *all* source nodes first, and *then* start replacing them in the
> target slice. Previously, they were copied over one by one while doing 
> the
> replacements, so now you're on the safe side here.
> 

  I can confirm the objectify case works for me now:

 >>>
>>> import lxml.etree
>>> import lxml.objectify
>>>
>>> xml = lxml.objectify.XML(
...     '<a xmlns:py="http://codespeak.net/lxml/objectify/pytype">'
...     '<b name="b1"><title 
py:pytype="str">tit</title><text>foo</text></b>'
...     '<b name="b2"><text>bar</text></b></a>')
>>>
>>> print lxml.etree.tostring(xml, pretty_print=True)
<a xmlns:py="http://codespeak.net/lxml/objectify/pytype">
  <b name="b1">
    <title py:pytype="str">tit</title>
    <text>foo</text>
  </b>
  <b name="b2">
    <text>bar</text>
  </b>
</a>
 
>>>
>>> foo = xml['b'][0]
>>> bar = xml['b'][1]
>>> foo['text'] = 'FOO!'
>>>
>>> print lxml.etree.tostring(xml, pretty_print=True)
<a xmlns:py="http://codespeak.net/lxml/objectify/pytype">
  <b name="b1">
    <title py:pytype="str">tit</title>
    <text py:pytype="str">FOO!</text>
  </b>
  <b name="b2">
    <text>bar</text>
  </b>
</a>
 
>>>
>>> foo = xml['b'][0]
>>> bar = xml['b'][1]
>>> xml['b'] = [bar, foo]
>>>
>>> print lxml.etree.tostring(xml, pretty_print=True)
<a xmlns:py="http://codespeak.net/lxml/objectify/pytype">
  <b name="b2">
    <text>bar</text>
  </b>
  <b name="b1">
    <title py:pytype="str">tit</title>
    <text py:pytype="str">FOO!</text>
  </b>
</a> 

 
>>> print etree.__version__
2.0.0-51328 

 
> although you can still do
> 
>   el.a = [el1, el2]
> 

>  


>>> l = [1, 2, 3, 4]

>>> l[2:3] = ["a", "b", "c", "d"]
>>> l
[1, 2, 'a', 'b', 'c', 'd', 4]
>>> root = objectify.Element("root")
>>> root.l = [1, 2, 3, 4]
>>> root.l[2:3] = ["a", "b", "c", "d"]
>>> print objectify.dump(root)
root = None [ObjectifiedElement]
    l = 1 [IntElement]
      * py:pytype = 'int'
    l = 2 [IntElement]
      * py:pytype = 'int'
    l = 'a' [StringElement]
      * py:pytype = 'str'
    l = 4 [IntElement]
      * py:pytype = 'int'
    l = 'b' [StringElement]
      * py:pytype = 'str'
    l = 'c' [StringElement]
      * py:pytype = 'str'
    l = 'd' [StringElement]
      * py:pytype = 'str'
>>> etree.tostring(root, pretty_print=True)
'<root xmlns:py="http://codespeak.net/lxml/objectify/pytype" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" py:pytype="TREE">\n  
<l py:pytype="int">1</l>\n  <l py:pytype="int">2</l>\n  <l 
py:pytype="str">a</l>\n  <l py:pytype="int">4</l>\n  <l 
py:pytype="str">b</l>\n  <l py:pytype="str">c</l>\n  <l 
py:pytype="str">d</l>\n</root>\n'
>>> print etree.tostring(root, pretty_print=True)
<root xmlns:py="http://codespeak.net/lxml/objectify/pytype" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" py:pytype="TREE">
  <l py:pytype="int">1</l>
  <l py:pytype="int">2</l>
  <l py:pytype="str">a</l>
  <l py:pytype="int">4</l>
  <l py:pytype="str">b</l>
  <l py:pytype="str">c</l>
  <l py:pytype="str">d</l>
</root>
 
>>> 
 So the correct slice gets substituted, but the order is a bit confused.

 
> I don't think anyone will really miss the first one, especially as it 
> only
> worked for one list level anyway.
 Right. I think the slice assignment stuff is basically corner cases, but 
it's nice somehow :-)

But I won't miss the first one for sure.

 Cheers,

Holger 


-- 
GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://codespeak.net/pipermail/lxml-dev/attachments/20080208/ce1c85b1/attachment-0001.htm 


More information about the lxml-dev mailing list